本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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')
示例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)
示例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))
示例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)
示例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)
示例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
示例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)
示例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)
示例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)