当前位置: 首页>>代码示例>>Python>>正文


Python instance_double.InstanceDouble类代码示例

本文整理汇总了Python中doubles.instance_double.InstanceDouble的典型用法代码示例。如果您正苦于以下问题:Python InstanceDouble类的具体用法?Python InstanceDouble怎么用?Python InstanceDouble使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InstanceDouble类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_returns_result_of_a_callable_with_positional_vargs

    def test_returns_result_of_a_callable_with_positional_vargs(self, stubber):
        subject = InstanceDouble('doubles.testing.User')

        stubber(subject).method_with_varargs.and_return_result_of(lambda *x: x)

        result = subject.method_with_varargs('bob', 'barker')
        assert result == ('bob', 'barker')
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:return_values_test.py

示例2: test_with_args_validator

    def test_with_args_validator(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).method_with_varargs.with_args_validator(
            lambda *args: args[0] == 'Bob Barker'
        )
        subject.method_with_varargs('Bob Barker', 'Drew Carey')
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:expect_test.py

示例3: test_passes_when_called_twice

    def test_passes_when_called_twice(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.twice()

        subject.instance_method()
        subject.instance_method()
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:expect_test.py

示例4: test_subsequent_allowances_override_previous_ones

    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'
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:return_values_test.py

示例5: test_passes_when_called_more_than_at_least_times

    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()
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:expect_test.py

示例6: test_raises_provided_exception

    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()
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:return_values_test.py

示例7: test_returns_specified_values_in_order

    def test_returns_specified_values_in_order(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'
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:return_values_test.py

示例8: test_skip_builtin_verification_does_not_affect_non_builtins

    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')
开发者ID:sladebot,项目名称:doubles,代码行数:7,代码来源:allow_test.py

示例9: TestAsync

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
开发者ID:sladebot,项目名称:doubles,代码行数:27,代码来源:allow_test.py

示例10: test_passes_when_called_exactly_at_least_times

    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()
开发者ID:sladebot,项目名称:doubles,代码行数:7,代码来源:allow_test.py

示例11: test_calls_are_chainable

    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()
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:expect_test.py

示例12: test_calls_are_chainable

    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()
开发者ID:sladebot,项目名称:doubles,代码行数:7,代码来源:allow_test.py

示例13: test_takes_precendence_over_previous_allowance

    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
开发者ID:uber,项目名称:doubles,代码行数:7,代码来源:expect_test.py

示例14: test_matches_most_specific_allowance

    def test_matches_most_specific_allowance(self):
        subject = InstanceDouble('doubles.testing.User')

        allow(subject).method_with_varargs.and_return('bar')
        allow(subject).method_with_varargs.with_args('baz').and_return('blah')

        assert subject.method_with_varargs('baz') == 'blah'
开发者ID:sladebot,项目名称:doubles,代码行数:7,代码来源:allow_test.py

示例15: test_chaining_result_methods_gives_the_last_one_precedence

    def test_chaining_result_methods_gives_the_last_one_precedence(self, stubber):
        subject = InstanceDouble('doubles.testing.User')

        stubber(subject).instance_method.and_return('bar').and_return_result_of(
            lambda: 'baz'
        ).and_raise(UserDefinedException).and_return('final')

        assert subject.instance_method() == 'final'
开发者ID:uber,项目名称:doubles,代码行数:8,代码来源:return_values_test.py


注:本文中的doubles.instance_double.InstanceDouble类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。