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

Python support.temp_cwd函数代码示例

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

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



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

示例1: test_issue_8766

    def test_issue_8766(self):
        # "import encodings" emits a warning whereas the warnings is not loaded
        # or not completely loaded (warnings imports indirectly encodings by
        # importing linecache) yet
        with support.temp_cwd() as cwd, support.temp_cwd('encodings'):
            # encodings loaded by initfsencoding()
            assert_python_ok('-c', 'pass', PYTHONPATH=cwd)

            # Use -W to load warnings module at startup
            assert_python_ok('-c', 'pass', '-W', 'always', PYTHONPATH=cwd)
开发者ID:ARK4579,项目名称:cpython,代码行数:10,代码来源:__init__.py


示例2: test_issue_8766

    def test_issue_8766(self):
        # "import encodings" emits a warning whereas the warnings is not loaded
        # or not completely loaded (warnings imports indirectly encodings by
        # importing linecache) yet
        with support.temp_cwd() as cwd, support.temp_cwd("encodings"):
            env = os.environ.copy()
            env["PYTHONPATH"] = cwd

            # encodings loaded by initfsencoding()
            retcode = subprocess.call([sys.executable, "-c", "pass"], env=env)
            self.assertEqual(retcode, 0)

            # Use -W to load warnings module at startup
            retcode = subprocess.call([sys.executable, "-c", "pass", "-W", "always"], env=env)
            self.assertEqual(retcode, 0)
开发者ID:pykomke,项目名称:Kurz_Python_KE,代码行数:15,代码来源:test_warnings.py


示例3: test_set_pycache_prefix

 def test_set_pycache_prefix(self):
     # sys.pycache_prefix can be set from either -X pycache_prefix or
     # PYTHONPYCACHEPREFIX env var, with the former taking precedence.
     NO_VALUE = object()  # `-X pycache_prefix` with no `=PATH`
     cases = [
         # (PYTHONPYCACHEPREFIX, -X pycache_prefix, sys.pycache_prefix)
         (None, None, None),
         ('foo', None, 'foo'),
         (None, 'bar', 'bar'),
         ('foo', 'bar', 'bar'),
         ('foo', '', None),
         ('foo', NO_VALUE, None),
     ]
     for envval, opt, expected in cases:
         exp_clause = "is None" if expected is None else f'== "{expected}"'
         code = f"import sys; sys.exit(not sys.pycache_prefix {exp_clause})"
         args = ['-c', code]
         env = {} if envval is None else {'PYTHONPYCACHEPREFIX': envval}
         if opt is NO_VALUE:
             args[:0] = ['-X', 'pycache_prefix']
         elif opt is not None:
             args[:0] = ['-X', f'pycache_prefix={opt}']
         with self.subTest(envval=envval, opt=opt):
             with support.temp_cwd():
                 assert_python_ok(*args, **env)
开发者ID:CCNITSilchar,项目名称:cpython,代码行数:25,代码来源:test_cmd_line.py


示例4: test_readrc_kwarg

    def test_readrc_kwarg(self):
        script = textwrap.dedent("""
            import pdb; pdb.Pdb(readrc=False).set_trace()

            print('hello')
        """)

        save_home = os.environ.pop('HOME', None)
        try:
            with support.temp_cwd():
                with open('.pdbrc', 'w') as f:
                    f.write("invalid\n")

                with open('main.py', 'w') as f:
                    f.write(script)

                cmd = [sys.executable, 'main.py']
                proc = subprocess.Popen(
                    cmd,
                    stdout=subprocess.PIPE,
                    stdin=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                )
                with proc:
                    stdout, stderr = proc.communicate(b'q\n')
                    self.assertNotIn("NameError: name 'invalid' is not defined",
                                  stdout.decode())

        finally:
            if save_home is not None:
                os.environ['HOME'] = save_home
开发者ID:Eyepea,项目名称:cpython,代码行数:31,代码来源:test_pdb.py


