File: call_count.py

package info (click to toggle)
python-flexmock 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: python: 3,802; makefile: 17; sh: 14
file content (76 lines) | stat: -rw-r--r-- 2,642 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Tests for call count modifiers."""

# pylint: disable=missing-docstring,no-member

from flexmock import exceptions, flexmock
from flexmock._api import flexmock_teardown
from tests.utils import assert_raises


class CallCountTestCase:
    def test_support_at_least_and_at_most_together(self):
        class Foo:
            def method(self):
                pass

        instance = Foo()
        flexmock(instance).should_call("method").at_least().once().at_most().twice()
        with assert_raises(
            exceptions.MethodCallError,
            "method() expected to be called at least 1 time and at most 2 times, called 0 times",
        ):
            flexmock_teardown()

        flexmock(instance).should_call("method").at_least().once().at_most().twice()
        instance.method()
        instance.method()
        with assert_raises(
            exceptions.MethodCallError,
            "method() expected to be called at most 2 times, called 3 times",
        ):
            instance.method()

        flexmock(instance).should_call("method").at_least().once().at_most().twice()
        instance.method()
        flexmock_teardown()

        flexmock(instance).should_call("method").at_least().once().at_most().twice()
        instance.method()
        instance.method()
        flexmock_teardown()

    def test_at_least_cannot_be_used_twice(self):
        class Foo:
            def method(self):
                pass

        expectation = flexmock(Foo).should_receive("method")
        with assert_raises(exceptions.FlexmockError, "cannot use at_least modifier twice"):
            expectation.at_least().at_least()

    def test_at_most_cannot_be_used_twice(self):
        class Foo:
            def method(self):
                pass

        expectation = flexmock(Foo).should_receive("method")
        with assert_raises(exceptions.FlexmockError, "cannot use at_most modifier twice"):
            expectation.at_most().at_most()

    def test_at_least_cannot_be_specified_until_at_most_is_set(self):
        class Foo:
            def method(self):
                pass

        expectation = flexmock(Foo).should_receive("method")
        with assert_raises(exceptions.FlexmockError, "cannot use at_most with at_least unset"):
            expectation.at_least().at_most()

    def test_at_most_cannot_be_specified_until_at_least_is_set(self):
        class Foo:
            def method(self):
                pass

        expectation = flexmock(Foo).should_receive("method")
        with assert_raises(exceptions.FlexmockError, "cannot use at_least with at_most unset"):
            expectation.at_most().at_least()