本文整理汇总了Python中py._code.code.FormattedExcinfo.get_source方法的典型用法代码示例。如果您正苦于以下问题:Python FormattedExcinfo.get_source方法的具体用法?Python FormattedExcinfo.get_source怎么用?Python FormattedExcinfo.get_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py._code.code.FormattedExcinfo
的用法示例。
在下文中一共展示了FormattedExcinfo.get_source方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_repr_source
# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import get_source [as 别名]
def test_repr_source(self):
pr = FormattedExcinfo()
source = py.code.Source("""
def f(x):
pass
""").strip()
pr.flow_marker = "|"
lines = pr.get_source(source, 0)
assert len(lines) == 2
assert lines[0] == "| def f(x):"
assert lines[1] == " pass"
示例2: test_repr_source_excinfo
# 需要导入模块: from py._code.code import FormattedExcinfo [as 别名]
# 或者: from py._code.code.FormattedExcinfo import get_source [as 别名]
def test_repr_source_excinfo(self):
""" check if indentation is right """
pr = FormattedExcinfo()
excinfo = self.excinfo_from_exec("""
def f():
assert 0
f()
""")
pr = FormattedExcinfo()
source = pr._getentrysource(excinfo.traceback[-1])
lines = pr.get_source(source, 1, excinfo)
assert lines == [
' def f():',
'> assert 0',
'E assert 0'
]