本文整理汇总了Python中test.test_support.rmtree函数的典型用法代码示例。如果您正苦于以下问题:Python rmtree函数的具体用法?Python rmtree怎么用?Python rmtree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rmtree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _inside_empty_temp_dir
def _inside_empty_temp_dir():
dir = tempfile.mkdtemp()
try:
with support.swap_attr(tempfile, 'tempdir', dir):
yield
finally:
support.rmtree(dir)
示例2: tearDown
def tearDown(self):
sys.path[:] = self.sys_path
if self.orig_module is not None:
sys.modules[self.module_name] = self.orig_module
else:
unload(self.module_name)
unlink(self.file_name)
unlink(self.compiled_name)
rmtree(self.dir_name)
示例3: get_new_environment_path
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
示例4: check_script_output
def check_script_output(self, src, expected):
tmpd = tempfile.mkdtemp()
try:
fn = os.path.join(tmpd, 'test.py')
with open(fn, 'wb') as fp:
fp.write(src)
rc, out, err = script_helper.assert_python_ok(fn)
finally:
rmtree(tmpd)
self.assertEqual(out.rstrip(), expected)
示例5: create_modules
def create_modules(*names):
u"""Temporarily create each named module with an attribute (named 'attr')
that contains the name passed into the context manager that caused the
creation of the module.
All files are created in a temporary directory returned by
tempfile.mkdtemp(). This directory is inserted at the beginning of
sys.path. When the context manager exits all created files (source and
bytecode) are explicitly deleted.
No magic is performed when creating packages! This means that if you create
a module within a package you must also create the package's __init__ as
well.
"""
source = u'attr = {0!r}'
created_paths = []
mapping = {}
state_manager = None
uncache_manager = None
try:
temp_dir = tempfile.mkdtemp()
mapping[u'.root'] = temp_dir
import_names = set()
for name in names:
if not name.endswith(u'__init__'):
import_name = name
else:
import_name = name[:-len(u'.__init__')]
import_names.add(import_name)
if import_name in sys.modules:
del sys.modules[import_name]
name_parts = name.split(u'.')
file_path = temp_dir
for directory in name_parts[:-1]:
file_path = os.path.join(file_path, directory)
if not os.path.exists(file_path):
os.mkdir(file_path)
created_paths.append(file_path)
file_path = os.path.join(file_path, name_parts[-1] + u'.py')
with open(file_path, u'w') as file:
file.write(source.format(name))
created_paths.append(file_path)
mapping[name] = file_path
uncache_manager = util.uncache(*import_names)
uncache_manager.__enter__()
state_manager = util.import_state(path=[temp_dir])
state_manager.__enter__()
yield mapping
finally:
if state_manager is not None:
state_manager.__exit__(None, None, None)
if uncache_manager is not None:
uncache_manager.__exit__(None, None, None)
support.rmtree(temp_dir)
示例6: test_yet_more_evil_still_undecodable
def test_yet_more_evil_still_undecodable(self):
# Issue #25388
src = b"#\x00\n#\xfd\n"
tmpd = tempfile.mkdtemp()
try:
fn = os.path.join(tmpd, "bad.py")
with open(fn, "wb") as fp:
fp.write(src)
rc, out, err = script_helper.assert_python_failure(fn)
finally:
test_support.rmtree(tmpd)
self.assertIn(b"Non-ASCII", err)
示例7: test_readonly_files
def test_readonly_files(self):
dir = _fname
os.mkdir(dir)
try:
fname = os.path.join(dir, 'db')
f = dumbdbm.open(fname, 'n')
self.assertEqual(list(f.keys()), [])
for key in self._dict:
f[key] = self._dict[key]
f.close()
os.chmod(fname + ".dir", stat.S_IRUSR)
os.chmod(fname + ".dat", stat.S_IRUSR)
os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
f = dumbdbm.open(fname, 'r')
self.assertEqual(sorted(f.keys()), sorted(self._dict))
f.close() # don't write
finally:
test_support.rmtree(dir)
示例8: test_yet_more_evil_still_undecodable
def test_yet_more_evil_still_undecodable(self):
# Issue #25388
src = b"#\x00\n#\xfd\n"
tmpd = tempfile.mkdtemp()
try:
fn = os.path.join(tmpd, "bad.py")
with open(fn, "wb") as fp:
fp.write(src)
try:
rc, out, err = script_helper.assert_python_failure(fn)
except AssertionError:
if check_impl_detail(pypy=True):
# as long as we don't crash
return
raise
finally:
test_support.rmtree(tmpd)
self.assertIn(b"Non-ASCII", err)
示例9: test_security
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.
os.unlink(temp_filename)
d = test_support.TESTFN
try:
os.mkdir(d)
fn = os.path.join(d, '.netrc')
with open(fn, 'wt') as f:
f.write(TEST_NETRC)
with test_support.EnvironmentVarGuard() as environ:
environ.set('HOME', d)
os.chmod(fn, 0600)
self.netrc = netrc.netrc()
self.test_case_1()
os.chmod(fn, 0622)
self.assertRaises(netrc.NetrcParseError, netrc.netrc)
finally:
test_support.rmtree(d)
示例10: tearDown
def tearDown(self):
rmtree(TESTFN)
unlink(TESTFN)
示例11: newdirinpath
def newdirinpath(dir):
os.mkdir(dir)
sys.path.insert(0, dir)
yield
sys.path.pop(0)
rmtree(dir)
示例12: tearDown
def tearDown(self):
test_support.rmtree(self.tmpdir)
示例13: remove_test_path_directory
def remove_test_path_directory() :
test_support.rmtree(get_new_path.prefix)
示例14: tearDown
def tearDown(self):
rmtree(self.topdir)
示例15: tearDownClass
def tearDownClass(cls):
td = cls.tmpdir
if td and os.path.isdir(td):
test_support.rmtree(td)