test__declaration.py 文件源码

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

项目:guillotina 作者: plone 项目源码 文件源码
def test_called_twice_from_class(self):
        import warnings
        from guillotina.component._declaration import adapts
        from zope.interface import Interface
        from zope.interface._compat import PYTHON3
        class IFoo(Interface):
            pass
        class IBar(Interface):
            pass
        globs = {'adapts': adapts, 'IFoo': IFoo, 'IBar': IBar}
        locs = {}
        CODE = "\n".join([
            'class Foo(object):',
            '    adapts(IFoo)',
            '    adapts(IBar)',
            ])
        with warnings.catch_warnings(record=True) as log:
            warnings.resetwarnings()
            try:
                exec(CODE, globs, locs)
            except TypeError:
                if not PYTHON3:
                    self.assertEqual(len(log), 0) # no longer warn
            else:
                self.fail("Didn't raise TypeError")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号