summaryrefslogtreecommitdiff
path: root/dev-python/testfixtures/files/testfixtures-6.18.1-py3.10.patch
blob: cd1ecbd8133dcbb1c936d49c2e7a8eb103926ee5 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
From 8fb2122eea0f1d0de1ccca7a3a0f5426bc6d4964 Mon Sep 17 00:00:00 2001
From: Louis Sautier <sautier.louis@gmail.com>
Date: Sat, 21 Aug 2021 03:00:51 +0200
Subject: [PATCH] tests: fix with Python 3.10 (changed exception messages)

---
 testfixtures/compat.py             |  1 +
 testfixtures/tests/test_popen.py   | 41 ++++++++++++++++++------------
 testfixtures/tests/test_replace.py | 24 ++++++++++-------
 3 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/testfixtures/compat.py b/testfixtures/compat.py
index 1042d27..ca00f32 100644
--- a/testfixtures/compat.py
+++ b/testfixtures/compat.py
@@ -5,6 +5,7 @@
 
 PY_36_PLUS = PY_VERSION >= (3, 6)
 PY_37_PLUS = PY_VERSION >= (3, 7)
+PY_310_PLUS = PY_VERSION >= (3, 10)
 
 
 if PY_VERSION > (3, 0):
diff --git a/testfixtures/tests/test_popen.py b/testfixtures/tests/test_popen.py
index aa211da..4ec3186 100644
--- a/testfixtures/tests/test_popen.py
+++ b/testfixtures/tests/test_popen.py
@@ -6,7 +6,7 @@
 from testfixtures import ShouldRaise, compare, Replacer
 
 from testfixtures.popen import MockPopen, PopenBehaviour
-from testfixtures.compat import BytesLiteral, PY2
+from testfixtures.compat import BytesLiteral, PY2, PY_310_PLUS
 
 import signal
 
@@ -471,10 +471,11 @@ def test_default_command_max_args(self):
         ], Popen.mock.method_calls)
 
     def test_invalid_parameters(self):
+        message = "__init__() got an unexpected keyword argument 'foo'"
+        if PY_310_PLUS:
+            message = "MockPopenInstance." + message
         Popen = MockPopen()
-        with ShouldRaise(TypeError(
-                "__init__() got an unexpected keyword argument 'foo'"
-        )):
+        with ShouldRaise(TypeError(message)):
             Popen(foo='bar')
 
     def test_invalid_method_or_attr(self):
@@ -492,39 +493,43 @@ def test_invalid_attribute(self):
             process.foo
 
     def test_invalid_communicate_call(self):
+        message = "communicate() got an unexpected keyword argument 'foo'"
+        if PY_310_PLUS:
+            message = "MockPopenInstance." + message
         Popen = MockPopen()
         Popen.set_command('bar')
         process = Popen('bar')
-        with ShouldRaise(TypeError(
-                "communicate() got an unexpected keyword argument 'foo'"
-        )):
+        with ShouldRaise(TypeError(message)):
             process.communicate(foo='bar')
 
     def test_invalid_wait_call(self):
+        message = "wait() got an unexpected keyword argument 'foo'"
+        if PY_310_PLUS:
+            message = "MockPopenInstance." + message
         Popen = MockPopen()
         Popen.set_command('bar')
         process = Popen('bar')
-        with ShouldRaise(TypeError(
-                "wait() got an unexpected keyword argument 'foo'"
-        )):
+        with ShouldRaise(TypeError(message)):
             process.wait(foo='bar')
 
     def test_invalid_send_signal(self):
+        message = "send_signal() got an unexpected keyword argument 'foo'"
+        if PY_310_PLUS:
+            message = "MockPopenInstance." + message
         Popen = MockPopen()
         Popen.set_command('bar')
         process = Popen('bar')
-        with ShouldRaise(TypeError(
-                "send_signal() got an unexpected keyword argument 'foo'"
-        )):
+        with ShouldRaise(TypeError(message)):
             process.send_signal(foo='bar')
 
     def test_invalid_terminate(self):
+        message = "terminate() got an unexpected keyword argument 'foo'"
+        if PY_310_PLUS:
+            message = "MockPopenInstance." + message
         Popen = MockPopen()
         Popen.set_command('bar')
         process = Popen('bar')
-        with ShouldRaise(TypeError(
-                "terminate() got an unexpected keyword argument 'foo'"
-        )):
+        with ShouldRaise(TypeError(message)):
             process.terminate(foo='bar')
 
     def test_invalid_kill(self):
@@ -535,6 +540,8 @@ def test_invalid_kill(self):
             text = 'kill() takes exactly 1 argument (2 given)'
         else:
             text = 'kill() takes 1 positional argument but 2 were given'
+            if PY_310_PLUS:
+                text = "MockPopenInstance." + text
         with ShouldRaise(TypeError(text)):
             process.kill('moo')
 
@@ -546,6 +553,8 @@ def test_invalid_poll(self):
             text = 'poll() takes exactly 1 argument (2 given)'
         else:
             text = 'poll() takes 1 positional argument but 2 were given'
+            if PY_310_PLUS:
+                text = "MockPopenInstance." + text
         with ShouldRaise(TypeError(text)):
             process.poll('moo')
 
diff --git a/testfixtures/tests/test_replace.py b/testfixtures/tests/test_replace.py
index 5a77e23..d3544a8 100644
--- a/testfixtures/tests/test_replace.py
+++ b/testfixtures/tests/test_replace.py
@@ -13,7 +13,7 @@
 
 from testfixtures.tests import sample1
 from testfixtures.tests import sample2
-from ..compat import PY3
+from ..compat import PY3, PY_310_PLUS
 
 from warnings import catch_warnings
 
@@ -259,19 +259,25 @@ def test_something(obj):
         self.failIf(hasattr(sample1, 'foo'))
 
     def test_replace_delattr_cant_remove(self):
+        if PY_310_PLUS:
+            message = "cannot set 'today' attribute of " \
+                      "immutable type 'datetime.datetime'"
+        else:
+            message = "can't set attributes of " \
+                      "built-in/extension type 'datetime.datetime'"
         with Replacer() as r:
-            with ShouldRaise(TypeError(
-                "can't set attributes of "
-                "built-in/extension type 'datetime.datetime'"
-                    )):
+            with ShouldRaise(TypeError(message)):
                 r.replace('datetime.datetime.today', not_there)
 
     def test_replace_delattr_cant_remove_not_strict(self):
+        if PY_310_PLUS:
+            message = "cannot set 'today' attribute of " \
+                      "immutable type 'datetime.datetime'"
+        else:
+            message = "can't set attributes of " \
+                      "built-in/extension type 'datetime.datetime'"
         with Replacer() as r:
-            with ShouldRaise(TypeError(
-                "can't set attributes of "
-                "built-in/extension type 'datetime.datetime'"
-                    )):
+            with ShouldRaise(TypeError(message)):
                 r.replace('datetime.datetime.today', not_there, strict=False)
 
     def test_replace_dict_remove_key(self):