From 5010c044c73ee55d0fd578cfecd3f4c3f01a4140 Mon Sep 17 00:00:00 2001 From: Karl Dubost Date: Wed, 12 May 2021 22:05:45 +0900 Subject: bpo-25479: add unit test for __subclasshook__ in test_abc.py (GH-24034) Co-authored-by: Szymon Trapp --- Lib/test/test_abc.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py index 3d603e7..c1d750d 100644 --- a/Lib/test/test_abc.py +++ b/Lib/test/test_abc.py @@ -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 -- cgit v0.12