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


Python trace.__file__方法代码示例

本文整理汇总了Python中trace.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python trace.__file__方法的具体用法?Python trace.__file__怎么用?Python trace.__file__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trace的用法示例。


在下文中一共展示了trace.__file__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_exec_counts

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [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_loop_caller_importing

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [as 别名]
def test_loop_caller_importing(self):
        self.tracer.runfunc(traced_func_importing_caller, 1)

        expected = {
            ((os.path.splitext(trace.__file__)[0] + '.py', 'trace', 'Trace.runfunc'),
                (self.filemod + ('traced_func_importing_caller',))): 1,
            ((self.filemod + ('traced_func_simple_caller',)),
                (self.filemod + ('traced_func_linear',))): 1,
            ((self.filemod + ('traced_func_importing_caller',)),
                (self.filemod + ('traced_func_simple_caller',))): 1,
            ((self.filemod + ('traced_func_importing_caller',)),
                (self.filemod + ('traced_func_importing',))): 1,
            ((self.filemod + ('traced_func_importing',)),
                (fix_ext_py(testmod.__file__), 'testmod', 'func')): 1,
        }
        self.assertEqual(self.tracer.results().callers, expected)


# Created separately for issue #3821 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_trace.py

示例3: test_issue9936

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [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

示例4: test_issue9936

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [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

示例5: test_cover_files_written_no_highlight

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [as 别名]
def test_cover_files_written_no_highlight(self):
        # Test also that the cover file for the trace module is not created
        # (issue #34171).
        tracedir = os.path.dirname(os.path.abspath(trace.__file__))
        tracecoverpath = os.path.join(tracedir, 'trace.cover')
        unlink(tracecoverpath)

        argv = '-m trace --count'.split() + [self.codefile]
        status, stdout, stderr = assert_python_ok(*argv)
        self.assertEqual(stderr, b'')
        self.assertFalse(os.path.exists(tracecoverpath))
        self.assertTrue(os.path.exists(self.coverfile))
        with open(self.coverfile) as f:
            self.assertEqual(f.read(),
                "    1: x = 42\n"
                "    1: if []:\n"
                "           print('unreachable')\n"
            ) 
开发者ID:bkerler,项目名称:android_universal,代码行数:20,代码来源:test_trace.py

示例6: my_file_and_modname

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [as 别名]
def my_file_and_modname():
    """The .py file and module name of this file (__file__)"""
    modname = os.path.splitext(os.path.basename(__file__))[0]
    return fix_ext_py(__file__), modname 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_trace.py

示例7: setUp

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [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_traced_func_importing

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [as 别名]
def test_traced_func_importing(self):
        self.tracer.runfunc(traced_func_importing, 2, 5)

        firstlineno = get_firstlineno(traced_func_importing)
        expected = {
            (self.my_py_filename, firstlineno + 1): 1,
            (fix_ext_py(testmod.__file__), 2): 1,
            (fix_ext_py(testmod.__file__), 3): 1,
        }

        self.assertEqual(self.tracer.results().counts, expected) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_trace.py

示例9: test_coverage_ignore

# 需要导入模块: import trace [as 别名]
# 或者: from trace import __file__ [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


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