本文整理汇总了Python中py.code.Source类的典型用法代码示例。如果您正苦于以下问题:Python Source类的具体用法?Python Source怎么用?Python Source使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Source类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_source_putaround
def test_source_putaround():
source = Source()
source = source.putaround("""
if 1:
x=1
""")
assert str(source).strip() == "if 1:\n x=1"
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:7,代码来源:test_source.py
示例2: test_getstatementrange_triple_quoted
def test_getstatementrange_triple_quoted(self):
#print str(self.source)
source = Source("""hello('''
''')""")
s = source.getstatement(0)
assert s == str(source)
s = source.getstatement(1)
assert s == str(source)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:8,代码来源:test_source.py
示例3: test_source_putaround_simple
def test_source_putaround_simple():
source = Source("raise ValueError")
source = source.putaround(
"try:", """\
except ValueError:
x = 42
else:
x = 23""")
assert str(source)=="""\
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:9,代码来源:test_source.py
示例4: test_getstatementrange_bug
def test_getstatementrange_bug(self):
source = Source("""\
try:
x = (
y +
z)
except:
pass
""")
assert len(source) == 6
assert source.getstatementrange(2) == (1, 4)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:11,代码来源:test_source.py
示例5: test_getstatementrange_bug2
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)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:14,代码来源:test_source.py
示例6: test_getstatementrange_bug2
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)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:15,代码来源:test_source.py
示例7: test_getstatementrange_within_constructs
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)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:18,代码来源:test_source.py
示例8: test_getstatementrange_within_constructs
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)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:19,代码来源:test_source.py
示例9: test_source_strip_multiline
def test_source_strip_multiline():
source = Source()
source.lines = ["", " hello", " "]
source2 = source.strip()
assert source2.lines == [" hello"]
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:5,代码来源:test_source.py
示例10: test_source_strips
def test_source_strips():
source = Source("")
assert source == Source()
assert str(source) == ''
assert source.strip() == source
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:5,代码来源:test_source.py
示例11: test_compile_to_ast
def test_compile_to_ast(self):
import ast
source = Source("x = 4")
mod = source.compile(flag=ast.PyCF_ONLY_AST)
assert isinstance(mod, ast.Module)
compile(mod, "<filename>", "exec")
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:6,代码来源:test_source.py
示例12: test_getstatementrange_with_syntaxerror_issue7
def test_getstatementrange_with_syntaxerror_issue7(self):
source = Source(":")
py.test.raises(SyntaxError, lambda: source.getstatementrange(0))
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:3,代码来源:test_source.py
示例13: test_getstatementrange_out_of_bounds_py3
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)
开发者ID:Eleanor66613,项目名称:CS249-midterm,代码行数:4,代码来源:test_source.py
注:本文中的py.code.Source类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论