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


Python test_support.temp_cwd函数代码示例

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


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


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