當前位置: 首頁>>代碼示例>>Python>>正文


Python Spec.should_raise方法代碼示例

本文整理匯總了Python中lancelot.Spec.should_raise方法的典型用法代碼示例。如果您正苦於以下問題:Python Spec.should_raise方法的具體用法?Python Spec.should_raise怎麽用?Python Spec.should_raise使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lancelot.Spec的用法示例。


在下文中一共展示了Spec.should_raise方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: should_verify_specified_collaborations

# 需要導入模塊: from lancelot import Spec [as 別名]
# 或者: from lancelot.Spec import should_raise [as 別名]
 def should_verify_specified_collaborations(self):
     ''' after start_collaborating, collaborations should be verified '''
     spec = Spec(MockSpec(name='a'))
     spec.when(spec.start_collaborating())
     spec.then(spec.foo())
     msg = 'should not be collaborating with a.foo()'
     spec.should_raise(UnmetSpecification(msg))
 
     spec = Spec(MockSpec(name='b'))
     spec.when(spec.foo(), spec.start_collaborating())
     spec.then(spec.bar())
     msg = 'should be collaborating with b.foo(), not b.bar()'
     spec.should_raise(UnmetSpecification(msg))
 
     spec = Spec(MockSpec(name='c'))
     spec.when(spec.foo(), spec.bar(), spec.start_collaborating())
     spec.then(spec.foo()).should_not_raise(UnmetSpecification)
     msg = 'should be collaborating with c.bar(), not c.baz()'
     spec.then(spec.baz()).should_raise(UnmetSpecification(msg))
     
     mock = MockSpec(name='d')
     mock.foo().times(2).will_return('camelot')
     spec = Spec(mock)
     spec.when(spec.start_collaborating())
     spec.then(spec.foo()).should_not_raise(UnmetSpecification)
     spec.then(spec.foo()).should_not_raise(UnmetSpecification)
     msg = 'should not be collaborating with d.foo()'
     spec.then(spec.foo()).should_raise(UnmetSpecification(msg))
開發者ID:gbremer,項目名稱:lancelot,代碼行數:30,代碼來源:mocking_spec.py

示例2: should_check_unverified_collaborations

# 需要導入模塊: from lancelot import Spec [as 別名]
# 或者: from lancelot.Spec import should_raise [as 別名]
 def should_check_unverified_collaborations(self):
     ''' check for unverified collaborations after start_collaborating '''
     spec = Spec(MockSpec())
     spec.when(spec.foo(), spec.start_collaborating())
     spec.then(spec.verify())
     msg = 'should be collaborating with unnamed_mock.foo()'
     spec.should_raise(UnmetSpecification(msg))
     
     spec = Spec(MockSpec())
     spec.when(spec.foo(), spec.start_collaborating(), spec.foo())
     spec.then(spec.verify())
     spec.should_not_raise(UnmetSpecification)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:14,代碼來源:mocking_spec.py

示例3: should_have_meaningful_msg

# 需要導入模塊: from lancelot import Spec [as 別名]
# 或者: from lancelot.Spec import should_raise [as 別名]
    def should_have_meaningful_msg(self):
        ''' Raise should produce meaningful UnmetSpecification messages'''
        spec = Spec(Raise(IndexError))
        msg = "should raise IndexError"
        spec.describe_constraint().should_be(msg)
        spec.verify(dont_raise_index_error)
        spec.should_raise(UnmetSpecification(msg))

        spec = Spec(Raise(IndexError('with some message')))
        msg = "should raise IndexError('with some message',)"
        spec.describe_constraint().should_be(msg)
        unmet_msg = msg + ", not IndexError('with message',)"
        unmet_specification = UnmetSpecification(unmet_msg)
        spec.verify(raise_index_error).should_raise(unmet_specification)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:16,代碼來源:constraint_spec.py


注:本文中的lancelot.Spec.should_raise方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。