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


Python support.forget函数代码示例

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


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

示例1: test_badimport

    def test_badimport(self):
        # This tests the fix for issue 5230, where if pydoc found the module
        # but the module had an internal import error pydoc would report no doc
        # found.
        modname = 'testmod_xyzzy'
        testpairs = (
            ('i_am_not_here', 'i_am_not_here'),
            ('test.i_am_not_here_either', 'i_am_not_here_either'),
            ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
            ('i_am_not_here.{}'.format(modname), 'i_am_not_here.{}'.format(modname)),
            ('test.{}'.format(modname), modname),
            )

        @contextmanager
        def newdirinpath(dir):
            os.mkdir(dir)
            sys.path.insert(0, dir)
            yield
            sys.path.pop(0)
            rmtree(dir)

        with newdirinpath(TESTFN), EnvironmentVarGuard() as env:
            env['PYTHONPATH'] = TESTFN
            fullmodname = os.path.join(TESTFN, modname)
            sourcefn = fullmodname + os.extsep + "py"
            for importstring, expectedinmsg in testpairs:
                f = open(sourcefn, 'w')
                f.write("import {}\n".format(importstring))
                f.close()
                try:
                    result = run_pydoc(modname).decode("ascii")
                finally:
                    forget(modname)
                expected = badimport_pattern % (modname, expectedinmsg)
                self.assertEqual(expected, result)
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:35,代码来源:test_pydoc.py

示例2: test_with_extension

        def test_with_extension(ext):
            # The extension is normally ".py", perhaps ".pyw".
            source = TESTFN + ext
            if is_jython:
                pyc = TESTFN + "$py.class"
            else:
                pyc = TESTFN + ".pyc"

            with open(source, "w") as f:
                print("# This tests Python's ability to import a",
                      ext, "file.", file=f)
                a = random.randrange(1000)
                b = random.randrange(1000)
                print("a =", a, file=f)
                print("b =", b, file=f)

            if TESTFN in sys.modules:
                del sys.modules[TESTFN]
            importlib.invalidate_caches()
            try:
                try:
                    mod = __import__(TESTFN)
                except ImportError as err:
                    self.fail("import from %s failed: %s" % (ext, err))

                self.assertEqual(mod.a, a,
                    "module loaded (%s) but contents invalid" % mod)
                self.assertEqual(mod.b, b,
                    "module loaded (%s) but contents invalid" % mod)
            finally:
                forget(TESTFN)
                unlink(source)
                unlink(pyc)
开发者ID:Stewori,项目名称:JyNIgate,代码行数:33,代码来源:__init__.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: test_missing_source

 def test_missing_source(self):
     # With PEP 3147 cache layout, removing the source but leaving the pyc
     # file does not satisfy the import.
     __import__(TESTFN)
     pyc_file = imp.cache_from_source(self.source)
     self.assertTrue(os.path.exists(pyc_file))
     os.remove(self.source)
     forget(TESTFN)
     self.assertRaises(ImportError, __import__, TESTFN)
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:9,代码来源:test_import.py

示例6: test_forget

    def test_forget(self):
        mod_filename = TESTFN + '.py'
        with open(mod_filename, 'w') as f:
            print('foo = 1', file=f)
        sys.path.insert(0, os.curdir)
        importlib.invalidate_caches()
        try:
            mod = __import__(TESTFN)
            self.assertIn(TESTFN, sys.modules)

            support.forget(TESTFN)
            self.assertNotIn(TESTFN, sys.modules)
        finally:
            del sys.path[0]
            support.unlink(mod_filename)
开发者ID:MYSHLIFE,项目名称:cpython-1,代码行数:15,代码来源:test_support.py

示例7: test_forget

    def test_forget(self):
        mod_filename = TESTFN + '.py'
        with open(mod_filename, 'wt') as f:
            f.write('foo = 1\n')
        sys.path.insert(0, os.curdir)
        try:
            mod = __import__(TESTFN)
            self.assertIn(TESTFN, sys.modules)

            support.forget(TESTFN)
            self.assertNotIn(TESTFN, sys.modules)
        finally:
            del sys.path[0]
            support.unlink(mod_filename)
            support.rmtree('__pycache__')
开发者ID:RDWang,项目名称:python,代码行数:15,代码来源:test_test_support.py

示例8: test_forget

    def test_forget(self):
        mod_filename = TESTFN + ".py"
        with open(mod_filename, "w") as f:
            print("foo = 1", file=f)
        sys.path.insert(0, os.curdir)
        importlib.invalidate_caches()
        try:
            mod = __import__(TESTFN)
            self.assertIn(TESTFN, sys.modules)

            support.forget(TESTFN)
            self.assertNotIn(TESTFN, sys.modules)
        finally:
            del sys.path[0]
            support.unlink(mod_filename)
            support.rmtree("__pycache__")
开发者ID:rahulnij,项目名称:practice-python,代码行数:16,代码来源:test_support.py

示例9: test_run_name

 def test_run_name(self):
     depth = 1
     run_name = "And now for something completely different"
     pkg_dir, mod_fname, mod_name = (
            self._make_pkg(example_source, depth))
     forget(mod_name)
     expected_ns = example_namespace.copy()
     expected_ns.update({
         "__name__": run_name,
         "__file__": mod_fname,
         "__package__": mod_name.rpartition(".")[0],
     })
     def create_ns(init_globals):
         return run_module(mod_name, init_globals, run_name)
     try:
         self.check_code_execution(create_ns, expected_ns)
     finally:
         self._del_pkg(pkg_dir, depth, mod_name)
开发者ID:BeboPremo,项目名称:cpython,代码行数:18,代码来源:test_runpy.py

示例10: _check_module

 def _check_module(self, depth):
     pkg_dir, mod_fname, mod_name = (
            self._make_pkg("x=1\n", depth))
     forget(mod_name)
     try:
         if verbose: print("Running from source:", mod_name)
         d1 = run_module(mod_name) # Read from source
         self.assertTrue("x" in d1)
         self.assertEqual(d1["x"], 1)
         del d1 # Ensure __loader__ entry doesn't keep file open
         __import__(mod_name)
         os.remove(mod_fname)
         if verbose: print("Running from compiled:", mod_name)
         d2 = run_module(mod_name) # Read from bytecode
         self.assertTrue("x" in d2)
         self.assertEqual(d2["x"], 1)
         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:Kanma,项目名称:Athena-Dependencies-Python,代码行数:20,代码来源:test_runpy.py

示例11: _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

示例12: _check_module

 def _check_module(self, depth):
     pkg_dir, mod_fname, mod_name = (
            self._make_pkg("x=1\n", depth))
     forget(mod_name)
     try:
         if verbose: print("Running from source:", mod_name)
         d1 = run_module(mod_name) # Read from source
         self.assertIn("x", d1)
         self.assertEqual(d1["x"], 1)
         del d1 # Ensure __loader__ entry doesn't keep file open
         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: print("Running from compiled:", mod_name)
         importlib.invalidate_caches()
         d2 = run_module(mod_name) # Read from bytecode
         self.assertIn("x", d2)
         self.assertEqual(d2["x"], 1)
         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:Naddiseo,项目名称:cpython,代码行数:24,代码来源:test_runpy.py

示例13: _clean

 def _clean(self):
     forget(TESTFN)
     rmtree('__pycache__')
     unlink(self.source)
开发者ID:Stewori,项目名称:JyNIgate,代码行数:4,代码来源:__init__.py


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