Exemplo n.º 1
0
    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()
Exemplo n.º 2
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
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    def test_passes_when_called_twice(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.twice()

        subject.instance_method()
        subject.instance_method()
Exemplo n.º 5
0
    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')
Exemplo n.º 6
0
    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')
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
    def test_passes_when_called_twice(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.twice()

        subject.instance_method()
        subject.instance_method()
Exemplo n.º 9
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
Exemplo n.º 10
0
    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()
Exemplo n.º 11
0
    def test_satisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

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

        with subject:
            pass
Exemplo n.º 12
0
    def test_satisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

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

        with subject:
            pass
Exemplo n.º 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()
Exemplo n.º 14
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()
Exemplo n.º 15
0
    def test_unsatisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).__exit__.once()

        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected '__exit__' to be called 1 time instead of 0 times on "
            r"<InstanceDouble of <class 'doubles.testing.User'> object at .+> "
            r"with any args, but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)", str(e.value))
Exemplo n.º 16
0
    def test_fails_when_called_once(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.twice()

        subject.instance_method()
        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected 'instance_method' to be called 2 times instead of 1 time on "
            r"<InstanceDouble of <class 'doubles.testing.User'> object at .+> "
            r"with any args, but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)", str(e.value))
Exemplo n.º 17
0
    def test_fails_when_called_more_than_at_most_times(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.at_most(1).times

        subject.instance_method()
        with raises(MockExpectationError) as e:
            subject.instance_method()
        teardown()

        assert re.match(
            r"Expected 'instance_method' to be called at most 1 time instead of 2 times on "
            r"<InstanceDouble of <class 'doubles.testing.User'> object at .+> "
            r"with any args, but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)", str(e.value))
Exemplo n.º 18
0
    def test_raises_if_an_expected_method_call_with_args_is_not_made(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).method_with_varargs.with_args('bar')

        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected 'method_with_varargs' to be called on "
            r"<InstanceDouble of <class '?doubles.testing.User'?"
            r"(?: at 0x[0-9a-f]{9})?> object at .+> "
            r"with \('bar'\), but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)", str(e.value))
Exemplo n.º 19
0
    def test_unsatisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).__exit__.once()

        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected '__exit__' to be called 1 time instead of 0 times on "
            r"<InstanceDouble of <class 'doubles.testing.User'> object at .+> "
            r"with any args, but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)",
            str(e.value)
        )
Exemplo n.º 20
0
    def test_with_args_validator_not_called(self):
        subject = InstanceDouble('doubles.testing.User')

        def arg_matcher(*args):
            return True

        expect(subject).method_with_varargs.with_args_validator(arg_matcher)
        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected 'method_with_varargs' to be called on "
            r"<InstanceDouble of <class '?doubles.testing.User'?"
            r"(?: at 0x[0-9a-f]{9})?> object at .+> "
            r"with custom matcher: 'arg_matcher', but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)", str(e.value))
Exemplo n.º 21
0
    def test_fails_when_called_once(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.twice()

        subject.instance_method()
        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected 'instance_method' to be called 2 times instead of 1 time on "
            r"<InstanceDouble of <class 'doubles.testing.User'> object at .+> "
            r"with any args, but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)",
            str(e.value)
        )
Exemplo n.º 22
0
    def test_fails_when_called_more_than_at_most_times(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.at_most(1).times

        subject.instance_method()
        with raises(MockExpectationError) as e:
            subject.instance_method()
        teardown()

        assert re.match(
            r"Expected 'instance_method' to be called at most 1 time instead of 2 times on "
            r"<InstanceDouble of <class 'doubles.testing.User'> object at .+> "
            r"with any args, but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)",
            str(e.value)
        )
Exemplo n.º 23
0
    def test_raises_if_an_expected_method_call_with_default_args_is_not_made(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).method_with_default_args.with_args('bar', bar='barker')

        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected 'method_with_default_args' to be called on "
            r"<InstanceDouble of <class '?doubles.testing.User'?"
            r"(?: at 0x[0-9a-f]{9})?> object at .+> "
            r"with \('bar', bar='barker'\), but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)",
            str(e.value)
        )
Exemplo n.º 24
0
    def test_with_args_validator_not_called(self):
        subject = InstanceDouble('doubles.testing.User')

        def arg_matcher(*args):
            return True
        expect(subject).method_with_varargs.with_args_validator(arg_matcher)
        with raises(MockExpectationError) as e:
            verify()
        teardown()

        assert re.match(
            r"Expected 'method_with_varargs' to be called on "
            r"<InstanceDouble of <class '?doubles.testing.User'?"
            r"(?: at 0x[0-9a-f]{9})?> object at .+> "
            r"with custom matcher: 'arg_matcher', but was not."
            r" \(.*doubles/test/expect_test.py:\d+\)",
            str(e.value)
        )
Exemplo n.º 25
0
    def test_passes_when_called_never(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.never()
Exemplo n.º 26
0
    def test_satisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).__call__.once()

        subject()
Exemplo n.º 27
0
    def test_passes_when_called_exactly_expected_times(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.exactly(1).times

        subject.instance_method()
Exemplo n.º 28
0
    def test_satisfied_expectation(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).__call__.once()

        subject()
Exemplo n.º 29
0
    def test_passes_if_an_expected_method_call_is_made(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method

        subject.instance_method()
Exemplo n.º 30
0
    def test_passes_when_called_exactly_expected_times(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.exactly(1).times

        subject.instance_method()
Exemplo n.º 31
0
    def test_passes_when_called_never(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method.never()
Exemplo n.º 32
0
    def test_passes_if_method_is_called_with_specified_arguments(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).method_with_default_args.with_args('one', bar='two')

        assert subject.method_with_default_args('one', bar='two') is None
Exemplo n.º 33
0
    def test_passes_if_method_is_called_with_specified_arguments(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).method_with_default_args.with_args('one', bar='two')

        assert subject.method_with_default_args('one', bar='two') is None
Exemplo n.º 34
0
    def test_passes_if_an_expected_method_call_is_made(self):
        subject = InstanceDouble('doubles.testing.User')

        expect(subject).instance_method

        subject.instance_method()
Exemplo n.º 35
0
                def runTest(self):
                    subject = InstanceDouble('doubles.testing.User')

                    expect(subject).instance_method