当前位置: 首页>>代码示例>>Python>>正文


Python trace.Trace方法代码示例

本文整理汇总了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]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_trace.py

示例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)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_trace.py

示例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. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_trace.py

示例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 
开发者ID:wxGlade,项目名称:wxGlade,代码行数:23,代码来源:utilities.py

示例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) 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:24,代码来源:storage_node.py

示例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 
开发者ID:PacktPublishing,项目名称:Modern-Python-Standard-Library-Cookbook,代码行数:18,代码来源:devtools_08.py

示例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__) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_trace.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_trace.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_trace.py

示例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, []) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_trace.py

示例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) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:12,代码来源:test_trace.py


注:本文中的trace.Trace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。