https://github.com/python/cpython/commit/36aaf4137d55df3e324d98ec06b983b0287d8949
commit: 36aaf4137d55df3e324d98ec06b983b0287d8949
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-01-20T11:19:43+02:00
summary:

gh-71339: Use new assertion methods in test_abc (GH-128826)

files:
M Lib/test/test_abc.py

diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 5ce57cc209ea85..e90a8dc617c094 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -20,7 +20,7 @@ def test_abstractproperty_basics(self):
             def foo(self): pass
             self.assertTrue(foo.__isabstractmethod__)
             def bar(self): pass
-            self.assertFalse(hasattr(bar, "__isabstractmethod__"))
+            self.assertNotHasAttr(bar, "__isabstractmethod__")
 
             class C(metaclass=abc_ABCMeta):
                 @abc.abstractproperty
@@ -89,7 +89,7 @@ def test_abstractmethod_basics(self):
             def foo(self): pass
             self.assertTrue(foo.__isabstractmethod__)
             def bar(self): pass
-            self.assertFalse(hasattr(bar, "__isabstractmethod__"))
+            self.assertNotHasAttr(bar, "__isabstractmethod__")
 
         def test_abstractproperty_basics(self):
             @property
@@ -276,21 +276,21 @@ class A(metaclass=abc_ABCMeta):
             class B(object):
                 pass
             b = B()
-            self.assertFalse(issubclass(B, A))
-            self.assertFalse(issubclass(B, (A,)))
+            self.assertNotIsSubclass(B, A)
+            self.assertNotIsSubclass(B, (A,))
             self.assertNotIsInstance(b, A)
             self.assertNotIsInstance(b, (A,))
             B1 = A.register(B)
-            self.assertTrue(issubclass(B, A))
-            self.assertTrue(issubclass(B, (A,)))
+            self.assertIsSubclass(B, A)
+            self.assertIsSubclass(B, (A,))
             self.assertIsInstance(b, A)
             self.assertIsInstance(b, (A,))
             self.assertIs(B1, B)
             class C(B):
                 pass
             c = C()
-            self.assertTrue(issubclass(C, A))
-            self.assertTrue(issubclass(C, (A,)))
+            self.assertIsSubclass(C, A)
+            self.assertIsSubclass(C, (A,))
             self.assertIsInstance(c, A)
             self.assertIsInstance(c, (A,))
 
@@ -301,16 +301,16 @@ class A(metaclass=abc_ABCMeta):
             class B(object):
                 pass
             b = B()
-            self.assertTrue(issubclass(B, A))
-            self.assertTrue(issubclass(B, (A,)))
+            self.assertIsSubclass(B, A)
+            self.assertIsSubclass(B, (A,))
             self.assertIsInstance(b, A)
             self.assertIsInstance(b, (A,))
             @A.register
             class C(B):
                 pass
             c = C()
-            self.assertTrue(issubclass(C, A))
-            self.assertTrue(issubclass(C, (A,)))
+            self.assertIsSubclass(C, A)
+            self.assertIsSubclass(C, (A,))
             self.assertIsInstance(c, A)
             self.assertIsInstance(c, (A,))
             self.assertIs(C, A.register(C))
@@ -321,14 +321,14 @@ class A(metaclass=abc_ABCMeta):
             class B:
                 pass
             b = B()
-            self.assertFalse(isinstance(b, A))
-            self.assertFalse(isinstance(b, (A,)))
+            self.assertNotIsInstance(b, A)
+            self.assertNotIsInstance(b, (A,))
             token_old = abc_get_cache_token()
             A.register(B)
             token_new = abc_get_cache_token()
             self.assertGreater(token_new, token_old)
-            self.assertTrue(isinstance(b, A))
-            self.assertTrue(isinstance(b, (A,)))
+            self.assertIsInstance(b, A)
+            self.assertIsInstance(b, (A,))
 
         def test_registration_builtins(self):
             class A(metaclass=abc_ABCMeta):
@@ -336,18 +336,18 @@ class A(metaclass=abc_ABCMeta):
             A.register(int)
             self.assertIsInstance(42, A)
             self.assertIsInstance(42, (A,))
-            self.assertTrue(issubclass(int, A))
-            self.assertTrue(issubclass(int, (A,)))
+            self.assertIsSubclass(int, A)
+            self.assertIsSubclass(int, (A,))
             class B(A):
                 pass
             B.register(str)
             class C(str): pass
             self.assertIsInstance("", A)
             self.assertIsInstance("", (A,))
-            self.assertTrue(issubclass(str, A))
-            self.assertTrue(issubclass(str, (A,)))
-            self.assertTrue(issubclass(C, A))
-            self.assertTrue(issubclass(C, (A,)))
+            self.assertIsSubclass(str, A)
+            self.assertIsSubclass(str, (A,))
+            self.assertIsSubclass(C, A)
+            self.assertIsSubclass(C, (A,))
 
         def test_registration_edge_cases(self):
             class A(metaclass=abc_ABCMeta):