示例5: test_empty

 def test_empty(self):
     # Switch to an existing, but safe, working directory to let the
     # cleanup code do its thing without permission errors.
     with support.temp_cwd(path=path.dirname(sys.executable)):
         empty = path.join(path.dirname(__file__), "empty.vbs")
         startfile(empty)
         startfile(empty, "open")
开发者ID:524777134,项目名称:cpython,代码行数:7,代码来源:test_startfile.py


示例6: test_options_no_site_import

 def test_options_no_site_import(self):
     with support.temp_cwd() as temp_cwd:
         self.assertEqual(
             subprocess.check_output(
                 [sys.executable, "-S", "-c",
                  "import sys; print sorted(sys.modules.keys())"]).strip(),
             "['__builtin__', '__main__', 'exceptions', 'sys']")
开发者ID:isaiah,项目名称:jython3,代码行数:7,代码来源:test_site_jy.py


示例7: test_compileall

    def test_compileall(self):
        with temp_cwd():
            PACKAGE = os.path.realpath("./greetings")
            PYC_GREETER = os.path.join(PACKAGE, "greeter.pyc")
            PYCLASS_GREETER = os.path.join(PACKAGE, "greeter$py.class")
            PYCLASS_TEST = os.path.join(PACKAGE, "test$py.class")            

            os.mkdir(PACKAGE)
            self.write_code(
                PACKAGE, "greeter.py",
                """
                def greet():
                    print 'Hello world!'
                """)
            self.write_code(
                PACKAGE, "test.py",
                """
                from greeter import greet
                greet()
                """)

            # pretend we have a Python bytecode compiler by touching this file
            open(PYC_GREETER, "a").close()
            
            compileall.compile_dir(PACKAGE, quiet=True)
            self.assertTrue(os.path.exists(PYC_GREETER))     # still exists
            self.assertTrue(os.path.exists(PYCLASS_TEST))    # along with these new compiled files
            self.assertTrue(os.path.exists(PYCLASS_GREETER))

            # verify we can work with just compiled files
            os.unlink(os.path.join(PACKAGE, "greeter.py"))
            self.assertEqual(
                subprocess.check_output([sys.executable, os.path.join(PACKAGE, "test.py")]).rstrip(),
                "Hello world!")
开发者ID:isaiah,项目名称:jython3,代码行数:34,代码来源:test_compile_jy.py


示例8: test_temp_cwd__chdir_warning

 def test_temp_cwd__chdir_warning(self):
     """Check the warning message when os.chdir() fails."""
     path = TESTFN + '_does_not_exist'
     with support.check_warnings() as recorder:
         with support.temp_cwd(path=path, quiet=True):
             pass
         messages = [str(w.message) for w in recorder.warnings]
     self.assertEqual(messages, ['tests may fail, unable to change the CWD to ' + path])
开发者ID:524777134,项目名称:cpython,代码行数:8,代码来源:test_support.py


示例9: test_property_no_site_import

 def test_property_no_site_import(self):
     # only the minimal set of modules are imported
     with support.temp_cwd() as temp_cwd:
         self.assertEqual(
             subprocess.check_output(
                 [sys.executable, "-Dpython.import.site=false", "-c",
                  "import sys; print sorted(sys.modules.keys())"]).strip(),
             "['__builtin__', '__main__', 'exceptions', 'sys']")
开发者ID:isaiah,项目名称:jython3,代码行数:8,代码来源:test_site_jy.py


示例10: test_abspath

 def test_abspath(self):
     tester('ntpath.abspath("C:\\")', "C:\\")
     with support.temp_cwd(support.TESTFN) as cwd_dir: # bpo-31047
         tester('ntpath.abspath("")', cwd_dir)
         tester('ntpath.abspath(" ")', cwd_dir + "\\ ")
         tester('ntpath.abspath("?")', cwd_dir + "\\?")
         drive, _ = ntpath.splitdrive(cwd_dir)
         tester('ntpath.abspath("/abc/")', drive + "\\abc")
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:8,代码来源:test_ntpath.py


