MCPcopy Index your code
hub / github.com/python/cpython / test_basic_protocol

Method test_basic_protocol

Lib/test/test_typing.py:2858–2878  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2856
2857class ProtocolTests(BaseTestCase):
2858 def test_basic_protocol(self):
2859 @runtime_checkable
2860 class P(Protocol):
2861 def meth(self):
2862 pass
2863
2864 class C: pass
2865
2866 class D:
2867 def meth(self):
2868 pass
2869
2870 def f():
2871 pass
2872
2873 self.assertIsSubclass(D, P)
2874 self.assertIsInstance(D(), P)
2875 self.assertNotIsSubclass(C, P)
2876 self.assertNotIsInstance(C(), P)
2877 self.assertNotIsSubclass(types.FunctionType, P)
2878 self.assertNotIsInstance(f, P)
2879
2880 def test_runtime_checkable_generic_non_protocol(self):
2881 # Make sure this doesn't raise AttributeError

Callers

nothing calls this directly

Calls 6

assertIsSubclassMethod · 0.80
assertIsInstanceMethod · 0.80
assertNotIsSubclassMethod · 0.80
assertNotIsInstanceMethod · 0.80
DClass · 0.70
CClass · 0.70

Tested by

no test coverage detected