當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。