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

Method test_descriptors_with_abstractmethod

Lib/test/test_abc.py:199–227  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

197 self.assertTrue(isabstract(F))
198
199 def test_descriptors_with_abstractmethod(self):
200 class C(metaclass=abc_ABCMeta):
201 @property
202 @abc.abstractmethod
203 def foo(self): return 3
204 @foo.setter
205 @abc.abstractmethod
206 def foo(self, val): pass
207 self.assertRaises(TypeError, C)
208 class D(C):
209 @C.foo.getter
210 def foo(self): return super().foo
211 self.assertRaises(TypeError, D)
212 class E(D):
213 @D.foo.setter
214 def foo(self, val): pass
215 self.assertEqual(E().foo, 3)
216 # check that the property's __isabstractmethod__ descriptor does the
217 # right thing when presented with a value that fails truth testing:
218 class NotBool(object):
219 def __bool__(self):
220 raise ValueError()
221 __len__ = __bool__
222 with self.assertRaises(ValueError):
223 class F(C):
224 def bar(self):
225 pass
226 bar.__isabstractmethod__ = NotBool()
227 foo = property(bar)
228
229
230 def test_customdescriptors_with_abstractmethod(self):

Callers

nothing calls this directly

Calls 3

EClass · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected