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


Python lancelot.Spec類代碼示例

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


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

示例1: verify_should_invoke_callable

 def verify_should_invoke_callable(self):
     ''' verify should invoke callable and compare result '''
     a_list = []
     with_callable = lambda: a_list.append(True)
     spec = Spec(Constraint())
     spec.verify(with_callable).should_raise(UnmetSpecification)
     spec.then(a_list.__len__).should_be(1)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:7,代碼來源:constraint_spec.py

示例2: can_override_comparators

 def can_override_comparators(self):
     ''' should be able to specify any comparator for arg verification '''
     mock_spec = MockSpec(comparators={Exception:Nothing})
     mock_call = mock_spec.your_mother(TypeError('hamster'))
     mock_call_result = mock_call.result_of('your_mother')
     spec = Spec(mock_call_result)
     spec.__call__(TypeError('hamster')).should_raise(UnmetSpecification)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:7,代碼來源:mocking_spec.py

示例3: override_comparators_dont_replace_all

 def override_comparators_dont_replace_all(self):
     ''' comparator overrides only affect comparator used for that type '''
     mock_spec = MockSpec(comparators={float:EqualsEquals})
     mock_call = mock_spec.your_mother(TypeError('hamster'))
     mock_call_result = mock_call.result_of('your_mother')
     spec = Spec(mock_call_result)
     spec.__call__(TypeError('hamster'))
     spec.should_not_raise(UnmetSpecification)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:8,代碼來源:mocking_spec.py

示例4: should_delegate_eq

 def should_delegate_eq(self):
     ''' base Comparator should delegate __eq__ to compare_to. '''
     #TODO: nicer way of forcing spec to use underlying __eq__
     base_comparator_equals = Comparator(1).__eq__
     spec = Spec(base_comparator_equals)
     spec.__call__(1).should_be(False)
     spec.__call__(2).should_be(False)
     spec.__call__(int).should_be(False)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:8,代碼來源:comparator_spec.py

示例5: given_typechecking_behaviour

def given_typechecking_behaviour():
    ''' Spec for check that given=... is correct type '''
    def spec_for_dict_given_empty_list():
        ''' callable method to defer instance creation until within Spec '''
        return Spec(type({}), given=lambda: [])
    
    spec = Spec(spec_for_dict_given_empty_list)
    type_error = TypeError("[] is not instance of <class 'dict'>")
    spec.__call__().should_raise(type_error)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:9,代碼來源:specification_spec.py

示例6: should_trap_incorrect_args

 def should_trap_incorrect_args(self):
     ''' Specified foo(2) & bar(), and foo(1) called: UnmetSpecification'''
     mock_spec = MockSpec()
     collaborations = (mock_spec.foo(2), mock_spec.bar())
     descriptions = [collaboration.description() 
                     for collaboration in collaborations]
     spec = Spec(CollaborateWith(*collaborations))
     spec.describe_constraint().should_be(','.join(descriptions))
     spec.verify(lambda: mock_spec.foo(1)).should_raise(UnmetSpecification)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:9,代碼來源:constraint_spec.py

示例7: desc_should_use_comparator

 def desc_should_use_comparator(self):
     ''' describe_constraint should delegate to comparator.description ''' 
     comparator = MockSpec()
     spec = Spec(Constraint(comparator))
     comparator_description = comparator.description()
     comparator_description.will_return('subtitled')
     spec.describe_constraint()
     spec.should_collaborate_with(comparator_description,
                                  and_result='should be subtitled')
開發者ID:gbremer,項目名稱:lancelot,代碼行數:9,代碼來源:constraint_spec.py

示例8: should_trap_incorrect_return

 def should_trap_incorrect_return(self):
     ''' Specified and_result="bar" but was "baz": UnmetSpecification.
     Note: and_result refers to the value returned from the callable  
     invoked in verify(), not the return value from the mock. See
     the Hungarian gentleman in the examples for a clearer picture... ''' 
     mock_spec = MockSpec()
     spec = Spec(CollaborateWith(mock_spec.foo().will_return('baz'), 
                                 and_result='bar'))
     spec.verify(lambda: mock_spec.foo()).should_raise(UnmetSpecification)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:9,代碼來源:constraint_spec.py