示例11: test_temp_cwd__name_none

 def test_temp_cwd__name_none(self):
     """Test passing None to temp_cwd()."""
     original_cwd = os.getcwd()
     with support.temp_cwd(name=None) as new_cwd:
         self.assertNotEqual(new_cwd, original_cwd)
         self.assertTrue(os.path.isdir(new_cwd))
         self.assertEqual(os.getcwd(), new_cwd)
     self.assertEqual(os.getcwd(), original_cwd)
开发者ID:MYSHLIFE,项目名称:cpython-1,代码行数:8,代码来源:test_support.py


示例12: test_directory

 def test_directory(self):
     dirname = os.path.join(support.TESTFN, 'Gr\xfc\xdf-\u66e8\u66e9\u66eb')
     filename = '\xdf-\u66e8\u66e9\u66eb'
     with support.temp_cwd(dirname):
         with open(filename, 'wb') as f:
             f.write((filename + '\n').encode("utf-8"))
         os.access(filename,os.R_OK)
         os.remove(filename)
开发者ID:3lnc,项目名称:cpython,代码行数:8,代码来源:test_pep277.py


示例13: test_reload_namespace_changed

    def test_reload_namespace_changed(self):
        name = 'spam'
        with support.temp_cwd(None) as cwd:
            with test_util.uncache('spam'):
                with support.DirsOnSysPath(cwd):
                    # Start as a namespace package.
                    self.init.invalidate_caches()
                    bad_path = os.path.join(cwd, name, '__init.py')
                    cached = self.util.cache_from_source(bad_path)
                    expected = {'__name__': name,
                                '__package__': name,
                                '__doc__': None,
                                '__file__': None,
                                }
                    os.mkdir(name)
                    with open(bad_path, 'w') as init_file:
                        init_file.write('eggs = None')
                    module = self.init.import_module(name)
                    ns = vars(module).copy()
                    loader = ns.pop('__loader__')
                    path = ns.pop('__path__')
                    spec = ns.pop('__spec__')
                    ns.pop('__builtins__', None)  # An implementation detail.
                    self.assertEqual(spec.name, name)
                    self.assertIsNotNone(spec.loader)
                    self.assertIsNotNone(loader)
                    self.assertEqual(spec.loader, loader)
                    self.assertEqual(set(path),
                                     set([os.path.dirname(bad_path)]))
                    with self.assertRaises(AttributeError):
                        # a NamespaceLoader
                        loader.path
                    self.assertEqual(ns, expected)

                    # Change to a regular package.
                    self.init.invalidate_caches()
                    init_path = os.path.join(cwd, name, '__init__.py')
                    cached = self.util.cache_from_source(init_path)
                    expected = {'__name__': name,
                                '__package__': name,
                                '__file__': init_path,
                                '__cached__': cached,
                                '__path__': [os.path.dirname(init_path)],
                                '__doc__': None,
                                'eggs': None,
                                }
                    os.rename(bad_path, init_path)
                    reloaded = self.init.reload(module)
                    ns = vars(reloaded).copy()
                    loader = ns.pop('__loader__')
                    spec = ns.pop('__spec__')
                    ns.pop('__builtins__', None)  # An implementation detail.
                    self.assertEqual(spec.name, name)
                    self.assertEqual(spec.loader, loader)
                    self.assertIs(reloaded, module)
                    self.assertEqual(loader.path, init_path)
                    self.assertEqual(ns, expected)
开发者ID:Dongese,项目名称:cpython,代码行数:57,代码来源:test_api.py


示例14: test_empty_python_home

 def test_empty_python_home(self):
     # http://bugs.jython.org/issue2283
     with support.temp_cwd() as temp_cwd:
         # using a new directory ensures no Lib/ directory is available
         self.assertEqual(
             subprocess.check_output(
                 [sys.executable, "-Dpython.home=", "-c",
                  "import os; os.system('echo 42'); os.system('echo 47')"])\
             .replace("\r", ""),  # in case of running on Windows
             "42\n47\n")
开发者ID:isaiah,项目名称:jython3,代码行数:10,代码来源:test_site_jy.py


示例15: extract_docstrings_from_str

 def extract_docstrings_from_str(self, module_content):
     """ utility: return all msgids extracted from module_content """
     filename = 'test_docstrings.py'
     with temp_cwd(None) as cwd:
         with open(filename, 'w') as fp:
             fp.write(module_content)
         assert_python_ok(self.script, '-D', filename)
         with open('messages.pot') as fp:
             data = fp.read()
     return self.get_msgids(data)
开发者ID:Dongese,项目名称:cpython,代码行数:10,代码来源:test_i18n.py


示例16: test_issue8202_dash_m_file_ignored

 def test_issue8202_dash_m_file_ignored(self):
     # Make sure a "-m" file in the current directory
     # does not alter the value of sys.path[0]
     with temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, 'other')
         with support.temp_cwd(path=script_dir):
             with open("-m", "w") as f:
                 f.write("data")
                 rc, out, err = assert_python_ok('-m', 'other', *example_args)
                 self._check_output(script_name, rc, out,
                                   script_name, script_name, '', '')
开发者ID:7modelsan,项目名称:kbengine,代码行数:11,代码来源:test_cmd_line_script.py


示例17: test_unicode_argv

 def test_unicode_argv(self):
     """Unicode roundtrips successfully through sys.argv arguments"""
     zhongwen = u'\u4e2d\u6587'
     with support.temp_cwd(name=u"tempcwd-%s" % zhongwen):
         p = subprocess.Popen(
             [sys.executable, '-c',
              'import sys;' \
              'sys.stdout.write(sys.argv[1].encode("utf-8"))',
              zhongwen],
             stdout=subprocess.PIPE)
         self.assertEqual(p.stdout.read().decode("utf-8"), zhongwen)
开发者ID:isaiah,项目名称:jython3,代码行数:11,代码来源:test_sys_jy.py


示例18: test_bad_python_home

 def test_bad_python_home(self):
     # http://bugs.jython.org/issue2283
     with support.temp_cwd() as temp_cwd:
         os.makedirs(os.path.join(temp_cwd, "Lib"))
         with self.assertRaises(subprocess.CalledProcessError) as cm:
             subprocess.check_output(
                 [sys.executable, "-Dpython.home=%s" % temp_cwd, "-c",
                  "print 42"],
                 stderr=subprocess.STDOUT)
         self.assertIn(
             'Exception in thread "main" ImportError: Cannot import site module and its dependencies: No module named site',
             cm.exception.output)
开发者ID:isaiah,项目名称:jython3,代码行数:12,代码来源:test_site_jy.py


示例19: test_issue8202_dash_c_file_ignored

 def test_issue8202_dash_c_file_ignored(self):
     # Make sure a "-c" file in the current directory
     # does not alter the value of sys.path[0]
     with temp_dir() as script_dir:
         with support.temp_cwd(path=script_dir):
             with open("-c", "w") as f:
                 f.write("data")
                 rc, out, err = assert_python_ok("-c", 'import sys; print("sys.path[0]==%r" % sys.path[0])')
                 if verbose > 1:
                     print(out)
                 expected = "sys.path[0]==%r" % ""
                 self.assertIn(expected.encode("utf-8"), out)
开发者ID:GaloisInc,项目名称:echronos,代码行数:12,代码来源:test_cmd_line_script.py


示例20: test_take_snapshot

    def test_take_snapshot(self):
        def callback(snapshot):
            snapshot.add_metric('callback', 5, 'size')

        with support.temp_cwd():
            task = tracemalloctext.TakeSnapshotTask(callback=callback)
            for index in range(1, 4):
                snapshot, filename = task.take_snapshot()
                self.assertEqual(snapshot.get_metric('callback'), 5)
                self.assertEqual(filename,
                                 'tracemalloc-%04d.pickle' % index)
                self.assertTrue(os.path.exists(filename))
开发者ID:waytai,项目名称:pytracemalloctext,代码行数:12,代码来源:test_tracemalloctext.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python support.temp_dir函数代码示例发布时间:2022-05-27
下一篇:
Python support.swap_item函数代码示例发布时间: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