本文整理汇总了Python中lancelot.Spec.__call__方法的典型用法代码示例。如果您正苦于以下问题:Python Spec.__call__方法的具体用法?Python Spec.__call__怎么用?Python Spec.__call__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lancelot.Spec
的用法示例。
在下文中一共展示了Spec.__call__方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: should_mimic_specification
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def should_mimic_specification(self):
''' result_of should be callable and return specified value or raise
specified exception '''
mock_call = MockSpec().foo()
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__().should_be(None)
mock_call = MockSpec().foo().will_return(1)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__().should_be(1)
mock_call = MockSpec().foo().will_return((2, 3))
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__().should_be((2, 3))
mock_call = MockSpec().foo().will_raise(StopIteration)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__().should_raise(StopIteration)
value_error = ValueError("that's no ordinary rabbit")
mock_spec = MockSpec()
mock_call = mock_spec.foo().will_raise(value_error)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__().should_raise(value_error)
# check that after exception raised the collaboration is 'over'
Spec(mock_spec).verify().should_not_raise(UnmetSpecification)
示例2: spec_getattr_behaviour
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def spec_getattr_behaviour():
''' getattr from spec should return wrapper for unknown attributes '''
spec = Spec(lambda: getattr(Spec('grail'), 'should'))
spec.__call__().should_not_be(Type(WrapFunction)) # Spec.should() exists
spec = Spec(lambda: getattr(Spec('life'), 'death'))
spec.__call__().should_be(Type(WrapFunction)) # Spec.death() not exists
示例3: can_override_comparators
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
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)
示例4: override_comparators_dont_replace_all
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
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)
示例5: should_delegate_eq
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
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)
示例6: given_typechecking_behaviour
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
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)
示例7: verify_exceptions_with_comparator
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def verify_exceptions_with_comparator(self):
''' ExceptionValue should be used to verify Exception args '''
mock_call = MockSpec().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)
mock_call = MockSpec().your_father(smelt_of=TypeError('elderberries'))
mock_call_result = mock_call.result_of('your_father')
spec = Spec(mock_call_result)
spec.__call__(smelt_of=TypeError('elderberries'))
spec.should_not_raise(UnmetSpecification)
示例8: should_verify_args_specification
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def should_verify_args_specification(self):
''' result_of should verify the args specification and supply a
meaningful message if specification is unmet '''
mock_call = MockSpec(name='a').foo()
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
msg = 'should be collaborating with a.foo(), not a.foo(1)'
spec.__call__(1).should_raise(UnmetSpecification(msg))
mock_call = MockSpec(name='b').foo(1)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
msg = "should be collaborating with b.foo(1), not b.foo('1')"
spec.__call__('1').should_raise(UnmetSpecification(msg))
mock_call = MockSpec(name='c').foo(1)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
msg = 'should be collaborating with c.foo(1), not c.foo()'
spec.__call__().should_raise(UnmetSpecification(msg))
mock_call = MockSpec(name='d').foo(1)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
msg = 'should be collaborating with d.foo(1), not d.foo(2)'
spec.__call__(2).should_raise(UnmetSpecification(msg))
mock_call = MockSpec(name='e').foo(1)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__(1).should_not_raise(UnmetSpecification)
mock_call = MockSpec(name='f').foo(1).will_return(2)
mock_call_result = mock_call.result_of('foo')
spec = Spec(mock_call_result)
spec.__call__(1).should_be(2)
mock_call = MockSpec(name='g').bar(keyword='named argument')
mock_call_result = mock_call.result_of('bar')
spec = Spec(mock_call_result)
msg = "should be collaborating with g.bar(keyword='named argument'), "\
+ "not g.bar(keyword='wrong argument')"
spec.__call__(keyword='wrong argument').should_raise(
UnmetSpecification(msg))
mock_call = MockSpec(name='h').bar(keyword='named argument')
mock_call_result = mock_call.result_of('bar')
spec = Spec(mock_call_result)
msg = "should be collaborating with h.bar(keyword='named argument'), "\
+ "not h.bar(bad_keyword='named argument')"
spec.__call__(bad_keyword='named argument').should_raise(
UnmetSpecification(msg))
mock_call = MockSpec(name='i').bar(keyword='named argument')
mock_call_result = mock_call.result_of('bar')
spec = Spec(mock_call_result)
spec.__call__(keyword='named argument').should_not_raise(
UnmetSpecification)
mock_call = MockSpec(name='j').bar(
keyword='named argument').will_return('monty')
mock_call_result = mock_call.result_of('bar')
spec = Spec(mock_call_result)
spec.__call__(keyword='named argument').should_be('monty')
示例9: verify_floats_with_comparator
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def verify_floats_with_comparator(self):
''' FloatValue should be used to verify float args '''
mock_call = MockSpec().kernigget(3.14)
mock_call_result = mock_call.result_of('kernigget')
spec = Spec(mock_call_result)
spec.__call__(3.141).should_not_raise(UnmetSpecification)
示例10: result_of_successive_times
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def result_of_successive_times():
''' result_of should "iterate" over will_return value(s) and
provide a meaningful error message if the specification is unmet'''
mock_call = MockSpec(name='x').foo().times(2).will_return(3, 4)
spec = Spec(mock_call.result_of('foo'))
spec.__call__().should_be(3)
spec = Spec(mock_call.result_of('foo'))
spec.__call__().should_be(4)
spec = Spec(mock_call.result_of('foo'))
msg = 'should be collaborating with x.foo() only 2 successive times'
spec.__call__().should_raise(UnmetSpecification(msg))
mock_call = MockSpec(name='y').bar().times(3).will_return(5)
spec = Spec(mock_call.result_of('bar'))
spec.__call__().should_be(5)
spec = Spec(mock_call.result_of('bar'))
spec.__call__().should_be(5)
spec = Spec(mock_call.result_of('bar'))
spec.__call__().should_be(5)
spec = Spec(mock_call.result_of('bar'))
msg = 'should be collaborating with y.bar() only 3 successive times'
spec.__call__().should_raise(UnmetSpecification(msg))
示例11: mock_call_call_returns_self
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def mock_call_call_returns_self():
'''making a mock call should return the mock call'''
mock_call = MockSpec().foo
spec = Spec(mock_call)
spec.__call__().should_be(mock_call)
示例12: should_wrap_modulefunctions
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def should_wrap_modulefunctions(self):
"""Wrapping module functions and instance methods should be possible"""
spec = Spec(WrapFunction(None, number_one, "number_one"))
spec.when(spec.__call__()).then(spec.result()).should_be(1)
示例13: result_invoke_underlying
# 需要导入模块: from lancelot import Spec [as 别名]
# 或者: from lancelot.Spec import __call__ [as 别名]
def result_invoke_underlying(self):
"""result() should invoke the wrapped function and return its result"""
spec = Spec(WrapFunction(None, "a", "startswith"))
spec.when(spec.__call__("a")).then(spec.result()).should_be(True)
spec.when(spec.__call__("b")).then(spec.result()).should_be(False)