test_pretty.py 文件源码

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

项目:leetcode 作者: thomasyimgit 项目源码 文件源码
def test_basic_class():
    def type_pprint_wrapper(obj, p, cycle):
        if obj is MyObj:
            type_pprint_wrapper.called = True
        return pretty._type_pprint(obj, p, cycle)
    type_pprint_wrapper.called = False

    stream = StringIO()
    printer = pretty.RepresentationPrinter(stream)
    printer.type_pprinters[type] = type_pprint_wrapper
    printer.pretty(MyObj)
    printer.flush()
    output = stream.getvalue()

    nt.assert_equal(output, '%s.MyObj' % __name__)
    nt.assert_true(type_pprint_wrapper.called)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号