• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python support.make_legacy_pyc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.support.make_legacy_pyc函数的典型用法代码示例。如果您正苦于以下问题:Python make_legacy_pyc函数的具体用法?Python make_legacy_pyc怎么用?Python make_legacy_pyc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_module_with_large_stack

    def test_module_with_large_stack(self, module="longlist"):
        # Regression test for http://bugs.python.org/issue561858.
        filename = module + ".py"

        # Create a file with a list of 65000 elements.
        with open(filename, "w") as f:
            f.write("d = [\n")
            for i in range(65000):
                f.write('"",\n')
            f.write("]")

        try:
            # Compile & remove .py file; we only need .pyc (or .pyo).
            # Bytecode must be relocated from the PEP 3147 bytecode-only location.
            py_compile.compile(filename)
        finally:
            unlink(filename)

        # Need to be able to load from current dir.
        sys.path.append("")
        importlib.invalidate_caches()

        try:
            make_legacy_pyc(filename)
            # This used to crash.
            exec("import " + module)
        finally:
            # Cleanup.
            del sys.path[-1]
            unlink(filename + "c")
            unlink(filename + "o")
开发者ID:certik,项目名称:python-3.3,代码行数:31,代码来源:test_import.py


示例2: run_test

    def run_test(self, test, create=None, *, compile_=None, unlink=None):
        """Test the finding of 'test' with the creation of modules listed in
        'create'.

        Any names listed in 'compile_' are byte-compiled. Modules
        listed in 'unlink' have their source files deleted.

        """
        if create is None:
            create = {test}
        with source_util.create_modules(*create) as mapping:
            if compile_:
                for name in compile_:
                    py_compile.compile(mapping[name])
            if unlink:
                for name in unlink:
                    os.unlink(mapping[name])
                    try:
                        make_legacy_pyc(mapping[name])
                    except OSError as error:
                        # Some tests do not set compile_=True so the source
                        # module will not get compiled and there will be no
                        # PEP 3147 pyc file to rename.
                        if error.errno != errno.ENOENT:
                            raise
            loader = self.import_(mapping['.root'], test)
            self.assertTrue(hasattr(loader, 'load_module'))
            return loader
开发者ID:Naddiseo,项目名称:cpython,代码行数:28,代码来源:test_finder.py


示例3: _check_package

 def _check_package(self, depth):
     pkg_dir, mod_fname, mod_name = self._make_pkg("x=1\n", depth, "__main__")
     pkg_name, _, _ = mod_name.rpartition(".")
     forget(mod_name)
     try:
         if verbose:
             print("Running from source:", pkg_name)
         d1 = run_module(pkg_name)  # Read from source
         self.assertIn("x", d1)
         self.assertTrue(d1["x"] == 1)
         del d1  # Ensure __loader__ entry doesn't keep file open
         __import__(mod_name)
         os.remove(mod_fname)
         make_legacy_pyc(mod_fname)
         unload(mod_name)  # In case loader caches paths
         if verbose:
             print("Running from compiled:", pkg_name)
         d2 = run_module(pkg_name)  # Read from bytecode
         self.assertIn("x", d2)
         self.assertTrue(d2["x"] == 1)
         del d2  # Ensure __loader__ entry doesn't keep file open
     finally:
         self._del_pkg(pkg_dir, depth, pkg_name)
     if verbose:
         print("Package executed successfully")
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:25,代码来源:test_runpy.py