示例9: given_when_then_behaviour

def given_when_then_behaviour(): 
    ''' given empty list when item appended then list length should be one '''
    spec = Spec([])
    spec.when(spec.append(object())).then(spec.it()).should_be(Length(1))

    def empty_list():
        ''' descriptive name for fn returning an empty list '''
        return []
    spec = Spec(type([]), given=empty_list)
    spec.when(spec.append('monty')).then(spec.it()).should_be(Length(1))
開發者ID:gbremer,項目名稱:lancelot,代碼行數:10,代碼來源:specification_spec.py

示例10: greaterthanorequal_behaviour

def greaterthanorequal_behaviour():
    ''' GreaterThanOrEqual should compare using >= '''
    spec = Spec(GreaterThanOrEqual(2))
    spec.description().should_be("=> 2")
    spec.compares_to(2).should_be(True)
    spec.compares_to(1).should_be(False)
    spec.compares_to('a').should_be(False)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:7,代碼來源:comparator_spec.py

示例11: notcontain_behaviour

def notcontain_behaviour():
    ''' NotContain comparator should negate the behaviour of Contain '''
    spec = Spec(NotContain(1))
    spec.description().should_be('not contain 1')
    spec.compares_to([1, 2]).should_be(False)
    spec.compares_to([1]).should_be(False)
    spec.compares_to([2]).should_be(True)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:7,代碼來源:comparator_spec.py

示例12: atomic_raise_behaviour

def atomic_raise_behaviour():
    ''' should_raise() and should_not_raise() are the only 
    "atomic" parts that require test assertions. All other 
    functionality can be bootstrap-specified using these methods. '''
    spec1 = Spec(dont_raise_index_error)
    try:
        spec1.dont_raise_index_error().should_raise(IndexError)
        assert False
    except UnmetSpecification:
        # UnmetSpecification because no IndexError is raised 
        pass
    
    spec2 = Spec(raise_index_error)
    try:
        spec2.raise_index_error().should_not_raise(IndexError)
        assert False
    except UnmetSpecification:
        # UnmetSpecification because an IndexError is raised 
        pass
    
    spec2 = Spec(raise_index_error)
    try:
        spec2.raise_index_error().should_raise(ValueError)
        assert False
    except IndexError:
        # Not UnmetSpecification because IndexError is raised, not ValueError 
        pass
開發者ID:gbremer,項目名稱:lancelot,代碼行數:27,代碼來源:specification_spec.py

示例13: lessthanorequal_behaviour

def lessthanorequal_behaviour():
    ''' LessThanOrEqual should compare using <= '''
    spec = Spec(LessThanOrEqual(2))
    spec.description().should_be("<= 2")
    spec.compares_to(1).should_be(True)
    spec.compares_to(2).should_be(True)
    spec.compares_to(3).should_be(False)
    spec.compares_to('a').should_be(False)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:8,代碼來源:comparator_spec.py

示例14: anything_behaviour

def anything_behaviour():
    ''' Anything comparator should find all compared objects equivalent. '''
    spec = Spec(Anything())
    spec.description().should_be("anything")
    spec.compares_to(1).should_be(True)
    spec.compares_to('1').should_be(True)
    spec.compares_to([1]).should_be(True)
    spec.compares_to('xyz').should_be(True)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:8,代碼來源:comparator_spec.py

示例15: nothing_behaviour

def nothing_behaviour():
    ''' Nothing comparator should never find compared objects equivalent. '''
    spec = Spec(Nothing())
    spec.description().should_be("nothing")
    spec.compares_to(1).should_be(False)
    spec.compares_to('1').should_be(False)
    spec.compares_to([1]).should_be(False)
    spec.compares_to('xyz').should_be(False)
開發者ID:gbremer,項目名稱:lancelot,代碼行數:8,代碼來源:comparator_spec.py


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