Skip to content

Commit

Permalink
Stackless issue python#286: Fix test case test_pickle.TextCopy
Browse files Browse the repository at this point in the history
The test always succeeded for objects considered immutable by
copy.copy().
  • Loading branch information
Anselm Kruis committed Jul 9, 2021
1 parent 1c04e79 commit 0419666
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Stackless/unittests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import struct
import warnings
import subprocess
import numbers
import stackless

from textwrap import dedent
Expand Down Expand Up @@ -1169,7 +1170,12 @@ class TestCopy(StacklessTestCase):

def _test(self, obj, *attributes, **kw):
expected_type = kw.get("expected_type", type(obj))
c = copy.copy(obj)
copier = copy._copy_dispatch.pop(type(obj), None)
try:
c = copy.copy(obj)
finally:
if copier is not None:
copy._copy_dispatch[type(obj)] = copier
try:
obj_hash = hash(obj)
except TypeError:
Expand All @@ -1184,7 +1190,10 @@ def _test(self, obj, *attributes, **kw):
value_c = getattr(c, name)
# it is a shallow copy, therefore the attributes should
# refer to the same objects
self.assertIs(value_c, value_obj)
if type(value_obj) is type(value_c) and isinstance(value_obj, numbers.Number):
self.assertEqual(value_c, value_obj, "{!r} != {!r} (attribute {})".format(value_c, value_obj, name))
else:
self.assertIs(value_c, value_obj, "{!r} is not {!r} (attribute {})".format(value_c, value_obj, name))
return c

def test_module_stackless(self):
Expand Down

0 comments on commit 0419666

Please sign in to comment.