示例4: _check_package

 def _check_package(self, depth, alter_sys=False):
     pkg_dir, mod_fname, mod_name = (
            self._make_pkg(example_source, depth, "__main__"))
     pkg_name = mod_name.rpartition(".")[0]
     forget(mod_name)
     expected_ns = example_namespace.copy()
     expected_ns.update({
         "__name__": mod_name,
         "__file__": mod_fname,
         "__package__": pkg_name,
     })
     if alter_sys:
         expected_ns.update({
             "run_argv0": mod_fname,
             "run_name_in_sys_modules": True,
             "module_in_sys_modules": True,
         })
     def create_ns(init_globals):
         return run_module(pkg_name, init_globals, alter_sys=alter_sys)
     try:
         if verbose > 1: print("Running from source:", pkg_name)
         self.check_code_execution(create_ns, expected_ns)
         importlib.invalidate_caches()
         __import__(mod_name)
         os.remove(mod_fname)
         make_legacy_pyc(mod_fname)
         unload(mod_name)  # In case loader caches paths
         if verbose > 1: print("Running from compiled:", pkg_name)
         importlib.invalidate_caches()
         self._fix_ns_for_legacy_pyc(expected_ns, alter_sys)
         self.check_code_execution(create_ns, expected_ns)
     finally:
         self._del_pkg(pkg_dir, depth, pkg_name)
     if verbose > 1: print("Package executed successfully")
开发者ID:BeboPremo,项目名称:cpython,代码行数:34,代码来源:test_runpy.py


示例5: _check_relative_imports

    def _check_relative_imports(self, depth, run_name=None):
        contents = r"""\
from __future__ import absolute_import
from . import sibling
from ..uncle.cousin import nephew
"""
        pkg_dir, mod_fname, mod_name = (
               self._make_pkg(contents, depth))
        try:
            self._add_relative_modules(pkg_dir, contents, depth)
            pkg_name = mod_name.rpartition('.')[0]
            if verbose: print("Running from source:", mod_name)
            d1 = run_module(mod_name, run_name=run_name) # Read from source
            self.assertIn("__package__", d1)
            self.assertTrue(d1["__package__"] == pkg_name)
            self.assertIn("sibling", d1)
            self.assertIn("nephew", d1)
            del d1 # Ensure __loader__ entry doesn't keep file open
            __import__(mod_name)
            os.remove(mod_fname)
            make_legacy_pyc(mod_fname)
            unload(mod_name)  # In case the loader caches paths
            if verbose: print("Running from compiled:", mod_name)
            d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
            self.assertIn("__package__", d2)
            self.assertTrue(d2["__package__"] == pkg_name)
            self.assertIn("sibling", d2)
            self.assertIn("nephew", d2)
            del d2 # Ensure __loader__ entry doesn't keep file open
        finally:
            self._del_pkg(pkg_dir, depth, mod_name)
        if verbose: print("Module executed successfully")
开发者ID:edmundgentle,项目名称:schoolscript,代码行数:32,代码来源:test_runpy.py


示例6: test_module_with_large_stack

    def test_module_with_large_stack(self, module='longlist'):
        # Regression test for http://bugs.python.org/issue561858.
        filename = module + '.py'

        # Create a file with a list of 65000 elements.
        with open(filename, 'w') as f:
            f.write('d = [\n')
            for i in range(65000):
                f.write('"",\n')
            f.write(']')

        try:
            # Compile & remove .py file; we only need .pyc (or .pyo).
            # Bytecode must be relocated from the PEP 3147 bytecode-only location.
            py_compile.compile(filename)
        finally:
            unlink(filename)

        # Need to be able to load from current dir.
        sys.path.append('')

        try:
            make_legacy_pyc(filename)
            # This used to crash.
            exec('import ' + module)
        finally:
            # Cleanup.
            del sys.path[-1]
            unlink(filename + 'c')
            unlink(filename + 'o')
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:30,代码来源:test_import.py


示例7: test_script_compiled

 def test_script_compiled(self):
     with temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, "script")
         py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         self._check_script(pyc_file, pyc_file, pyc_file, script_dir, None, importlib.machinery.SourcelessFileLoader)
开发者ID:GaloisInc,项目名称:echronos,代码行数:7,代码来源:test_cmd_line_script.py


示例8: test_script_compiled

 def test_script_compiled(self):
     with temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, 'script')
         py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         self._check_script(pyc_file)
