8000 [3.9] bpo-25479: add unit test for __subclasshook__ in test_abc.py (GH-24034) by miss-islington · Pull Request #26063 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.9] bpo-25479: add unit test for __subclasshook__ in test_abc.py (GH-24034) #26063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,24 @@ class S(metaclass=abc_ABCMeta):
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
Expand Down
0