Skip to content

Commit 44db2d2

Browse files
dslavicektomasr8
authored andcommitted
improve test_copy_reduce and test_deepcopy_reduce coverage (GH-154182)
* improve test_copy_reduce and test_deepcopy_reduce coverage * add assert __reduce_ex__ not called * change reduce params in test copy and deepcopy reduce_ex * change reduce_ex params in test copy and deepcopy reduce --------- (cherry picked from commit 4af81d9) Co-authored-by: David <slavicek.david29@gmail.com> Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
1 parent 042df0a commit 44db2d2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Lib/test/test_copy.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class C(object):
6060
def __reduce_ex__(self, proto):
6161
c.append(1)
6262
return ""
63-
def __reduce__(self):
63+
def __reduce__(*args):
6464
self.fail("shouldn't call this")
6565
c = []
6666
x = C()
@@ -70,9 +70,15 @@ def __reduce__(self):
7070

7171
def test_copy_reduce(self):
7272
class C(object):
73+
def __reduce_ex__(*args):
74+
self.fail("shouldn't call this")
7375
def __reduce__(self):
7476
c.append(1)
7577
return ""
78+
def __getattribute__(self, name):
79+
if name == "__reduce_ex__":
80+
raise AttributeError(name)
81+
return object.__getattribute__(self, name)
7682
c = []
7783
x = C()
7884
y = copy.copy(x)
@@ -329,7 +335,7 @@ class C(object):
329335
def __reduce_ex__(self, proto):
330336
c.append(1)
331337
return ""
332-
def __reduce__(self):
338+
def __reduce__(*args):
333339
self.fail("shouldn't call this")
334340
c = []
335341
x = C()
@@ -339,9 +345,15 @@ def __reduce__(self):
339345

340346
def test_deepcopy_reduce(self):
341347
class C(object):
348+
def __reduce_ex__(*args):
349+
self.fail("shouldn't call this")
342350
def __reduce__(self):
343351
c.append(1)
344352
return ""
353+
def __getattribute__(self, name):
354+
if name == "__reduce_ex__":
355+
raise AttributeError(name)
356+
return object.__getattribute__(self, name)
345357
c = []
346358
x = C()
347359
y = copy.deepcopy(x)

0 commit comments

Comments
 (0)