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


Python support.make_legacy_pyc函数代码示例

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


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


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