本文整理汇总了Python中py.code.Source.getstatementrange方法的典型用法代码示例。如果您正苦于以下问题:Python Source.getstatementrange方法的具体用法?Python Source.getstatementrange怎么用?Python Source.getstatementrange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py.code.Source
的用法示例。
在下文中一共展示了Source.getstatementrange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getstatementrange_within_constructs
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_within_constructs(self):
source = Source("""\
try:
try:
raise ValueError
except SomeThing:
pass
finally:
42
""")
assert len(source) == 7
assert source.getstatementrange(0) == (0, 7)
assert source.getstatementrange(1) == (1, 5)
assert source.getstatementrange(2) == (2, 3)
assert source.getstatementrange(3) == (1, 5)
assert source.getstatementrange(4) == (4, 5)
assert source.getstatementrange(5) == (0, 7)
assert source.getstatementrange(6) == (6, 7)
示例2: test_getstatementrange_within_constructs
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_within_constructs(self):
source = Source("""\
try:
try:
raise ValueError
except SomeThing:
pass
finally:
42
""")
assert len(source) == 7
# check all lineno's that could occur in a traceback
#assert source.getstatementrange(0) == (0, 7)
#assert source.getstatementrange(1) == (1, 5)
assert source.getstatementrange(2) == (2, 3)
assert source.getstatementrange(3) == (3, 4)
assert source.getstatementrange(4) == (4, 5)
#assert source.getstatementrange(5) == (0, 7)
assert source.getstatementrange(6) == (6, 7)
示例3: test_getstatementrange_bug
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_bug(self):
source = Source("""\
try:
x = (
y +
z)
except:
pass
""")
assert len(source) == 6
assert source.getstatementrange(2) == (1, 4)
示例4: test_getstatementrange_bug2
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_bug2(self):
source = Source("""\
assert (
33
==
[
X(3,
b=1, c=2
),
]
)
""")
assert len(source) == 9
assert source.getstatementrange(5) == (0, 9)
示例5: test_getstatementrange_bug2
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_bug2(self):
py.test.skip("fix me (issue19)")
source = Source("""\
assert (
33
==
[
X(3,
b=1, c=2
),
]
)
""")
assert len(source) == 9
assert source.getstatementrange(5) == (0, 9)
示例6: test_getstatementrange_with_syntaxerror_issue7
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_with_syntaxerror_issue7(self):
source = Source(":")
py.test.raises(SyntaxError, lambda: source.getstatementrange(0))
示例7: test_getstatementrange_out_of_bounds_py3
# 需要导入模块: from py.code import Source [as 别名]
# 或者: from py.code.Source import getstatementrange [as 别名]
def test_getstatementrange_out_of_bounds_py3(self):
source = Source("if xxx:\n from .collections import something")
r = source.getstatementrange(1)
assert r == (1,2)