Add tests for using PEP560 with classes implemented in C. (#4883)

Based on tests from #4878
This commit is contained in:
Serhiy Storchaka 2017-12-16 11:25:56 +02:00 committed by Ivan Levkivskyi
parent 9c19b02024
commit 45700fb757
2 changed files with 103 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import unittest
from test import support
class TestMROEntry(unittest.TestCase):
@ -248,5 +249,22 @@ class TestClassGetitem(unittest.TestCase):
self.assertEqual(C[int], 'from metaclass')
@support.cpython_only
class CAPITest(unittest.TestCase):
def test_c_class(self):
from _testcapi import Generic, GenericAlias
self.assertIsInstance(Generic.__class_getitem__(Generic, int), GenericAlias)
IntGeneric = Generic[int]
self.assertIs(type(IntGeneric), GenericAlias)
self.assertEqual(IntGeneric.__mro_entries__(()), (int,))
class C(IntGeneric):
pass
self.assertEqual(C.__bases__, (int,))
self.assertEqual(C.__orig_bases__, (IntGeneric,))
self.assertEqual(C.__mro__, (C, int, object))
if __name__ == "__main__":
unittest.main()