File: test__signature_checking_during_record.py

package info (click to toggle)
python-pyforge 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: python: 3,666; makefile: 12; sh: 7
file content (96 lines) | stat: -rw-r--r-- 3,064 bytes parent folder | download | duplicates (5)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from .ut_utils import ForgeTestCase
from forge import SignatureException

class call(object):
    def __init__(self, *args, **kwargs):
        self.func = args[0]
        self.args = args[1:]
        self.kwargs = kwargs

class SignatureCheckingTest(ForgeTestCase):
    def test__good_record(self):
        for good_call in self._iterate_valid_calls():
            stub = self.forge.create_function_stub(good_call.func)
            self.assertTrue(self.forge.is_recording())
            stub(*good_call.args, **good_call.kwargs)
            self.forge.replay()
            stub(*good_call.args, **good_call.kwargs)
            self.forge.verify()
            self.forge.reset()
    def test__signature_checking_on_record(self):
        for invalid_call in self._iterate_invalid_calls():
            stub = self.forge.create_function_stub(invalid_call.func)
            self.assertTrue(self.forge.is_recording())
            with self.assertRaises(SignatureException):
                stub(*invalid_call.args, **invalid_call.kwargs)

    def _iterate_valid_calls(self):
        def f():
            raise NotImplementedError()
        yield call(f)
        def f(a, b, c):
            raise NotImplementedError()
        yield call(f, 1, 2, 3)
        yield call(f, a=1, b=2, c=3)
        yield call(f, 1, 2, c=3)

        def f(a, b, c=2):
            raise NotImplementedError()
        yield call(f, 1, 2, 3)
        yield call(f, a=1, b=2, c=3)
        yield call(f, 1, 2)

        def f(a, b, c=2, *args):
            raise NotImplementedError()
        yield call(f, 1, 2, 3)
        yield call(f, 1, 2, 3, 4, 5)
        yield call(f, 1, 2, c=5)

        def f(a, b, c=2, **kwargs):
            raise NotImplementedError()
        yield call(f, 1, 2, 3)
        yield call(f, 1, 2, 3, d=5)
        yield call(f, 1, 2, c=2, d=5)

        def f(a, b, c=2, *args, **kwags):
            raise NotImplementedError()
        yield call(f, 1, 2, 3, 4, 5)
        yield call(f, 1, 2, 3, 4, 5, d=5, e=8)
    def _iterate_invalid_calls(self):
        def f():
            raise NotImplementedError()
        yield call(f, 2)
        yield call(f, c=3)

        def f(a, b, c):
            raise NotImplementedError()
        yield call(f)
        yield call(f, 1)
        yield call(f, 1, 2)
        yield call(f, 1, 2, 3, 4)
        yield call(f, 1, c=3)

        def f(a, b, c=2):
            raise NotImplementedError()
        yield call(f)
        yield call(f, 1)
        yield call(f, 1, 2, 3, 4)
        yield call(f, c=5)
        yield call(f, 1, c=5)
        def f(a, b, c=2, *args):
            raise NotImplementedError()
        yield call(f, 1, 2, d=5)
        yield call(f, 1, 2, 3, c=5)
        yield call(f, 1, 2, a=1)

        def f(a, b, c=2, **kwargs):
            raise NotImplementedError()
        yield call(f, 1, 2, 3, c=5)
        yield call(f, 1, 2, 3, 4)
        yield call(f, 1, c=2, d=5)

        def f(a, b, c=2, *args, **kwags):
            raise NotImplementedError()
        yield call(f, 1)
        yield call(f, 1, 2, 3, 4, 5, c=4)