本文整理汇总了Python中doubles.instance_double.InstanceDouble.instance_method方法的典型用法代码示例。如果您正苦于以下问题:Python InstanceDouble.instance_method方法的具体用法?Python InstanceDouble.instance_method怎么用?Python InstanceDouble.instance_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doubles.instance_double.InstanceDouble
的用法示例。
在下文中一共展示了InstanceDouble.instance_method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_skip_builtin_verification_does_not_affect_non_builtins
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_skip_builtin_verification_does_not_affect_non_builtins(self):
with no_builtin_verification():
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method
with raises(VerifyingDoubleArgumentError):
subject.instance_method('bar')
示例2: test_raises_provided_exception
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_raises_provided_exception(self, stubber):
subject = InstanceDouble('doubles.testing.User')
stubber(subject).instance_method.and_raise(UserDefinedException)
with raises(UserDefinedException):
subject.instance_method()
示例3: test_passes_when_called_exactly_at_least_times
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_passes_when_called_exactly_at_least_times(self):
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method.at_least(1).times
subject.instance_method()
subject.instance_method()
示例4: test_calls_are_chainable
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_calls_are_chainable(self):
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method.exactly(1).time.exactly(2).times
subject.instance_method()
subject.instance_method()
示例5: test_passes_when_called_twice
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_passes_when_called_twice(self):
subject = InstanceDouble('doubles.testing.User')
expect(subject).instance_method.twice()
subject.instance_method()
subject.instance_method()
示例6: test_passes_when_called_more_than_at_least_times
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_passes_when_called_more_than_at_least_times(self):
subject = InstanceDouble('doubles.testing.User')
expect(subject).instance_method.at_least(1).times
subject.instance_method()
subject.instance_method()
示例7: test_calls_are_chainable
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_calls_are_chainable(self):
subject = InstanceDouble('doubles.testing.User')
expect(subject).instance_method.at_most(1).times.at_most(2).times
subject.instance_method()
subject.instance_method()
示例8: TestAsync
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
class TestAsync(object):
def setup(self):
self.subject = InstanceDouble('doubles.testing.User')
def test_and_return_future(self):
allow(self.subject).instance_method.and_return_future('Bob Barker')
result = self.subject.instance_method()
assert result.result() == 'Bob Barker'
def test_and_return_future_multiple_values(self):
allow(self.subject).instance_method.and_return_future('Bob Barker', 'Drew Carey')
result1 = self.subject.instance_method()
result2 = self.subject.instance_method()
assert result1.result() == 'Bob Barker'
assert result2.result() == 'Drew Carey'
def test_and_raise_future(self):
exception = Exception('Bob Barker')
allow(self.subject).instance_method.and_raise_future(exception)
result = self.subject.instance_method()
with raises(Exception) as e:
result.result()
assert e.value == exception
示例9: test_returns_the_last_specified_value_multiple_times
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_returns_the_last_specified_value_multiple_times(self, stubber):
subject = InstanceDouble('doubles.testing.User')
stubber(subject).instance_method.and_return('bar', 'bazz')
assert subject.instance_method() == 'bar'
assert subject.instance_method() == 'bazz'
assert subject.instance_method() == 'bazz'
示例10: test_raises_provided_exception_with_complex_signature
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_raises_provided_exception_with_complex_signature(self, stubber):
subject = InstanceDouble('doubles.testing.User')
stubber(subject).instance_method.and_raise(
UserDefinedExceptionWithArgs('msg', 'arg1', arg2='arg2'),
)
with raises(UserDefinedExceptionWithArgs):
subject.instance_method()
示例11: test_called_with_zero
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_called_with_zero(self):
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method.exactly(0).times
with raises(MockExpectationError) as e:
subject.instance_method()
teardown()
assert re.match(
r"Allowed 'instance_method' to be called 0 times but was called 1 "
r"time on <InstanceDouble of <class 'doubles.testing.User'> "
r"object at .+> with any args, but was not."
r" \(.*doubles/test/allow_test.py:\d+\)",
str(e.value)
)
示例12: test_raises_if_called_with_args
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_raises_if_called_with_args(self):
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method.with_no_args()
with raises(UnallowedMethodCallError) as e:
subject.instance_method('bar')
assert re.match(
r"Received unexpected call to 'instance_method' on "
r"<InstanceDouble of <class '?doubles.testing.User'?"
r"(?: at 0x[0-9a-f]{9})?> object at .+>\."
r" The supplied arguments \('bar'\)"
r" do not match any available allowances.",
str(e.value)
)
示例13: test_fails_when_called_once_times
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_fails_when_called_once_times(self):
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method.never()
with raises(MockExpectationError) as e:
subject.instance_method()
teardown()
assert re.match(
r"Allowed 'instance_method' to be called 0 times instead of 1 "
r"time on <InstanceDouble of <class 'doubles.testing.User'> "
r"object at .+> with any args, but was not."
r" \(.*doubles/test/allow_test.py:\d+\)",
str(e.value)
)
示例14: test_takes_precendence_over_previous_allowance
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_takes_precendence_over_previous_allowance(self):
subject = InstanceDouble('doubles.testing.User')
allow(subject).instance_method.and_return('foo')
expect(subject).instance_method
assert subject.instance_method() is None
示例15: test_subsequent_allowances_override_previous_ones
# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import instance_method [as 别名]
def test_subsequent_allowances_override_previous_ones(self, stubber):
subject = InstanceDouble('doubles.testing.User')
stubber(subject).instance_method.never().and_return('bar')
stubber(subject).instance_method.and_return('baz')
assert subject.instance_method() == 'baz'