本文整理汇总了Python中test.test_support.rmtree方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.rmtree方法的具体用法?Python test_support.rmtree怎么用?Python test_support.rmtree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.test_support
的用法示例。
在下文中一共展示了test_support.rmtree方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_security
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.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 = test_support.TESTFN
os.mkdir(d)
self.addCleanup(test_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 test_support.EnvironmentVarGuard() as environ:
environ.set('HOME', d)
os.chmod(fn, 0600)
nrc = netrc.netrc()
self.assertEqual(nrc.hosts['foo.domain.com'],
('bar', None, 'pass'))
os.chmod(fn, 0o622)
self.assertRaises(netrc.NetrcParseError, netrc.netrc)
示例2: test_directory
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def test_directory(self):
os.mkdir(test_support.TESTFN)
self.addCleanup(test_support.rmtree, test_support.TESTFN)
c_filename = os.path.join(test_support.TESTFN, "file.c")
with open(c_filename, "w") as file:
file.write("int xx;\n")
with open(os.path.join(test_support.TESTFN, "file.py"), "w") as file:
file.write("xx = 'unaltered'\n")
script = os.path.join(scriptsdir, "fixcid.py")
# ignore dbg() messages
with test_support.captured_stderr() as stderr:
output = self.run_script(args=(test_support.TESTFN,))
self.assertMultiLineEqual(output,
"{}:\n"
"1\n"
'< int xx;\n'
'> int yy;\n'.format(c_filename),
"stderr: %s" % stderr.getvalue()
)
示例3: test_lll_multiple_dirs
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def test_lll_multiple_dirs(self):
dir1 = tempfile.mkdtemp()
dir2 = tempfile.mkdtemp()
self.addCleanup(test_support.rmtree, dir1)
self.addCleanup(test_support.rmtree, dir2)
fn1 = os.path.join(dir1, 'foo1')
fn2 = os.path.join(dir2, 'foo2')
for fn, dir in (fn1, dir1), (fn2, dir2):
open(fn, 'w').close()
os.symlink(fn, os.path.join(dir, 'symlink'))
rc, out, err = assert_python_ok(self.script, dir1, dir2)
self.assertEqual(out,
'{dir1}:\n'
'symlink -> {fn1}\n'
'\n'
'{dir2}:\n'
'symlink -> {fn2}\n'
.format(dir1=dir1, fn1=fn1, dir2=dir2, fn2=fn2)
)
示例4: test_readonly_files
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
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)
示例5: get_new_environment_path
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.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
示例6: remove_test_path_directory
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def remove_test_path_directory() :
test_support.rmtree(get_new_path.prefix)
示例7: _inside_empty_temp_dir
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def _inside_empty_temp_dir():
dir = tempfile.mkdtemp()
try:
with support.swap_attr(tempfile, 'tempdir', dir):
yield
finally:
support.rmtree(dir)
示例8: test_bad_mode
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def test_bad_mode(self):
dir = tempfile.mkdtemp()
self.addCleanup(support.rmtree, dir)
with self.assertRaises(TypeError):
tempfile.NamedTemporaryFile(mode=(), dir=dir)
self.assertEqual(os.listdir(dir), [])
# How to test the mode and bufsize parameters?
示例9: _delete_recursively
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def _delete_recursively(self, target):
# Delete a file or delete a directory recursively
if os.path.isdir(target):
test_support.rmtree(target)
elif os.path.exists(target):
test_support.unlink(target)
示例10: setUp
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def setUp(self):
# create a new maildir mailbox to work with:
self._dir = test_support.TESTFN
if os.path.isdir(self._dir):
test_support.rmtree(self._dir)
if os.path.isfile(self._dir):
test_support.unlink(self._dir)
os.mkdir(self._dir)
os.mkdir(os.path.join(self._dir, "cur"))
os.mkdir(os.path.join(self._dir, "tmp"))
os.mkdir(os.path.join(self._dir, "new"))
self._counter = 1
self._msgfiles = []
示例11: test_no_files_left_behind
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def test_no_files_left_behind(self):
# use a private empty directory
our_temp_directory = tempfile.mkdtemp()
try:
# force _get_default_tempdir() to consider our empty directory
def our_candidate_list():
return [our_temp_directory]
with support.swap_attr(tempfile, "_candidate_tempdir_list",
our_candidate_list):
# verify our directory is empty after _get_default_tempdir()
tempfile._get_default_tempdir()
self.assertEqual(os.listdir(our_temp_directory), [])
def raise_OSError(*args, **kwargs):
raise OSError(-1)
with support.swap_attr(io, "open", raise_OSError):
# test again with failing io.open()
with self.assertRaises(IOError) as cm:
tempfile._get_default_tempdir()
self.assertEqual(cm.exception.errno, errno.ENOENT)
self.assertEqual(os.listdir(our_temp_directory), [])
open = io.open
def bad_writer(*args, **kwargs):
fp = open(*args, **kwargs)
fp.write = raise_OSError
return fp
with support.swap_attr(io, "open", bad_writer):
# test again with failing write()
with self.assertRaises(IOError) as cm:
tempfile._get_default_tempdir()
self.assertEqual(cm.exception.errno, errno.ENOENT)
self.assertEqual(os.listdir(our_temp_directory), [])
finally:
shutil.rmtree(our_temp_directory)
示例12: tearDown
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import rmtree [as 别名]
def tearDown(self):
test_support.rmtree(self.tmpdir)