Skip to content

Commit 0419666

Browse files
author
Anselm Kruis
committed
Stackless issue python#286: Fix test case test_pickle.TextCopy
The test always succeeded for objects considered immutable by copy.copy().
1 parent 1c04e79 commit 0419666

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Stackless/unittests/test_pickle.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import struct
1313
import warnings
1414
import subprocess
15+
import numbers
1516
import stackless
1617

1718
from textwrap import dedent
@@ -1169,7 +1170,12 @@ class TestCopy(StacklessTestCase):
11691170

11701171
def _test(self, obj, *attributes, **kw):
11711172
expected_type = kw.get("expected_type", type(obj))
1172-
c = copy.copy(obj)
1173+
copier = copy._copy_dispatch.pop(type(obj), None)
1174+
try:
1175+
c = copy.copy(obj)
1176+
finally:
1177+
if copier is not None:
1178+
copy._copy_dispatch[type(obj)] = copier
11731179
try:
11741180
obj_hash = hash(obj)
11751181
except TypeError:
@@ -1184,7 +1190,10 @@ def _test(self, obj, *attributes, **kw):
11841190
value_c = getattr(c, name)
11851191
# it is a shallow copy, therefore the attributes should
11861192
# refer to the same objects
1187-
self.assertIs(value_c, value_obj)
1193+
if type(value_obj) is type(value_c) and isinstance(value_obj, numbers.Number):
1194+
self.assertEqual(value_c, value_obj, "{!r} != {!r} (attribute {})".format(value_c, value_obj, name))
1195+
else:
1196+
self.assertIs(value_c, value_obj, "{!r} is not {!r} (attribute {})".format(value_c, value_obj, name))
11881197
return c
11891198

11901199
def test_module_stackless(self):

0 commit comments

Comments
 (0)