test_builtins.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:packaging 作者: blockstack 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号