@@ -375,39 +375,39 @@ class A(metaclass=abc_ABCMeta):
         def test_registration_transitiveness(self):
             class A(metaclass=abc_ABCMeta):
                 pass
-            self.assertTrue(issubclass(A, A))
-            self.assertTrue(issubclass(A, (A,)))
+            self.assertIsSubclass(A, A)
+            self.assertIsSubclass(A, (A,))
             class B(metaclass=abc_ABCMeta):
                 pass
-            self.assertFalse(issubclass(A, B))
-            self.assertFalse(issubclass(A, (B,)))
-            self.assertFalse(issubclass(B, A))
-            self.assertFalse(issubclass(B, (A,)))
+            self.assertNotIsSubclass(A, B)
+            self.assertNotIsSubclass(A, (B,))
+            self.assertNotIsSubclass(B, A)
+            self.assertNotIsSubclass(B, (A,))
             class C(metaclass=abc_ABCMeta):
                 pass
             A.register(B)
             class B1(B):
                 pass
-            self.assertTrue(issubclass(B1, A))
-            self.assertTrue(issubclass(B1, (A,)))
+            self.assertIsSubclass(B1, A)
+            self.assertIsSubclass(B1, (A,))
             class C1(C):
                 pass
             B1.register(C1)
-            self.assertFalse(issubclass(C, B))
-            self.assertFalse(issubclass(C, (B,)))
-            self.assertFalse(issubclass(C, B1))
-            self.assertFalse(issubclass(C, (B1,)))
-            self.assertTrue(issubclass(C1, A))
-            self.assertTrue(issubclass(C1, (A,)))
-            self.assertTrue(issubclass(C1, B))
-            self.assertTrue(issubclass(C1, (B,)))
-            self.assertTrue(issubclass(C1, B1))
-            self.assertTrue(issubclass(C1, (B1,)))
+            self.assertNotIsSubclass(C, B)
+            self.assertNotIsSubclass(C, (B,))
+            self.assertNotIsSubclass(C, B1)
+            self.assertNotIsSubclass(C, (B1,))
+            self.assertIsSubclass(C1, A)
+            self.assertIsSubclass(C1, (A,))
+            self.assertIsSubclass(C1, B)
+            self.assertIsSubclass(C1, (B,))
+            self.assertIsSubclass(C1, B1)
+            self.assertIsSubclass(C1, (B1,))
             C1.register(int)
             class MyInt(int):
                 pass
-            self.assertTrue(issubclass(MyInt, A))
-            self.assertTrue(issubclass(MyInt, (A,)))
+            self.assertIsSubclass(MyInt, A)
+            self.assertIsSubclass(MyInt, (A,))
             self.assertIsInstance(42, A)
             self.assertIsInstance(42, (A,))
 
@@ -467,16 +467,16 @@ def __subclasshook__(cls, C):
                     if cls is A:
                         return 'foo' in C.__dict__
                     return NotImplemented
-            self.assertFalse(issubclass(A, A))
-            self.assertFalse(issubclass(A, (A,)))
+            self.assertNotIsSubclass(A, A)
+            self.assertNotIsSubclass(A, (A,))
             class B:
                 foo = 42
-            self.assertTrue(issubclass(B, A))
-            self.assertTrue(issubclass(B, (A,)))
+            self.assertIsSubclass(B, A)
+            self.assertIsSubclass(B, (A,))
             class C:
                 spam = 42
-            self.assertFalse(issubclass(C, A))
-            self.assertFalse(issubclass(C, (A,)))
+            self.assertNotIsSubclass(C, A)
+            self.assertNotIsSubclass(C, (A,))
 
         def test_all_new_methods_are_called(self):
             class A(metaclass=abc_ABCMeta):
@@ -493,7 +493,7 @@ class C(A, B):
             self.assertEqual(B.counter, 1)
 
         def test_ABC_has___slots__(self):
-            self.assertTrue(hasattr(abc.ABC, '__slots__'))
+            self.assertHasAttr(abc.ABC, '__slots__')
 
         def test_tricky_new_works(self):
             def with_metaclass(meta, *bases):
@@ -515,7 +515,7 @@ def foo(self):
 
             del A.foo
             self.assertEqual(A.__abstractmethods__, {'foo'})
-            self.assertFalse(hasattr(A, 'foo'))
+            self.assertNotHasAttr(A, 'foo')
 
             abc.update_abstractmethods(A)
 
@@ -588,7 +588,7 @@ def updated_foo(self):
             A.foo = updated_foo
             abc.update_abstractmethods(A)
             A()
-            self.assertFalse(hasattr(A, '__abstractmethods__'))
+            self.assertNotHasAttr(A, '__abstractmethods__')
 
         def test_update_del_implementation(self):
             class A(metaclass=abc_ABCMeta):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to