本文整理汇总了Python中coverage.parser.PythonParser.arcs方法的典型用法代码示例。如果您正苦于以下问题:Python PythonParser.arcs方法的具体用法?Python PythonParser.arcs怎么用?Python PythonParser.arcs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.parser.PythonParser
的用法示例。
在下文中一共展示了PythonParser.arcs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare_alternatives
# 需要导入模块: from coverage.parser import PythonParser [as 别名]
# 或者: from coverage.parser.PythonParser import arcs [as 别名]
def compare_alternatives(source):
all_all_arcs = collections.defaultdict(list)
for i, alternate_source in enumerate(async_alternatives(source)):
parser = PythonParser(alternate_source)
arcs = parser.arcs()
all_all_arcs[tuple(arcs)].append((i, alternate_source))
return len(all_all_arcs)
示例2: print
# 需要导入模块: from coverage.parser import PythonParser [as 别名]
# 或者: from coverage.parser.PythonParser import arcs [as 别名]
"""Parse every Python file in a tree."""
import os
import sys
from coverage.misc import CoverageException
from coverage.parser import PythonParser
for root, dirnames, filenames in os.walk(sys.argv[1]):
for filename in filenames:
if filename.endswith(".py"):
filename = os.path.join(root, filename)
print(":: {}".format(filename))
try:
par = PythonParser(filename=filename)
par.parse_source()
par.arcs()
except Exception as exc:
print(" ** {}".format(exc))
示例3: one_file
# 需要导入模块: from coverage.parser import PythonParser [as 别名]
# 或者: from coverage.parser.PythonParser import arcs [as 别名]
def one_file(self, options, filename):
"""Process just one file."""
# `filename` can have a line number suffix. In that case, extract those
# lines, dedent them, and use that. This is for trying test cases
# embedded in the test files.
match = re.search(r"^(.*):(\d+)-(\d+)$", filename)
if match:
filename, start, end = match.groups()
start, end = int(start), int(end)
else:
start = end = None
try:
text = get_python_source(filename)
if start is not None:
lines = text.splitlines(True)
text = textwrap.dedent("".join(lines[start-1:end]).replace("\\\\", "\\"))
pyparser = PythonParser(text, filename=filename, exclude=r"no\s*cover")
pyparser.parse_source()
except Exception as err:
print("%s" % (err,))
return
if options.dis:
print("Main code:")
self.disassemble(pyparser.byte_parser, histogram=options.histogram)
arcs = pyparser.arcs()
if options.source or options.tokens:
pyparser.show_tokens = options.tokens
pyparser.parse_source()
if options.source:
arc_chars = self.arc_ascii_art(arcs)
if arc_chars:
arc_width = max(len(a) for a in arc_chars.values())
exit_counts = pyparser.exit_counts()
for lineno, ltext in enumerate(pyparser.lines, start=1):
marks = [' ', ' ', ' ', ' ', ' ']
a = ' '
if lineno in pyparser.raw_statements:
marks[0] = '-'
if lineno in pyparser.statements:
marks[1] = '='
exits = exit_counts.get(lineno, 0)
if exits > 1:
marks[2] = str(exits)
if lineno in pyparser.raw_docstrings:
marks[3] = '"'
if lineno in pyparser.raw_classdefs:
marks[3] = 'C'
if lineno in pyparser.raw_excluded:
marks[4] = 'x'
if arc_chars:
a = arc_chars[lineno].ljust(arc_width)
else:
a = ""
print("%4d %s%s %s" % (lineno, "".join(marks), a, ltext))