예제 #1
0
    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
예제 #2
0
    def test_raises_when_stubbing_noncallable_attributes(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).class_attribute

        assert re.search(r"not a callable attribute", str(e))
예제 #3
0
    def test_raises_when_stubbing_noncallable_attributes(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).class_attribute

        assert re.search(r"not a callable attribute", str(e))
예제 #4
0
    def test_raises_when_stubbing_nonexistent_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).foo

        assert re.search(r"does not implement it", str(e))
예제 #5
0
파일: expect_test.py 프로젝트: uber/doubles
    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
예제 #6
0
    def test_allows_default_arguments_specified_positionally(
            self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).method_with_default_args.with_args('blah', 'blam')

        assert doubled_user.method_with_default_args('blah', 'blam') is None
예제 #7
0
    def test_raises_when_stubbing_nonexistent_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleError) as e:
            allow(doubled_user).foo

        assert re.search(r"does not implement it", str(e))
예제 #8
0
파일: expect_test.py 프로젝트: uber/doubles
    def test_satisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

        allow(subject).__enter__
        expect(subject).__exit__.once()

        with subject:
            pass
예제 #9
0
    def test_satisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

        allow(subject).__enter__
        expect(subject).__exit__.once()

        with subject:
            pass
예제 #10
0
파일: expect_test.py 프로젝트: uber/doubles
    def test_takes_precedence_over_subsequent_allowances(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method
        allow(subject).instance_method.and_return('foo')

        with raises(MockExpectationError):
            verify()

        teardown()
예제 #11
0
    def test_mocking__enter__and__exit__works(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).__enter__.and_return('bob barker')
        # Not ideal to do both in the same test case,
        # but the with block won't execute at all unless both methods are defined.
        allow(doubled_user).__exit__

        with doubled_user as u:
            assert u == 'bob barker'
예제 #12
0
    def test_mocking__enter__and__exit__works(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).__enter__.and_return('bob barker')
        # Not ideal to do both in the same test case,
        # but the with block won't execute at all unless both methods are defined.
        allow(doubled_user).__exit__

        with doubled_user as u:
            assert u == 'bob barker'
예제 #13
0
    def test_takes_precedence_over_subsequent_allowances(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method
        allow(subject).instance_method.and_return('foo')

        with raises(MockExpectationError):
            verify()

        teardown()
예제 #14
0
    def test_raises_when_specifying_different_arity(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleArgumentError):
            allow(doubled_user).get_name.with_args('foo', 'bar')
예제 #15
0
    def test_allows_varkwargs_if_specified(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).method_with_varkwargs.with_args(foo='bar')

        assert doubled_user.method_with_varkwargs(foo='bar') is None
예제 #16
0
    def test_raises_when_specifying_extra_keyword_arguments(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleArgumentError):
            allow(doubled_user).method_with_default_args.with_args(1, moo='woof')
예제 #17
0
    def test_raises_when_specifying_higher_arity_to_method_with_default_arguments(self, test_object):  # noqa
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleArgumentError):
            allow(doubled_user).method_with_default_args.with_args(1, 2, 3)
예제 #18
0
    def test_raises_when_specifying_higher_arity_to_method_with_default_arguments(
            self, test_object):  # noqa
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleArgumentError):
            allow(doubled_user).method_with_default_args.with_args(1, 2, 3)
예제 #19
0
    def test_raises_when_specifying_different_arity(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleArgumentError):
            allow(doubled_user).get_name.with_args('foo', 'bar')
예제 #20
0
    def test_allows_varargs_if_specified(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).method_with_varargs.with_args('foo', 'bar', 'baz')

        assert doubled_user.method_with_varargs('foo', 'bar', 'baz') is None
예제 #21
0
    def test_allows_stubs_on_existing_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).get_name.and_return('Bob')

        assert doubled_user.get_name() == 'Bob'
예제 #22
0
    def test_mocking__call__works(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).__call__.and_return('bob barker')

        assert doubled_user() == 'bob barker'
예제 #23
0
    def test_raises_when_specifying_extra_keyword_arguments(self, test_object):
        doubled_user = ObjectDouble(test_object)

        with raises(VerifyingDoubleArgumentError):
            allow(doubled_user).method_with_default_args.with_args(1,
                                                                   moo='woof')
예제 #24
0
    def test_allows_missing_default_arguments(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).method_with_default_args.with_args('blah')

        assert doubled_user.method_with_default_args('blah') is None
예제 #25
0
    def test_allows_stubs_on_existing_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).get_name.and_return('Bob')

        assert doubled_user.get_name() == 'Bob'
예제 #26
0
    def test_allows_default_arguments_specified_with_keywords(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).method_with_default_args.with_args('blah', bar='blam')

        assert doubled_user.method_with_default_args('blah', bar='blam') is None
예제 #27
0
    def test_mocking__call__works(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).__call__.and_return('bob barker')

        assert doubled_user() == 'bob barker'
예제 #28
0
    def test_allows_missing_default_arguments(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).method_with_default_args.with_args('blah')

        assert doubled_user.method_with_default_args('blah') is None