summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_abc.py
diff options
context:
space:
mode:
authorKarl Dubost <karl+github@la-grange.net>2021-05-12 13:05:45 (GMT)
committerGitHub <noreply@github.com>2021-05-12 13:05:45 (GMT)
commit5010c044c73ee55d0fd578cfecd3f4c3f01a4140 (patch)
tree61e8bcc241860e371dc03844263d81d24c79fbcd /Lib/test/test_abc.py
parent117bfd2b7141127b18d5ca4d6bbc4b3068bbce33 (diff)
downloadcpython-5010c044c73ee55d0fd578cfecd3f4c3f01a4140.zip
cpython-5010c044c73ee55d0fd578cfecd3f4c3f01a4140.tar.gz
cpython-5010c044c73ee55d0fd578cfecd3f4c3f01a4140.tar.bz2
bpo-25479: add unit test for __subclasshook__ in test_abc.py (GH-24034)
Co-authored-by: Szymon Trapp
Diffstat (limited to 'Lib/test/test_abc.py')
-rw-r--r--Lib/test/test_abc.py18
1 files changed, 18 insertions, 0 deletions
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