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


Python InstanceDouble.method_with_positional_arguments方法代码示例

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


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

示例1: test_returns_result_of_a_callable_with_positional_arg

# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import method_with_positional_arguments [as 别名]
    def test_returns_result_of_a_callable_with_positional_arg(self, stubber):
        subject = InstanceDouble('doubles.testing.User')

        stubber(subject).method_with_positional_arguments.and_return_result_of(lambda x: x)

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

示例2: test_allows_specification_of_arguments

# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import method_with_positional_arguments [as 别名]
    def test_allows_specification_of_arguments(self):
        subject = InstanceDouble('doubles.testing.User')

        allow(subject).method_with_positional_arguments.with_args('foo')

        assert subject.method_with_positional_arguments('foo') is None
开发者ID:sladebot,项目名称:doubles,代码行数:8,代码来源:allow_test.py

示例3: test_allows_any_arguments_if_none_are_specified

# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import method_with_positional_arguments [as 别名]
    def test_allows_any_arguments_if_none_are_specified(self):
        subject = InstanceDouble('doubles.testing.User')

        allow(subject).method_with_positional_arguments.and_return('bar')

        assert subject.method_with_positional_arguments('unspecified argument') == 'bar'
开发者ID:sladebot,项目名称:doubles,代码行数:8,代码来源:allow_test.py

示例4: test__call__is_short_hand_for_with_args

# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import method_with_positional_arguments [as 别名]
    def test__call__is_short_hand_for_with_args(self):
        subject = InstanceDouble('doubles.testing.User')

        allow(subject).method_with_positional_arguments('Bob').and_return('Barker')
        assert subject.method_with_positional_arguments('Bob') == 'Barker'
开发者ID:sladebot,项目名称:doubles,代码行数:7,代码来源:allow_test.py

示例5: test_objects_with_custom__eq__method_two

# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import method_with_positional_arguments [as 别名]
    def test_objects_with_custom__eq__method_two(self):
        subject = InstanceDouble('doubles.testing.User')
        allow(subject).method_with_positional_arguments.with_args(AlwaysEquals())

        subject.method_with_positional_arguments(NeverEquals())
开发者ID:sladebot,项目名称:doubles,代码行数:7,代码来源:allow_test.py

示例6: TestCustomMatcher

# 需要导入模块: from doubles.instance_double import InstanceDouble [as 别名]
# 或者: from doubles.instance_double.InstanceDouble import method_with_positional_arguments [as 别名]
class TestCustomMatcher(object):
    def setup(self):
        self.subject = InstanceDouble('doubles.testing.User')

    def test_matcher_raises_an_exception(self):
        def func():
            raise Exception('Bob Barker')

        allow(self.subject).instance_method.with_args_validator(func)
        with raises(UnallowedMethodCallError):
            self.subject.instance_method()

    def test_matcher_with_no_args_returns_true(self):
        allow(self.subject).instance_method.with_args_validator(lambda: True).and_return('Bob')
        self.subject.instance_method() == 'Bob'

    def test_matcher_with_no_args_returns_false(self):
        allow(self.subject).instance_method.with_args_validator(lambda: False)
        with raises(UnallowedMethodCallError):
            self.subject.instance_method()

    def test_matcher_with_positional_args_returns_true(self):
        (allow(self.subject)
            .method_with_positional_arguments
            .with_args_validator(lambda x: True)
            .and_return('Bob'))
        self.subject.method_with_positional_arguments('Bob Barker') == 'Bob'

    def test_matcher_with_positional_args_returns_false(self):
        allow(self.subject).method_with_positional_arguments.with_args_validator(lambda x: False)
        with raises(UnallowedMethodCallError):
            self.subject.method_with_positional_arguments('Bob Barker')

    def test_matcher_with_kwargs_args_returns_false(self):
        def func(bar=None):
            return False
        allow(self.subject).instance_method.with_args_validator(func)
        with raises(UnallowedMethodCallError):
            self.subject.instance_method()

    def test_matcher_with_kwargs_args_returns_true(self):
        def func(bar=None):
            return True
        allow(self.subject).instance_method.with_args_validator(func).and_return('Bob')
        self.subject.instance_method() == 'Bob'

    def test_matcher_with_positional_and_kwargs_returns_true(self):
        def func(foo, bar=None):
            return True
        allow(self.subject).method_with_default_args.with_args_validator(func).and_return('Bob')
        self.subject.method_with_default_args('bob', bar='Barker') == 'Bob'

    def test_matcher_with_positional_and_kwargs_returns_false(self):
        def func(foo, bar=None):
            return False
        allow(self.subject).method_with_default_args.with_args_validator(func).and_return('Bob')
        with raises(UnallowedMethodCallError):
            self.subject.method_with_default_args('bob', bar='Barker')

    def test_matcher_returns_true_but_args_do_not_match_call_signature(self):
        allow(self.subject).instance_method.with_args_validator(lambda x: True)
        with raises(VerifyingDoubleArgumentError):
            self.subject.instance_method('bob')
开发者ID:sladebot,项目名称:doubles,代码行数:65,代码来源:allow_test.py


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