def test_property___isabstractmethod__descriptor(self):
for val in (True, False, [], [1], '', '1'):
class C(object):
def foo(self):
pass
foo.__isabstractmethod__ = val
foo = DynamicClassAttribute(foo)
self.assertIs(C.__dict__['foo'].__isabstractmethod__, bool(val))
# check that the DynamicClassAttribute's __isabstractmethod__ descriptor does the
# right thing when presented with a value that fails truth testing:
class NotBool(object):
def __nonzero__(self):
raise ValueError()
__len__ = __nonzero__
with self.assertRaises(ValueError):
class C(object):
def foo(self):
pass
foo.__isabstractmethod__ = NotBool()
foo = DynamicClassAttribute(foo)
test_dynamicclassattribute.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录