Python test.test_support.rmtree() Examples
The following are 30
code examples of test.test_support.rmtree().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.test_support
, or try the search function
.
Example #1
Source File: test_netrc.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: test_tools.py From ironpython2 with Apache License 2.0 | 6 votes |
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() )
Example #3
Source File: test_tools.py From ironpython2 with Apache License 2.0 | 6 votes |
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) )
Example #4
Source File: test_netrc.py From oss-ftp with MIT License | 6 votes |
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)
Example #5
Source File: test_netrc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #6
Source File: test_dumbdbm.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: test_mailbox.py From oss-ftp with MIT License | 5 votes |
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 = []
Example #8
Source File: test_all.py From oss-ftp with MIT License | 5 votes |
def remove_test_path_directory() : test_support.rmtree(get_new_path.prefix)
Example #9
Source File: test_tempfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #10
Source File: test_tempfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _inside_empty_temp_dir(): dir = tempfile.mkdtemp() try: with support.swap_attr(tempfile, 'tempdir', dir): yield finally: support.rmtree(dir)
Example #11
Source File: test_mailbox.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #12
Source File: test_mailbox.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 = []
Example #13
Source File: test_mailbox.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: test_mailbox.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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 = []
Example #15
Source File: test_bytecodetools_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def tearDown(self): test_support.rmtree(self.tmpdir)
Example #16
Source File: test_mailbox.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #17
Source File: test_mailbox.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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 = []
Example #18
Source File: test_bytecodetools_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def tearDown(self): test_support.rmtree(self.tmpdir)
Example #19
Source File: test_tempfile.py From oss-ftp with MIT License | 5 votes |
def _inside_empty_temp_dir(): dir = tempfile.mkdtemp() try: with support.swap_attr(tempfile, 'tempdir', dir): yield finally: support.rmtree(dir)
Example #20
Source File: test_tempfile.py From oss-ftp with MIT License | 5 votes |
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)
Example #21
Source File: test_all.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #22
Source File: test_all.py From oss-ftp with MIT License | 5 votes |
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
Example #23
Source File: test_mailbox.py From BinderFilter with MIT License | 5 votes |
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 = []
Example #24
Source File: test_mailbox.py From BinderFilter with MIT License | 5 votes |
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)
Example #25
Source File: test_all.py From BinderFilter with MIT License | 5 votes |
def remove_test_path_directory() : test_support.rmtree(get_new_path.prefix)
Example #26
Source File: test_all.py From BinderFilter with MIT License | 5 votes |
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
Example #27
Source File: test_mailbox.py From ironpython2 with Apache License 2.0 | 5 votes |
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 = []
Example #28
Source File: test_mailbox.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #29
Source File: test_tempfile.py From ironpython2 with Apache License 2.0 | 5 votes |
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?
Example #30
Source File: test_tempfile.py From ironpython2 with Apache License 2.0 | 5 votes |
def _inside_empty_temp_dir(): dir = tempfile.mkdtemp() try: with support.swap_attr(tempfile, 'tempdir', dir): yield finally: support.rmtree(dir)