开发者ID:alex,项目名称:cpython,代码行数:7,代码来源:test_multiprocessing_main_handling.py


示例9: test_directory_compiled

 def test_directory_compiled(self):
     with temp_dir() as script_dir:
         mod_name = "__main__"
         script_name = self._make_test_script(script_dir, mod_name)
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         legacy_pyc = make_legacy_pyc(script_name)
         self._check_script(script_dir, "<run_path>", legacy_pyc, script_dir, "")
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:8,代码来源:test_runpy.py


示例10: test_module_without_source

 def test_module_without_source(self):
     target = "another_module.py"
     py_compile.compile(self.file_name, dfile=target)
     os.remove(self.file_name)
     pyc_file = make_legacy_pyc(self.file_name)
     mod = self.import_module()
     self.assertEqual(mod.module_filename, pyc_file)
     self.assertEqual(mod.code_filename, target)
     self.assertEqual(mod.func_filename, target)
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:9,代码来源:test_import.py


示例11: test_directory_compiled

 def test_directory_compiled(self):
     source = self.main_in_children_source
     with temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, '__main__',
                                         source=source)
         py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         self._check_script(script_dir)
开发者ID:alex,项目名称:cpython,代码行数:9,代码来源:test_multiprocessing_main_handling.py


示例12: test_directory_compiled

 def test_directory_compiled(self):
     with support.temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, '__main__')
         py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         self._check_script(script_dir, pyc_file, script_dir,
                            script_dir, '',
                            importlib.machinery.SourcelessFileLoader)
开发者ID:CabbageHead-360,项目名称:cpython,代码行数:9,代码来源:test_cmd_line_script.py


示例13: test_script_compiled

 def test_script_compiled(self):
     with temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, 'script')
         py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         package = '' if support.check_impl_detail(pypy=True) else None
         self._check_script(pyc_file, pyc_file,
                            pyc_file, script_dir, package,
                            importlib.machinery.SourcelessFileLoader)
开发者ID:timm,项目名称:timmnix,代码行数:10,代码来源:test_cmd_line_script.py


示例14: test_directory_compiled

 def test_directory_compiled(self):
     with temp_dir() as script_dir:
         mod_name = '__main__'
         script_name = self._make_test_script(script_dir, mod_name)
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         if not sys.dont_write_bytecode:
             legacy_pyc = make_legacy_pyc(script_name)
             self._check_script(script_dir, "<run_path>", legacy_pyc,
                                script_dir, mod_name=mod_name)
开发者ID:DAWZayas-Projects,项目名称:TEJEDOR-RETUERTO-ALEJANDRO,代码行数:10,代码来源:test_runpy.py


示例15: test_package_compiled

 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, pyc_file,
                            pyc_file, script_dir, 'test_pkg')
开发者ID:7modelsan,项目名称:kbengine,代码行数:11,代码来源:test_cmd_line_script.py


示例16: _check_relative_imports

    def _check_relative_imports(self, depth, run_name=None):
        contents = r"""\
from __future__ import absolute_import
from . import sibling
from ..uncle.cousin import nephew
"""
        pkg_dir, mod_fname, mod_name, mod_spec = self._make_pkg(contents, depth)
        if run_name is None:
            expected_name = mod_name
        else:
            expected_name = run_name
        try:
            self._add_relative_modules(pkg_dir, contents, depth)
            pkg_name = mod_name.rpartition(".")[0]
            if verbose > 1:
                print("Running from source:", mod_name)
            d1 = run_module(mod_name, run_name=run_name)  # Read from source
            self.assertEqual(d1["__name__"], expected_name)
            self.assertEqual(d1["__package__"], pkg_name)
            self.assertIn("sibling", d1)
            self.assertIn("nephew", d1)
            del d1  # Ensure __loader__ entry doesn't keep file open
            importlib.invalidate_caches()
            __import__(mod_name)
            os.remove(mod_fname)
            if not sys.dont_write_bytecode:
                make_legacy_pyc(mod_fname)
                unload(mod_name)  # In case the loader caches paths
                if verbose > 1:
                    print("Running from compiled:", mod_name)
                importlib.invalidate_caches()
                d2 = run_module(mod_name, run_name=run_name)  # Read from bytecode
                self.assertEqual(d2["__name__"], expected_name)
                self.assertEqual(d2["__package__"], pkg_name)
                self.assertIn("sibling", d2)
                self.assertIn("nephew", d2)
                del d2  # Ensure __loader__ entry doesn't keep file open
        finally:
            self._del_pkg(pkg_dir)
        if verbose > 1:
            print("Module executed successfully")
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:41,代码来源:test_runpy.py


