def test_hasattr(self):
self.assertTrue(hasattr(sys, 'stdout'))
self.assertRaises(TypeError, hasattr, sys, 1)
self.assertRaises(TypeError, hasattr)
# Fails on Py2:
# self.assertEqual(False, hasattr(sys, chr(sys.maxunicode)))
# Check that hasattr propagates all exceptions outside of
# AttributeError.
class A(object):
def __getattr__(self, what):
raise SystemExit
self.assertRaises(SystemExit, hasattr, A(), "b")
class B(object):
def __getattr__(self, what):
raise ValueError
# Was: self.assertRaises(ValueError, hasattr, B(), "b")
# Fails on Py2
评论列表
文章目录