本文整理汇总了Python中trace.Trace方法的典型用法代码示例。如果您正苦于以下问题:Python trace.Trace方法的具体用法?Python trace.Trace怎么用?Python trace.Trace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trace
的用法示例。
在下文中一共展示了trace.Trace方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exec_counts
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_exec_counts(self):
self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
code = r'''traced_func_loop(2, 5)'''
code = compile(code, __file__, 'exec')
self.tracer.runctx(code, globals(), vars())
firstlineno = get_firstlineno(traced_func_loop)
expected = {
(self.my_py_filename, firstlineno + 1): 1,
(self.my_py_filename, firstlineno + 2): 6,
(self.my_py_filename, firstlineno + 3): 5,
(self.my_py_filename, firstlineno + 4): 1,
}
# When used through 'run', some other spurious counts are produced, like
# the settrace of threading, which we ignore, just making sure that the
# counts fo traced_func_loop were right.
#
for k in expected.keys():
self.assertEqual(self.tracer.results().counts[k], expected[k])
示例2: test_issue9936
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_issue9936(self):
tracer = trace.Trace(trace=0, count=1)
modname = 'test.tracedmodules.testmod'
# Ensure that the module is executed in import
if modname in sys.modules:
del sys.modules[modname]
cmd = ("import test.tracedmodules.testmod as t;"
"t.func(0); t.func2();")
with captured_stdout() as stdout:
self._coverage(tracer, cmd)
stdout.seek(0)
stdout.readline()
coverage = {}
for line in stdout:
lines, cov, module = line.split()[:3]
coverage[module] = (int(lines), int(cov[:-1]))
# XXX This is needed to run regrtest.py as a script
modname = trace.fullmodname(sys.modules[modname].__file__)
self.assertIn(modname, coverage)
self.assertEqual(coverage[modname], (5, 100))
示例3: test_issue9936
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_issue9936(self):
tracer = trace.Trace(trace=0, count=1)
modname = 'test.tracedmodules.testmod'
# Ensure that the module is executed in import
if modname in sys.modules:
del sys.modules[modname]
cmd = ("import test.tracedmodules.testmod as t;"
"t.func(0); t.func2();")
with captured_stdout() as stdout:
self._coverage(tracer, cmd)
stdout.seek(0)
stdout.readline()
coverage = {}
for line in stdout:
lines, cov, module = line.split()[:3]
coverage[module] = (int(lines), int(cov[:-1]))
# XXX This is needed to run regrtest.py as a script
modname = trace._fullmodname(sys.modules[modname].__file__)
self.assertIn(modname, coverage)
self.assertEqual(coverage[modname], (5, 100))
### Tests that don't mess with sys.settrace and can be traced
### themselves TODO: Skip tests that do mess with sys.settrace when
### regrtest is invoked with -T option.
示例4: trace1
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def trace1(func, *args, **kwargs):
# use built-in trace module to write an execution trace to stdout
# e.g. utilities.trace1(clipboard.paste, focused_widget)
import sys, trace
tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
ignoremods=["gui_mixins", "new_properties", "decorators", "__init__", "clipboard"],
trace=1, count=0)
editor = common.root.children[-1]
tracer.runfunc(editor.create_widgets)
# make a report, placing output in the current directory
r = tracer.results()
if filename:
r.write_results_file(path, lines, lnotab, lines_hit, encoding=None)
else:
r.write_results(show_missing=True, coverdir=".")
# own implementation for wxGlade
示例5: create_tracing_node
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def create_tracing_node(uri, control_uri, attributes=None):
"""
Same as create_node, but will trace every line of execution.
Creates trace dump in output file '<host>_<port>.trace'
"""
n = StorageNode(control_uri)
_, host = uri.split('://')
with open("%s.trace" % (host, ), "w") as f:
tmp = sys.stdout
# Modules to ignore
ignore = [
'queue', 'calvin', 'actor', 'pickle', 'socket',
'uuid', 'codecs', 'copy_reg', 'string_escape', '__init__',
'colorlog', 'posixpath', 'glob', 'genericpath', 'base',
'sre_parse', 'sre_compile', 'fdesc', 'posixbase', 'escape_codes',
'fnmatch', 'urlparse', 're', 'stat', 'six'
]
with f as sys.stdout:
tracer = trace.Trace(trace=1, count=0, ignoremods=ignore)
tracer.runfunc(n.run)
sys.stdout = tmp
_log.info('Quitting node "%s"' % n.control_uri)
示例6: report_tracing
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def report_tracing(func, *args, **kwargs):
outputs = collections.defaultdict(list)
tracing = trace.Trace(trace=False)
tracing.runfunc(func, *args, **kwargs)
traced = collections.defaultdict(set)
for filename, line in tracing.results().counts:
traced[filename].add(line)
for filename, tracedlines in traced.items():
with open(filename) as f:
for idx, fileline in enumerate(f, start=1):
outputs[filename].append((idx, idx in tracedlines, fileline))
return outputs
示例7: setUp
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def setUp(self):
self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
self.my_py_filename = fix_ext_py(__file__)
示例8: test_linear_methods
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_linear_methods(self):
# XXX todo: later add 'static_method_linear' and 'class_method_linear'
# here, once issue1764286 is resolved
#
for methname in ['inst_method_linear',]:
tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
traced_obj = TracedClass(25)
method = getattr(traced_obj, methname)
tracer.runfunc(method, 20)
firstlineno = get_firstlineno(method)
expected = {
(self.my_py_filename, firstlineno + 1): 1,
}
self.assertEqual(tracer.results().counts, expected)
示例9: test_coverage
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_coverage(self):
tracer = trace.Trace(trace=0, count=1)
with captured_stdout() as stdout:
self._coverage(tracer)
stdout = stdout.getvalue()
self.assertIn("pprint.py", stdout)
self.assertIn("case.py", stdout) # from unittest
files = os.listdir(TESTFN)
self.assertIn("pprint.cover", files)
self.assertIn("unittest.case.cover", files)
示例10: test_coverage_ignore
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_coverage_ignore(self):
# Ignore all files, nothing should be traced nor printed
libpath = os.path.normpath(os.path.dirname(os.__file__))
# sys.prefix does not work when running from a checkout
tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix, libpath],
trace=0, count=1)
with captured_stdout() as stdout:
self._coverage(tracer)
if os.path.exists(TESTFN):
files = os.listdir(TESTFN)
self.assertEqual(files, [])
示例11: test_coverage
# 需要导入模块: import trace [as 别名]
# 或者: from trace import Trace [as 别名]
def test_coverage(self):
tracer = trace.Trace(trace=0, count=1)
with captured_stdout() as stdout:
self._coverage(tracer)
stdout = stdout.getvalue()
self.assertTrue("pprint.py" in stdout)
self.assertTrue("case.py" in stdout) # from unittest
files = os.listdir(TESTFN)
self.assertTrue("pprint.cover" in files)
self.assertTrue("unittest.case.cover" in files)