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


Python support.rmtree方法代码示例

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


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

示例1: test_rmtree

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def test_rmtree(self):
        dirpath = support.TESTFN + 'd'
        subdirpath = os.path.join(dirpath, 'subdir')
        os.mkdir(dirpath)
        os.mkdir(subdirpath)
        support.rmtree(dirpath)
        self.assertFalse(os.path.exists(dirpath))
        with support.swap_attr(support, 'verbose', 0):
            support.rmtree(dirpath)

        os.mkdir(dirpath)
        os.mkdir(subdirpath)
        os.chmod(dirpath, stat.S_IRUSR|stat.S_IXUSR)
        with support.swap_attr(support, 'verbose', 0):
            support.rmtree(dirpath)
        self.assertFalse(os.path.exists(dirpath))

        os.mkdir(dirpath)
        os.mkdir(subdirpath)
        os.chmod(dirpath, 0)
        with support.swap_attr(support, 'verbose', 0):
            support.rmtree(dirpath)
        self.assertFalse(os.path.exists(dirpath)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_test_support.py

示例2: test_temp_dir__existing_dir__quiet_true

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_test_support.py

示例3: test_security

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def test_security(self):
        # This test is incomplete since we are normally not run as root and
        # therefore can't test the file ownership being wrong.
        d = support.TESTFN
        os.mkdir(d)
        self.addCleanup(support.rmtree, d)
        fn = os.path.join(d, '.netrc')
        with open(fn, 'wt') as f:
            f.write("""\
                machine foo.domain.com login bar password pass
                default login foo password pass
                """)
        with support.EnvironmentVarGuard() as environ:
            environ.set('HOME', d)
            os.chmod(fn, 0o600)
            nrc = netrc.netrc()
            self.assertEqual(nrc.hosts['foo.domain.com'],
                             ('bar', None, 'pass'))
            os.chmod(fn, 0o622)
            self.assertRaises(netrc.NetrcParseError, netrc.netrc) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_netrc.py

示例4: test_temp_dir__existing_dir__quiet_true

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [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:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_support.py

示例5: setUp

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def setUp(self):
        os.mkdir(BASE)
        self.addCleanup(support.rmtree, BASE)
        os.mkdir(join('dirA'))
        os.mkdir(join('dirB'))
        os.mkdir(join('dirC'))
        os.mkdir(join('dirC', 'dirD'))
        with open(join('fileA'), 'wb') as f:
            f.write(b"this is file A\n")
        with open(join('dirB', 'fileB'), 'wb') as f:
            f.write(b"this is file B\n")
        with open(join('dirC', 'fileC'), 'wb') as f:
            f.write(b"this is file C\n")
        with open(join('dirC', 'dirD', 'fileD'), 'wb') as f:
            f.write(b"this is file D\n")
        if not symlink_skip_reason:
            # Relative symlinks
            os.symlink('fileA', join('linkA'))
            os.symlink('non-existing', join('brokenLink'))
            self.dirlink('dirB', join('linkB'))
            self.dirlink(os.path.join('..', 'dirB'), join('dirA', 'linkC'))
            # This one goes upwards but doesn't create a loop
            self.dirlink(os.path.join('..', 'dirB'), join('dirB', 'linkD')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_pathlib.py

示例6: test_resolve_common

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def test_resolve_common(self):
        P = self.cls
        p = P(BASE, 'foo')
        with self.assertRaises(OSError) as cm:
            p.resolve()
        self.assertEqual(cm.exception.errno, errno.ENOENT)
        # These are all relative symlinks
        p = P(BASE, 'dirB', 'fileB')
        self._check_resolve_relative(p, p)
        p = P(BASE, 'linkA')
        self._check_resolve_relative(p, P(BASE, 'fileA'))
        p = P(BASE, 'dirA', 'linkC', 'fileB')
        self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB'))
        p = P(BASE, 'dirB', 'linkD', 'fileB')
        self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB'))
        # Now create absolute symlinks
        d = tempfile.mkdtemp(suffix='-dirD')
        self.addCleanup(support.rmtree, d)
        os.symlink(os.path.join(d), join('dirA', 'linkX'))
        os.symlink(join('dirB'), os.path.join(d, 'linkY'))
        p = P(BASE, 'dirA', 'linkX', 'linkY', 'fileB')
        self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_pathlib.py

示例7: setUp

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def setUp(self):
        self.dirname = support.TESTFN
        self.fname = os.path.join(self.dirname, "f1")

        self.addCleanup(support.rmtree, self.dirname)
        os.mkdir(self.dirname)
        with open(self.fname, 'wb') as fp:
            fp.write(b"ABC")

        def restore_float_times(state):
            with warnings.catch_warnings():
                warnings.simplefilter("ignore", DeprecationWarning)

                os.stat_float_times(state)

        # ensure that st_atime and st_mtime are float
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", DeprecationWarning)

            old_float_times = os.stat_float_times(-1)
            self.addCleanup(restore_float_times, old_float_times)

            os.stat_float_times(True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_os.py

示例8: run_pdb

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def run_pdb(self, script, commands):
        """Run 'script' lines with pdb and the pdb 'commands'."""
        filename = 'main.py'
        with open(filename, 'w') as f:
            f.write(textwrap.dedent(script))
        self.addCleanup(support.unlink, filename)
        self.addCleanup(support.rmtree, '__pycache__')
        cmd = [sys.executable, '-m', 'pdb', filename]
        stdout = stderr = None
        with subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                   stdin=subprocess.PIPE,
                                   stderr=subprocess.STDOUT,
                                   ) as proc:
            stdout, stderr = proc.communicate(str.encode(commands))
        stdout = stdout and bytes.decode(stdout)
        stderr = stderr and bytes.decode(stderr)
        return stdout, stderr 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_pdb.py

示例9: get_new_environment_path

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def get_new_environment_path() :
    path=get_new_path("environment")
    import os
    try:
        os.makedirs(path,mode=0700)
    except os.error:
        test_support.rmtree(path)
        os.makedirs(path)
    return path 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_all.py

示例10: remove_test_path_directory

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def remove_test_path_directory() :
    test_support.rmtree(get_new_path.prefix) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_all.py

示例11: test_forget

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
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:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_test_support.py

示例12: test_temp_dir

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [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

示例13: restore_support_TESTFN

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def restore_support_TESTFN(self, saved_value):
        if saved_value is None:
            if os.path.isfile(support.TESTFN):
                os.unlink(support.TESTFN)
            elif os.path.isdir(support.TESTFN):
                shutil.rmtree(support.TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:regrtest.py

示例14: restore_files

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def restore_files(self, saved_value):
        fn = support.TESTFN
        if fn not in saved_value and (fn + '/') not in saved_value:
            if os.path.isfile(fn):
                support.unlink(fn)
            elif os.path.isdir(fn):
                support.rmtree(fn) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:regrtest.py

示例15: cleanup_test_droppings

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import rmtree [as 别名]
def cleanup_test_droppings(testname, verbose):
    import stat
    import gc

    # First kill any dangling references to open files etc.
    gc.collect()

    # Try to clean up junk commonly left behind.  While tests shouldn't leave
    # any files or directories behind, when a test fails that can be tedious
    # for it to arrange.  The consequences can be especially nasty on Windows,
    # since if a test leaves a file open, it cannot be deleted by name (while
    # there's nothing we can do about that here either, we can display the
    # name of the offending test, which is a real help).
    for name in (support.TESTFN,
                 "db_home",
                ):
        if not os.path.exists(name):
            continue

        if os.path.isdir(name):
            kind, nuker = "directory", shutil.rmtree
        elif os.path.isfile(name):
            kind, nuker = "file", os.unlink
        else:
            raise SystemError("os.path says %r exists but is neither "
                              "directory nor file" % name)

        if verbose:
            print "%r left behind %s %r" % (testname, kind, name)
        try:
            # if we have chmod, fix possible permissions problems
            # that might prevent cleanup
            if (hasattr(os, 'chmod')):
                os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
            nuker(name)
        except Exception, msg:
            print >> sys.stderr, ("%r left behind %s %r and it couldn't be "
                "removed: %s" % (testname, kind, name, msg)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:40,代码来源:regrtest.py


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