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


Python support.temp_dir方法代码示例

本文整理汇总了Python中test.support.temp_dir方法的典型用法代码示例。如果您正苦于以下问题:Python support.temp_dir方法的具体用法?Python support.temp_dir怎么用?Python support.temp_dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test.support的用法示例。


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

示例1: test_temp_dir__existing_dir__quiet_default

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_temp_dir__existing_dir__quiet_default(self):
        """Test passing a directory that already exists."""
        def call_temp_dir(path):
            with support.temp_dir(path) as temp_path:
                raise Exception("should not get here")

        path = tempfile.mkdtemp()
        path = os.path.realpath(path)
        try:
            self.assertTrue(os.path.isdir(path))
            with self.assertRaises(OSError) as cm:
                call_temp_dir(path)
            self.assertEqual(cm.exception.errno, errno.EEXIST)
            # Make sure temp_dir did not delete the original directory.
            self.assertTrue(os.path.isdir(path))
        finally:
            shutil.rmtree(path) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_test_support.py

示例2: test_change_cwd__non_existent_dir__quiet_true

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_change_cwd__non_existent_dir__quiet_true(self):
        """Test passing a non-existent directory with quiet=True."""
        original_cwd = os.getcwd()

        with support.temp_dir() as parent_dir:
            bad_dir = os.path.join(parent_dir, 'does_not_exist')
            with support.check_warnings() as recorder:
                with support.change_cwd(bad_dir, quiet=True) as new_cwd:
                    self.assertEqual(new_cwd, original_cwd)
                    self.assertEqual(os.getcwd(), new_cwd)
                warnings = [str(w.message) for w in recorder.warnings]

        expected = ['tests may fail, unable to change CWD to: ' + bad_dir]
        self.assertEqual(warnings, expected)

    # Tests for change_cwd() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_test_support.py

示例3: test_issue8202

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_issue8202(self):
        # Make sure package __init__ modules see "-m" in sys.argv0 while
        # searching for the module to execute
        with support.temp_dir() as script_dir:
            with support.change_cwd(path=script_dir):
                pkg_dir = os.path.join(script_dir, 'test_pkg')
                make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])")
                script_name = _make_test_script(pkg_dir, 'script')
                rc, out, err = assert_python_ok('-m', 'test_pkg.script', *example_args, __isolated=False)
                if verbose > 1:
                    print(repr(out))
                expected = "init_argv0==%r" % '-m'
                self.assertIn(expected.encode('utf-8'), out)
                self._check_output(script_name, rc, out,
                                   script_name, script_name, '', 'test_pkg',
                                   importlib.machinery.SourceFileLoader) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_cmd_line_script.py

示例4: test_pep_409_verbiage

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_pep_409_verbiage(self):
        # Make sure PEP 409 syntax properly suppresses
        # the context of an exception
        script = textwrap.dedent("""\
            try:
                raise ValueError
            except:
                raise NameError from None
            """)
        with support.temp_dir() as script_dir:
            script_name = _make_test_script(script_dir, 'script', script)
            exitcode, stdout, stderr = assert_python_failure(script_name)
            text = stderr.decode('ascii').split('\n')
            self.assertEqual(len(text), 4)
            self.assertTrue(text[0].startswith('Traceback'))
            self.assertTrue(text[1].startswith('  File '))
            self.assertTrue(text[3].startswith('NameError')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_cmd_line_script.py

示例5: test_issue20500_exit_with_exception_value

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_issue20500_exit_with_exception_value(self):
        script = textwrap.dedent("""\
            import sys
            error = None
            try:
                raise ValueError('some text')
            except ValueError as err:
                error = err

            if error:
                sys.exit(error)
            """)
        with support.temp_dir() as script_dir:
            script_name = _make_test_script(script_dir, 'script', script)
            exitcode, stdout, stderr = assert_python_failure(script_name)
            text = stderr.decode('ascii')
            self.assertEqual(text, "some text") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_cmd_line_script.py

示例6: test_temp_dir__existing_dir__quiet_true

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_temp_dir__existing_dir__quiet_true(self):
        """Test passing a directory that already exists with quiet=True."""
        path = tempfile.mkdtemp()
        path = os.path.realpath(path)

        try:
            with support.check_warnings() as recorder:
                with support.temp_dir(path, quiet=True) as temp_path:
                    self.assertEqual(path, temp_path)
                warnings = [str(w.message) for w in recorder.warnings]
            # Make sure temp_dir did not delete the original directory.
            self.assertTrue(os.path.isdir(path))
        finally:
            shutil.rmtree(path)

        expected = ['tests may fail, unable to create temp dir: ' + path]
        self.assertEqual(warnings, expected)

    # Tests for change_cwd() 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:test_support.py

示例7: test_find_executable

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_find_executable(self):
        with test_support.temp_dir() as tmp_dir:
            # use TESTFN to get a pseudo-unique filename
            program_noeext = test_support.TESTFN
            # Give the temporary program an ".exe" suffix for all.
            # It's needed on Windows and not harmful on other platforms.
            program = program_noeext + ".exe"

            filename = os.path.join(tmp_dir, program)
            with open(filename, "wb"):
                pass
            os.chmod(filename, stat.S_IXUSR)

            # test path parameter
            rv = find_executable(program, path=tmp_dir)
            self.assertEqual(rv, filename)

            if sys.platform == 'win32':
                # test without ".exe" extension
                rv = find_executable(program_noeext, path=tmp_dir)
                self.assertEqual(rv, filename)

            # test find in the current directory
            with test_support.change_cwd(tmp_dir):
                rv = find_executable(program)
                self.assertEqual(rv, program)

            # test non-existent program
            dont_exist_program = "dontexist_" + program
            rv = find_executable(dont_exist_program , path=tmp_dir)
            self.assertIsNone(rv)

            # test os.defpath: missing PATH environment variable
            with test_support.EnvironmentVarGuard() as env:
                from distutils import spawn
                with test_support.swap_attr(spawn.os, 'defpath', tmp_dir):
                    env.pop('PATH')

                    rv = find_executable(program)
                    self.assertEqual(rv, filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:42,代码来源:test_spawn.py

示例8: test_bind_port

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_bind_port(self):
        s = socket.socket()
        support.bind_port(s)
        s.listen(5)
        s.close()

    # Tests for temp_dir() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_test_support.py

示例9: test_temp_dir

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_temp_dir(self):
        """Test that temp_dir() creates and destroys its directory."""
        parent_dir = tempfile.mkdtemp()
        parent_dir = os.path.realpath(parent_dir)

        try:
            path = os.path.join(parent_dir, 'temp')
            self.assertFalse(os.path.isdir(path))
            with support.temp_dir(path) as temp_path:
                self.assertEqual(temp_path, path)
                self.assertTrue(os.path.isdir(path))
            self.assertFalse(os.path.isdir(path))
        finally:
            support.rmtree(parent_dir) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_test_support.py

示例10: test_temp_dir__path_none

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_temp_dir__path_none(self):
        """Test passing no path."""
        with support.temp_dir() as temp_path:
            self.assertTrue(os.path.isdir(temp_path))
        self.assertFalse(os.path.isdir(temp_path)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_test_support.py

示例11: test_change_cwd

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_change_cwd(self):
        original_cwd = os.getcwd()

        with support.temp_dir() as temp_path:
            with support.change_cwd(temp_path) as new_cwd:
                self.assertEqual(new_cwd, temp_path)
                self.assertEqual(os.getcwd(), new_cwd)

        self.assertEqual(os.getcwd(), original_cwd) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_test_support.py

示例12: test_change_cwd__non_existent_dir

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_change_cwd__non_existent_dir(self):
        """Test passing a non-existent directory."""
        original_cwd = os.getcwd()

        def call_change_cwd(path):
            with support.change_cwd(path) as new_cwd:
                raise Exception("should not get here")

        with support.temp_dir() as parent_dir:
            non_existent_dir = os.path.join(parent_dir, 'does_not_exist')
            with self.assertRaises(OSError) as cm:
                call_change_cwd(non_existent_dir)
            self.assertEqual(cm.exception.errno, errno.ENOENT)

        self.assertEqual(os.getcwd(), original_cwd) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_test_support.py

示例13: test_basic_script

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_basic_script(self):
        with support.temp_dir() as script_dir:
            script_name = _make_test_script(script_dir, 'script')
            self._check_script(script_name) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_multiprocessing_main_handling.py

示例14: test_basic_script_no_suffix

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_basic_script_no_suffix(self):
        with support.temp_dir() as script_dir:
            script_name = _make_test_script(script_dir, 'script',
                                            omit_suffix=True)
            self._check_script(script_name) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_multiprocessing_main_handling.py

示例15: test_ipython_workaround

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import temp_dir [as 别名]
def test_ipython_workaround(self):
        # Some versions of the IPython launch script are missing the
        # __name__ = "__main__" guard, and multiprocessing has long had
        # a workaround for that case
        # See https://github.com/ipython/ipython/issues/4698
        source = test_source_main_skipped_in_children
        with support.temp_dir() as script_dir:
            script_name = _make_test_script(script_dir, 'ipython',
                                            source=source)
            self._check_script(script_name)
            script_no_suffix = _make_test_script(script_dir, 'ipython',
                                                 source=source,
                                                 omit_suffix=True)
            self._check_script(script_no_suffix) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_multiprocessing_main_handling.py


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