当前位置: 首页>>代码示例>>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;未经允许,请勿转载。