示例17: test_package_compiled

 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, "test_pkg")
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, "__main__")
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
         self._check_script(
             launch_name, pyc_file, pyc_file, script_dir, "test_pkg", importlib.machinery.SourcelessFileLoader
         )
开发者ID:GaloisInc,项目名称:echronos,代码行数:12,代码来源:test_cmd_line_script.py


示例18: test_package_compiled

 def test_package_compiled(self):
     with support.temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         self._check_script(["-m", "test_pkg"], pyc_file,
                            pyc_file, script_dir, 'test_pkg',
                            importlib.machinery.SourcelessFileLoader,
                            cwd=script_dir)
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:12,代码来源:test_cmd_line_script.py


示例19: test_file_to_source

    def test_file_to_source(self):
        # check if __file__ points to the source file where available
        source = TESTFN + ".py"
        with open(source, "w") as f:
            f.write("test = None\n")

        sys.path.insert(0, os.curdir)
        try:
            mod = __import__(TESTFN)
            self.assertTrue(mod.__file__.endswith('.py'))
            os.remove(source)
            del sys.modules[TESTFN]
            make_legacy_pyc(source)
            mod = __import__(TESTFN)
            base, ext = os.path.splitext(mod.__file__)
            self.assertIn(ext, ('.pyc', '.pyo'))
        finally:
            del sys.path[0]
            remove_files(TESTFN)
            if TESTFN in sys.modules:
                del sys.modules[TESTFN]
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:21,代码来源:test_import.py


示例20: _check_module

    def _check_module(self, depth, alter_sys=False, *, namespace=False, parent_namespaces=False):
        pkg_dir, mod_fname, mod_name, mod_spec = self._make_pkg(
            example_source, depth, namespace=namespace, parent_namespaces=parent_namespaces
        )
        forget(mod_name)
        expected_ns = example_namespace.copy()
        expected_ns.update(
            {
                "__name__": mod_name,
                "__file__": mod_fname,
                "__cached__": mod_spec.cached,
                "__package__": mod_name.rpartition(".")[0],
                "__spec__": mod_spec,
            }
        )
        if alter_sys:
            expected_ns.update({"run_argv0": mod_fname, "run_name_in_sys_modules": True, "module_in_sys_modules": True})

        def create_ns(init_globals):
            return run_module(mod_name, init_globals, alter_sys=alter_sys)

        try:
            if verbose > 1:
                print("Running from source:", mod_name)
            self.check_code_execution(create_ns, expected_ns)
            importlib.invalidate_caches()
            __import__(mod_name)
            os.remove(mod_fname)
            if not sys.dont_write_bytecode:
                make_legacy_pyc(mod_fname)
                unload(mod_name)  # In case loader caches paths
                importlib.invalidate_caches()
                if verbose > 1:
                    print("Running from compiled:", mod_name)
                self._fix_ns_for_legacy_pyc(expected_ns, alter_sys)
                self.check_code_execution(create_ns, expected_ns)
        finally:
            self._del_pkg(pkg_dir)
        if verbose > 1:
            print("Module executed successfully")
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:40,代码来源:test_runpy.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python support.python_is_optimized函数代码示例发布时间:2022-05-27
下一篇:
Python support.make_bad_fd函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap