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

Python test_support.temp_cwd函数代码示例

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

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



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

示例1: 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:EnviroCentre,项目名称:jython-upgrade,代码行数:34,代码来源:test_compile_jy.py


示例2: test_options_no_site_import

 def test_options_no_site_import(self):
     with test_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:EnviroCentre,项目名称:jython-upgrade,代码行数:7,代码来源:test_site_jy.py


示例3: test_getcwd

 def test_getcwd(self):
     with test_support.temp_cwd(name=u"tempcwd-中文") as temp_cwd:
         p = subprocess.Popen([sys.executable, "-c",
                               'import sys,os;' \
                               'sys.stdout.write(os.getcwd().encode("utf-8"))'],
                              stdout=subprocess.PIPE)
         self.assertEqual(p.stdout.read().decode("utf-8"), temp_cwd)
开发者ID:pekkaklarck,项目名称:jython,代码行数:7,代码来源:test_os_jy.py


示例4: test_readlink_nonexistent

 def test_readlink_nonexistent(self):
     with test_support.temp_cwd() as new_cwd:
         nonexistent_file = os.path.join(new_cwd, "nonexistent-file")
         with self.assertRaises(OSError) as cm:
             os.readlink(nonexistent_file)
         self.assertEqual(cm.exception.errno, errno.ENOENT)
         self.assertEqual(cm.exception.filename, nonexistent_file)
开发者ID:Stewori,项目名称:jython,代码行数:7,代码来源:test_os_jy.py


示例5: test_property_no_site_import

 def test_property_no_site_import(self):
     # only the minimal set of modules are imported
     with test_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:EnviroCentre,项目名称:jython-upgrade,代码行数:8,代码来源:test_site_jy.py


示例6: test_directory

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


示例7: test_link

 def test_link(self):
     with test_support.temp_cwd() as new_cwd:
         target = os.path.join(new_cwd, "target")
         with open(target, "w") as f:
             f.write("TARGET")
         source = os.path.join(new_cwd, "source")
         os.link(target, source)
         with open(source, "r") as f:
             self.assertEqual(f.read(), "TARGET")
开发者ID:Stewori,项目名称:jython,代码行数:9,代码来源:test_os_jy.py


示例8: test_bad_symlink

 def test_bad_symlink(self):
     with test_support.temp_cwd() as new_cwd:
         target = os.path.join(new_cwd, "target")
         with open(target, "w") as f:
             f.write("TARGET")
         source = os.path.join(new_cwd, "source")
         with self.assertRaises(OSError) as cm:
             os.symlink(source, target)  # reversed args!
         self.assertEqual(cm.exception.errno, errno.EEXIST)
开发者ID:Stewori,项目名称:jython,代码行数:9,代码来源:test_os_jy.py


示例9: test_getcwdu

 def test_getcwdu(self):
     with test_support.temp_cwd(name=u"tempcwd-中文") as temp_cwd:
         # os.getcwdu reports the working directory as unicode,
         # which must be encoded for subprocess communication.
         p = subprocess.Popen([
                 sys.executable, "-c",
                 'import sys,os;' \
                 'sys.stdout.write(os.getcwdu().encode(sys.getfilesystemencoding()))'],
             stdout=subprocess.PIPE)
         self.assertEqual(p.stdout.read(), temp_cwd)
开发者ID:Stewori,项目名称:jython,代码行数:10,代码来源:test_os_jy.py


示例10: test_readlink

 def test_readlink(self):
     with test_support.temp_cwd() as new_cwd:
         target = os.path.join(new_cwd, "target")
         with open(target, "w") as f:
             f.write("TARGET")
         source = os.path.join(new_cwd, "source")
         os.symlink(target, source)
         self.assertEqual(os.readlink(source), target)
         self.assertEqual(os.readlink(unicode(source)), unicode(target))
         self.assertIsInstance(os.readlink(unicode(source)), unicode)
开发者ID:Stewori,项目名称:jython,代码行数:10,代码来源:test_os_jy.py


示例11: test_empty_python_home

 def test_empty_python_home(self):
     # http://bugs.jython.org/issue2283
     with test_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:EnviroCentre,项目名称:jython-upgrade,代码行数:10,代码来源:test_site_jy.py


示例12: test_env

 def test_env(self):
     with test_support.temp_cwd(name=u"tempcwd-中文"):
         newenv = os.environ.copy()
         newenv["TEST_HOME"] = u"首页"
         p = subprocess.Popen([sys.executable, "-c",
                               'import sys,os;' \
                               'sys.stdout.write(os.getenv("TEST_HOME").encode("utf-8"))'],
                              stdout=subprocess.PIPE,
                              env=newenv)
         self.assertEqual(p.stdout.read().decode("utf-8"), u"首页")
开发者ID:pekkaklarck,项目名称:jython,代码行数:10,代码来源:test_os_jy.py


示例13: test_getcwd

 def test_getcwd(self):
     with test_support.temp_cwd(name=u"tempcwd-中文") as temp_cwd:
         # os.getcwd reports the working directory as an FS-encoded str,
         # which is also the encoding used in subprocess communication.
         p = subprocess.Popen([
                 sys.executable, "-c",
                 'import sys,os;' \
                 'sys.stdout.write(os.getcwd())'],
             stdout=subprocess.PIPE)
         self.assertEqual(p.stdout.read(), temp_cwd)
开发者ID:Stewori,项目名称:jython,代码行数:10,代码来源:test_os_jy.py


示例14: test_readlink_non_symlink

 def test_readlink_non_symlink(self):
     """os.readlink of a non symbolic link should raise an error"""
     # test for http://bugs.jython.org/issue2292
     with test_support.temp_cwd() as new_cwd:
         target = os.path.join(new_cwd, "target")
         with open(target, "w") as f:
             f.write("TARGET")
         with self.assertRaises(OSError) as cm:
             os.readlink(target)
         self.assertEqual(cm.exception.errno, errno.EINVAL)
         self.assertEqual(cm.exception.filename, target)
开发者ID:Stewori,项目名称:jython,代码行数:11,代码来源:test_os_jy.py


示例15: test_unicode_argv

 def test_unicode_argv(self):
     # Unicode roundtrips successfully through sys.argv arguments
     zhongwen = u'\u4e2d\u6587'
     with test_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:Stewori,项目名称:jython,代码行数:11,代码来源:test_sys_jy.py


示例16: test_bad_python_home

 def test_bad_python_home(self):
     # http://bugs.jython.org/issue2283
     with test_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:EnviroCentre,项目名称:jython-upgrade,代码行数:12,代码来源:test_site_jy.py


示例17: test_listdir

    def test_listdir(self):
        # It is hard to avoid Unicode paths on systems like OS X. Use
        # relative paths from a temp CWD to work around this
        with test_support.temp_cwd() as new_cwd:
            unicode_path = os.path.join(".", "unicode")
            self.assertIs(type(unicode_path), str)
            chinese_path = os.path.join(unicode_path, u"中文")
            self.assertIs(type(chinese_path), unicode)
            home_path = os.path.join(chinese_path, u"首页")
            os.makedirs(home_path)
            
            with open(os.path.join(home_path, "test.txt"), "w") as test_file:
                test_file.write("42\n")

            # Verify works with str paths, returning Unicode as necessary
            entries = os.listdir(unicode_path)
            self.assertIn(u"中文", entries)

            # Verify works with Unicode paths
            entries = os.listdir(chinese_path)
            self.assertIn(u"首页", entries)
           
            # glob.glob builds on os.listdir; note that we don't use
            # Unicode paths in the arg to glob
            self.assertEqual(
                glob.glob(os.path.join("unicode", "*")),
                [os.path.join(u"unicode", u"中文")])
            self.assertEqual(
                glob.glob(os.path.join("unicode", "*", "*")),
                [os.path.join(u"unicode", u"中文", u"首页")])
            self.assertEqual(
                glob.glob(os.path.join("unicode", "*", "*", "*")),
                [os.path.join(u"unicode", u"中文", u"首页", "test.txt")])

            # Now use a Unicode path as well as in the glob arg
            self.assertEqual(
                glob.glob(os.path.join(u"unicode", "*")),
                [os.path.join(u"unicode", u"中文")])
            self.assertEqual(
                glob.glob(os.path.join(u"unicode", "*", "*")),
                [os.path.join(u"unicode", u"中文", u"首页")])
            self.assertEqual(
                glob.glob(os.path.join(u"unicode", "*", "*", "*")),
                [os.path.join(u"unicode", u"中文", u"首页", "test.txt")])
 
            # Verify Java integration. But we will need to construct
            # an absolute path since chdir doesn't work with Java
            # (except for subprocesses, like below in test_env)
            for entry in entries:
                entry_path = os.path.join(new_cwd, chinese_path, entry)
                f = File(entry_path)
                self.assertTrue(f.exists(), "File %r (%r) should be testable for existence" % (
                    f, entry_path))
开发者ID:EnviroCentre,项目名称:jython-upgrade,代码行数:53,代码来源:test_os_jy.py


示例18: test_bad_link

    def test_bad_link(self):
        with test_support.temp_cwd() as new_cwd:
            target = os.path.join(new_cwd, "target")
            with open(target, "w") as f:
                f.write("TARGET")
            source = os.path.join(new_cwd, "source")
            with self.assertRaises(OSError) as cm:
                os.link(target, target)
            self.assertEqual(cm.exception.errno, errno.EEXIST)

            with self.assertRaises(OSError) as cm:
                os.link("nonexistent-file", source)
            self.assertEqual(cm.exception.errno, errno.ENOENT)
开发者ID:Stewori,项目名称:jython,代码行数:13,代码来源:test_os_jy.py


示例19: test_system_uses_os_environ

 def test_system_uses_os_environ(self):
     """Writing to os.environ is made available as env vars in os.system subprocesses"""
     # This test likely requires additional customization for
     # environments like AS/400, but I do not have current access.
     # Verifies fix for http://bugs.jython.org/issue2416
     if os._name == "nt":
         echo_command = 'echo %TEST_ENVVAR%'
     else:
         echo_command = 'echo $TEST_ENVVAR'
     with test_support.temp_cwd() as temp_cwd:
         self.assertEqual(
             subprocess.check_output(
                 [sys.executable, "-c",
                  "import os; os.environ['TEST_ENVVAR'] = 'works on 2.7.1+'; os.system('%s')" % echo_command])\
             .replace("\r", ""),  # in case of running on Windows
             "works on 2.7.1+\n")
开发者ID:Stewori,项目名称:jython,代码行数:16,代码来源:test_os_jy.py


示例20: test_system_no_site_import

 def test_system_no_site_import(self):
     # If not importing site (-S), importing traceback previously
     # would fail with an import error due to creating a circular
     # import chain. This root cause is because the os module
     # imports the subprocess module for the system function; but
     # the subprocess module imports from os. Verifies that this is
     # managed by making the import late; also verify the
     # monkeypatching optimization is successful by calling
     # os.system twice.
     with test_support.temp_cwd() as temp_cwd:
         self.assertEqual(
             subprocess.check_output(
                 [sys.executable, "-S", "-c",
                  "import traceback; import os; os.system('echo 42'); os.system('echo 47')"])\
             .replace("\r", ""),  # in case of running on Windows
             "42\n47\n")
开发者ID:Stewori,项目名称:jython,代码行数:16,代码来源:test_os_jy.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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