本文整理汇总了Python中trace.find_strings方法的典型用法代码示例。如果您正苦于以下问题:Python trace.find_strings方法的具体用法?Python trace.find_strings怎么用?Python trace.find_strings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trace
的用法示例。
在下文中一共展示了trace.find_strings方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _find_docstrings
# 需要导入模块: import trace [as 别名]
# 或者: from trace import find_strings [as 别名]
def _find_docstrings(self, filename):
# A replacement for trace.find_strings() which was deprecated in
# Python 3.2 and removed in 3.6.
strs = set()
prev = token.INDENT # so module docstring is detected as docstring
with open(filename) as f:
tokens = tokenize.generate_tokens(f.readline)
for ttype, tstr, start, end, line in tokens:
if ttype == token.STRING and prev == token.INDENT:
strs.update(range(start[0], end[0] + 1))
prev = ttype
return strs
示例2: test_deprecated_find_strings
# 需要导入模块: import trace [as 别名]
# 或者: from trace import find_strings [as 别名]
def test_deprecated_find_strings(self):
with open(TESTFN, 'w') as fd:
self.addCleanup(unlink, TESTFN)
with self.assertWarns(DeprecationWarning):
trace.find_strings(fd.name)
示例3: find_source_lines
# 需要导入模块: import trace [as 别名]
# 或者: from trace import find_strings [as 别名]
def find_source_lines(self):
"""Mark all executable source lines in fn as executed 0 times."""
strs = trace.find_strings(self.filename)
lines = trace.find_lines_from_code(self.fn.__code__, strs)
self.firstcodelineno = sys.maxint
for lineno in lines:
self.firstcodelineno = min(self.firstcodelineno, lineno)
self.sourcelines.setdefault(lineno, 0)
if self.firstcodelineno == sys.maxint:
self.firstcodelineno = self.firstlineno
示例4: opt_coverage
# 需要导入模块: import trace [as 别名]
# 或者: from trace import find_strings [as 别名]
def opt_coverage(self):
"""
Generate coverage information in the given directory (relative to
trial temporary working directory). Requires Python 2.3.3.
"""
coverdir = 'coverage'
print "Setting coverage directory to %s." % (coverdir,)
import trace
# begin monkey patch ---------------------------
# Before Python 2.4, this function asserted that 'filename' had
# to end with '.py' This is wrong for at least two reasons:
# 1. We might be wanting to find executable line nos in a script
# 2. The implementation should use os.splitext
# This monkey patch is the same function as in the stdlib (v2.3)
# but with the assertion removed.
def find_executable_linenos(filename):
"""Return dict where keys are line numbers in the line number
table.
"""
#assert filename.endswith('.py') # YOU BASTARDS
try:
prog = open(filename).read()
prog = '\n'.join(prog.splitlines()) + '\n'
except IOError, err:
sys.stderr.write("Not printing coverage data for %r: %s\n"
% (filename, err))
sys.stderr.flush()
return {}
code = compile(prog, filename, "exec")
strs = trace.find_strings(filename)
return trace.find_lines(code, strs)
示例5: find_source_lines
# 需要导入模块: import trace [as 别名]
# 或者: from trace import find_strings [as 别名]
def find_source_lines(self):
"""Mark all executable source lines in fn as executed 0 times."""
strs = trace.find_strings(self.filename)
lines = trace.find_lines_from_code(self.fn.func_code, strs)
self.firstcodelineno = sys.maxint
for lineno in lines:
self.firstcodelineno = min(self.firstcodelineno, lineno)
self.sourcelines.setdefault(lineno, 0)
if self.firstcodelineno == sys.maxint:
self.firstcodelineno = self.firstlineno