gh-99430: Remove duplicated tests for old-styled classes (#99432)

python 1 & 2 were a loong time ago.
This commit is contained in:
Nikita Sobolev 2022-11-13 21:30:00 +03:00 committed by GitHub
parent 439b9cfaf4
commit d329f859b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 139 deletions

View File

@ -2,85 +2,7 @@
import types import types
class A_classic: class A_new:
"A classic class."
def A_method(self):
"Method defined in A."
def AB_method(self):
"Method defined in A and B."
def AC_method(self):
"Method defined in A and C."
def AD_method(self):
"Method defined in A and D."
def ABC_method(self):
"Method defined in A, B and C."
def ABD_method(self):
"Method defined in A, B and D."
def ACD_method(self):
"Method defined in A, C and D."
def ABCD_method(self):
"Method defined in A, B, C and D."
class B_classic(A_classic):
"A classic class, derived from A_classic."
def AB_method(self):
"Method defined in A and B."
def ABC_method(self):
"Method defined in A, B and C."
def ABD_method(self):
"Method defined in A, B and D."
def ABCD_method(self):
"Method defined in A, B, C and D."
def B_method(self):
"Method defined in B."
def BC_method(self):
"Method defined in B and C."
def BD_method(self):
"Method defined in B and D."
def BCD_method(self):
"Method defined in B, C and D."
class C_classic(A_classic):
"A classic class, derived from A_classic."
def AC_method(self):
"Method defined in A and C."
def ABC_method(self):
"Method defined in A, B and C."
def ACD_method(self):
"Method defined in A, C and D."
def ABCD_method(self):
"Method defined in A, B, C and D."
def BC_method(self):
"Method defined in B and C."
def BCD_method(self):
"Method defined in B, C and D."
def C_method(self):
"Method defined in C."
def CD_method(self):
"Method defined in C and D."
class D_classic(B_classic, C_classic):
"A classic class, derived from B_classic and C_classic."
def AD_method(self):
"Method defined in A and D."
def ABD_method(self):
"Method defined in A, B and D."
def ACD_method(self):
"Method defined in A, C and D."
def ABCD_method(self):
"Method defined in A, B, C and D."
def BD_method(self):
"Method defined in B and D."
def BCD_method(self):
"Method defined in B, C and D."
def CD_method(self):
"Method defined in C and D."
def D_method(self):
"Method defined in D."
class A_new(object):
"A new-style class." "A new-style class."
def A_method(self): def A_method(self):

View File

@ -88,9 +88,7 @@ class TestCopy(unittest.TestCase):
# Type-specific _copy_xxx() methods # Type-specific _copy_xxx() methods
def test_copy_atomic(self): def test_copy_atomic(self):
class Classic: class NewStyle:
pass
class NewStyle(object):
pass pass
def f(): def f():
pass pass
@ -100,7 +98,7 @@ class TestCopy(unittest.TestCase):
42, 2**100, 3.14, True, False, 1j, 42, 2**100, 3.14, True, False, 1j,
"hello", "hello\u1234", f.__code__, "hello", "hello\u1234", f.__code__,
b"world", bytes(range(256)), range(10), slice(1, 10, 2), b"world", bytes(range(256)), range(10), slice(1, 10, 2),
NewStyle, Classic, max, WithMetaclass, property()] NewStyle, max, WithMetaclass, property()]
for x in tests: for x in tests:
self.assertIs(copy.copy(x), x) self.assertIs(copy.copy(x), x)
@ -350,15 +348,13 @@ class TestCopy(unittest.TestCase):
# Type-specific _deepcopy_xxx() methods # Type-specific _deepcopy_xxx() methods
def test_deepcopy_atomic(self): def test_deepcopy_atomic(self):
class Classic: class NewStyle:
pass
class NewStyle(object):
pass pass
def f(): def f():
pass pass
tests = [None, 42, 2**100, 3.14, True, False, 1j, tests = [None, 42, 2**100, 3.14, True, False, 1j,
"hello", "hello\u1234", f.__code__, "hello", "hello\u1234", f.__code__,
NewStyle, range(10), Classic, max, property()] NewStyle, range(10), max, property()]
for x in tests: for x in tests:
self.assertIs(copy.deepcopy(x), x) self.assertIs(copy.deepcopy(x), x)

View File

@ -3261,12 +3261,8 @@ order (MRO) for bases """
if otype: if otype:
otype = otype.__name__ otype = otype.__name__
return 'object=%s; type=%s' % (object, otype) return 'object=%s; type=%s' % (object, otype)
class OldClass: class NewClass:
__doc__ = DocDescr() __doc__ = DocDescr()
class NewClass(object):
__doc__ = DocDescr()
self.assertEqual(OldClass.__doc__, 'object=None; type=OldClass')
self.assertEqual(OldClass().__doc__, 'object=OldClass instance; type=OldClass')
self.assertEqual(NewClass.__doc__, 'object=None; type=NewClass') self.assertEqual(NewClass.__doc__, 'object=None; type=NewClass')
self.assertEqual(NewClass().__doc__, 'object=NewClass instance; type=NewClass') self.assertEqual(NewClass().__doc__, 'object=NewClass instance; type=NewClass')

View File

@ -542,48 +542,6 @@ class GCTests(unittest.TestCase):
self.assertEqual(gc.collect(), 2) self.assertEqual(gc.collect(), 2)
self.assertEqual(len(gc.garbage), garbagelen) self.assertEqual(len(gc.garbage), garbagelen)
def test_boom_new(self):
# boom__new and boom2_new are exactly like boom and boom2, except use
# new-style classes.
class Boom_New(object):
def __getattr__(self, someattribute):
del self.attr
raise AttributeError
a = Boom_New()
b = Boom_New()
a.attr = b
b.attr = a
gc.collect()
garbagelen = len(gc.garbage)
del a, b
self.assertEqual(gc.collect(), 2)
self.assertEqual(len(gc.garbage), garbagelen)
def test_boom2_new(self):
class Boom2_New(object):
def __init__(self):
self.x = 0
def __getattr__(self, someattribute):
self.x += 1
if self.x > 1:
del self.attr
raise AttributeError
a = Boom2_New()
b = Boom2_New()
a.attr = b
b.attr = a
gc.collect()
garbagelen = len(gc.garbage)
del a, b
self.assertEqual(gc.collect(), 2)
self.assertEqual(len(gc.garbage), garbagelen)
def test_get_referents(self): def test_get_referents(self):
alist = [1, 3, 5] alist = [1, 3, 5]
got = gc.get_referents(alist) got = gc.get_referents(alist)

View File

@ -2380,12 +2380,7 @@ class UnicodeTest(string_tests.CommonTest,
def __repr__(self): def __repr__(self):
return '\\n' return '\\n'
class s2:
def __repr__(self):
return '\\n'
self.assertEqual(repr(s1()), '\\n') self.assertEqual(repr(s1()), '\\n')
self.assertEqual(repr(s2()), '\\n')
def test_printable_repr(self): def test_printable_repr(self):
self.assertEqual(repr('\U00010000'), "'%c'" % (0x10000,)) # printable self.assertEqual(repr('\U00010000'), "'%c'" % (0x10000,)) # printable