test_descr.py 文件源码

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

项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码
def test_recursions_1(self):
        # Testing recursion checks ...
        class Letter(str):
            def __new__(cls, letter):
                if letter == 'EPS':
                    return str.__new__(cls)
                return str.__new__(cls, letter)
            def __str__(self):
                if not self:
                    return 'EPS'
                return self
        # sys.stdout needs to be the original to trigger the recursion bug
        test_stdout = sys.stdout
        sys.stdout = test_support.get_original_stdout()
        try:
            # nothing should actually be printed, this should raise an exception
            print Letter('w')
        except RuntimeError:
            pass
        else:
            self.fail("expected a RuntimeError for print recursion")
        finally:
            sys.stdout = test_stdout
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号