bpo-25479: add unit test for __subclasshook__ in test_abc.py (GH-24034)

Co-authored-by: Szymon Trapp
This commit is contained in:
Karl Dubost 2021-05-12 22:05:45 +09:00 committed by GitHub
parent 117bfd2b71
commit 5010c044c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -459,6 +459,24 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
with self.assertRaisesRegex(Exception, exc_msg):
issubclass(int, S)
def test_subclasshook(self):
class A(metaclass=abc.ABCMeta):
@classmethod
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,)))
class B:
foo = 42
self.assertTrue(issubclass(B, A))
self.assertTrue(issubclass(B, (A,)))
class C:
spam = 42
self.assertFalse(issubclass(C, A))
self.assertFalse(issubclass(C, (A,)))
def test_all_new_methods_are_called(self):
class A(metaclass=abc_ABCMeta):
pass