Python test.test_support.unlink() Examples
The following are 30
code examples of test.test_support.unlink().
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_pdb.py From ironpython2 with Apache License 2.0 | 6 votes |
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(test_support.unlink, filename) cmd = [sys.executable, '-m', 'pdb', filename] stdout = stderr = None proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, ) stdout, stderr = proc.communicate(commands) proc.stdout.close() proc.stdin.close() return stdout, stderr
Example #2
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_path_with_null_byte(self): fn = test_support.TESTFN fn_with_NUL = fn + '\0' self.addCleanup(test_support.unlink, fn) test_support.unlink(fn) fd = None try: with self.assertRaises(TypeError): fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises finally: if fd is not None: os.close(fd) self.assertFalse(os.path.exists(fn)) self.assertRaises(TypeError, os.mkdir, fn_with_NUL) self.assertFalse(os.path.exists(fn)) open(fn, 'wb').close() self.assertRaises(TypeError, os.stat, fn_with_NUL)
Example #3
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_path_with_null_unicode(self): fn = test_support.TESTFN_UNICODE try: fn.encode(test_support.TESTFN_ENCODING) except (UnicodeError, TypeError): self.skipTest("Requires unicode filenames support") fn_with_NUL = fn + u'\0' self.addCleanup(test_support.unlink, fn) test_support.unlink(fn) fd = None try: with self.assertRaises(TypeError): fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises finally: if fd is not None: os.close(fd) self.assertFalse(os.path.exists(fn)) self.assertRaises(TypeError, os.mkdir, fn_with_NUL) self.assertFalse(os.path.exists(fn)) open(fn, 'wb').close() self.assertRaises(TypeError, os.stat, fn_with_NUL)
Example #4
Source File: test_array.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_filewrite(self): a = array.array(self.typecode, 2*self.example) f = open(test_support.TESTFN, 'wb') try: f.write(a) f.close() b = array.array(self.typecode) f = open(test_support.TESTFN, 'rb') b.fromfile(f, len(self.example)) self.assertEqual(b, array.array(self.typecode, self.example)) self.assertNotEqual(a, b) b.fromfile(f, len(self.example)) self.assertEqual(a, b) f.close() finally: if not f.closed: f.close() test_support.unlink(test_support.TESTFN)
Example #5
Source File: test_fileinput.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_readline(self): with open(TESTFN, 'wb') as f: f.write('A\nB\r\nC\r') # Fill TextIOWrapper buffer. f.write('123456789\n' * 1000) # Issue #20501: readline() shouldn't read whole file. f.write('\x80') self.addCleanup(safe_unlink, TESTFN) fi = FileInput(files=TESTFN, openhook=hook_encoded('ascii')) # The most likely failure is a UnicodeDecodeError due to the entire # file being read when it shouldn't have been. self.assertEqual(fi.readline(), u'A\n') self.assertEqual(fi.readline(), u'B\r\n') self.assertEqual(fi.readline(), u'C\r') with self.assertRaises(UnicodeDecodeError): # Read to the end of file. list(fi) fi.close()
Example #6
Source File: test_contextlib.py From ironpython2 with Apache License 2.0 | 6 votes |
def testWithOpen(self): tfn = tempfile.mktemp() try: f = None with open(tfn, "w") as f: self.assertFalse(f.closed) f.write("Booh\n") self.assertTrue(f.closed) f = None with self.assertRaises(ZeroDivisionError): with open(tfn, "r") as f: self.assertFalse(f.closed) self.assertEqual(f.read(), "Booh\n") 1 // 0 self.assertTrue(f.closed) finally: test_support.unlink(tfn)
Example #7
Source File: test_tools.py From ironpython2 with Apache License 2.0 | 6 votes |
def run_script(self, input="", args=("-",), substfile="xx yy\n"): substfilename = test_support.TESTFN + ".subst" with open(substfilename, "w") as file: file.write(substfile) self.addCleanup(test_support.unlink, substfilename) argv = ["fixcid.py", "-s", substfilename] + list(args) script = os.path.join(scriptsdir, "fixcid.py") with test_support.swap_attr(sys, "argv", argv), \ test_support.swap_attr(sys, "stdin", StringIO(input)), \ test_support.captured_stdout() as output: try: runpy.run_path(script, run_name="__main__") except SystemExit as exit: self.assertEqual(exit.code, 0) return output.getvalue()
Example #8
Source File: test_mailbox.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_file_perms(self): # From bug #3228, we want to verify that the mailbox file isn't executable, # even if the umask is set to something that would leave executable bits set. # We only run this test on platforms that support umask. try: old_umask = os.umask(0077) self._box.close() os.unlink(self._path) self._box = mailbox.mbox(self._path, create=True) self._box.add('') self._box.close() finally: os.umask(old_umask) st = os.stat(self._path) perms = st.st_mode self.assertFalse((perms & 0111)) # Execute bits should all be off.
Example #9
Source File: test_fileinput.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_modes(self): with open(TESTFN, 'wb') as f: # UTF-7 is a convenient, seldom used encoding f.write('A\nB\r\nC\rD+IKw-') self.addCleanup(safe_unlink, TESTFN) def check(mode, expected_lines): fi = FileInput(files=TESTFN, mode=mode, openhook=hook_encoded('utf-7')) lines = list(fi) fi.close() self.assertEqual(lines, expected_lines) check('r', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac']) check('rU', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac']) check('U', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac']) check('rb', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac'])
Example #10
Source File: test_posixpath.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_realpath_deep_recursion(self): depth = 10 try: os.mkdir(ABSTFN) for i in range(depth): os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1)) os.symlink('.', ABSTFN + '/0') self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN) # Test using relative path as well. with support.change_cwd(ABSTFN): self.assertEqual(realpath('%d' % depth), ABSTFN) finally: for i in range(depth + 1): test_support.unlink(ABSTFN + '/%d' % i) safe_rmdir(ABSTFN)
Example #11
Source File: test_posixpath.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_realpath_resolve_parents(self): # We also need to resolve any symlinks in the parents of a relative # path passed to realpath. E.g.: current working directory is # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call # realpath("a"). This should return /usr/share/doc/a/. try: os.mkdir(ABSTFN) os.mkdir(ABSTFN + "/y") os.symlink(ABSTFN + "/y", ABSTFN + "/k") with support.change_cwd(ABSTFN + "/k"): self.assertEqual(realpath("a"), ABSTFN + "/y/a") finally: test_support.unlink(ABSTFN + "/k") safe_rmdir(ABSTFN + "/y") safe_rmdir(ABSTFN)
Example #12
Source File: test_posixpath.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_realpath_resolve_before_normalizing(self): # Bug #990669: Symbolic links should be resolved before we # normalize the path. E.g.: if we have directories 'a', 'k' and 'y' # in the following hierarchy: # a/k/y # # and a symbolic link 'link-y' pointing to 'y' in directory 'a', # then realpath("link-y/..") should return 'k', not 'a'. try: os.mkdir(ABSTFN) os.mkdir(ABSTFN + "/k") os.mkdir(ABSTFN + "/k/y") os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y") # Absolute path. self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k") # Relative path. with support.change_cwd(dirname(ABSTFN)): self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."), ABSTFN + "/k") finally: test_support.unlink(ABSTFN + "/link-y") safe_rmdir(ABSTFN + "/k/y") safe_rmdir(ABSTFN + "/k") safe_rmdir(ABSTFN)
Example #13
Source File: test_tarfile.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_init_close_fobj(self): # Issue #7341: Close the internal file object in the TarFile # constructor in case of an error. For the test we rely on # the fact that opening an empty file raises a ReadError. empty = os.path.join(TEMPDIR, "empty") with open(empty, "wb") as fobj: fobj.write("") try: tar = object.__new__(tarfile.TarFile) try: tar.__init__(empty) except tarfile.ReadError: self.assertTrue(tar.fileobj.closed) else: self.fail("ReadError not raised") finally: support.unlink(empty)
Example #14
Source File: test_dist.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_debug_mode(self): with open(TESTFN, "w") as f: f.write("[global]\n") f.write("command_packages = foo.bar, splat") self.addCleanup(unlink, TESTFN) files = [TESTFN] sys.argv.append("build") with captured_stdout() as stdout: self.create_distribution(files) stdout.seek(0) self.assertEqual(stdout.read(), '') distutils.dist.DEBUG = True try: with captured_stdout() as stdout: self.create_distribution(files) stdout.seek(0) self.assertEqual(stdout.read(), '') finally: distutils.dist.DEBUG = False
Example #15
Source File: test_dist.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_command_packages_configfile(self): sys.argv.append("build") self.addCleanup(os.unlink, TESTFN) f = open(TESTFN, "w") try: print >> f, "[global]" print >> f, "command_packages = foo.bar, splat" finally: f.close() d = self.create_distribution([TESTFN]) self.assertEqual(d.get_command_packages(), ["distutils.command", "foo.bar", "splat"]) # ensure command line overrides config: sys.argv[1:] = ["--command-packages", "spork", "build"] d = self.create_distribution([TESTFN]) self.assertEqual(d.get_command_packages(), ["distutils.command", "spork"]) # Setting --command-packages to '' should cause the default to # be used even if a config file specified something else: sys.argv[1:] = ["--command-packages", "", "build"] d = self.create_distribution([TESTFN]) self.assertEqual(d.get_command_packages(), ["distutils.command"])
Example #16
Source File: test_marshal.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_dict(self): new = marshal.loads(marshal.dumps(self.d)) self.assertEqual(self.d, new) marshal.dump(self.d, file(test_support.TESTFN, "wb")) new = marshal.load(file(test_support.TESTFN, "rb")) self.assertEqual(self.d, new) os.unlink(test_support.TESTFN)
Example #17
Source File: test_marshal.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_string(self): for s in ["", "Andr� Previn", "abc", " "*10000]: new = marshal.loads(marshal.dumps(s)) self.assertEqual(s, new) self.assertEqual(type(s), type(new)) marshal.dump(s, file(test_support.TESTFN, "wb")) new = marshal.load(file(test_support.TESTFN, "rb")) self.assertEqual(s, new) self.assertEqual(type(s), type(new)) os.unlink(test_support.TESTFN)
Example #18
Source File: test_xml_etree.py From ironpython2 with Apache License 2.0 | 5 votes |
def tearDown(self): support.unlink(TESTFN)
Example #19
Source File: test_uu.py From ironpython2 with Apache License 2.0 | 5 votes |
def setUp(self): self.tmpin = support.TESTFN + "i" self.tmpout = support.TESTFN + "o" self.addCleanup(support.unlink, self.tmpin) self.addCleanup(support.unlink, self.tmpout)
Example #20
Source File: test_marshal.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_ints(self): # Test the full range of Python ints. n = sys.maxint while n: for expected in (-n, n): s = marshal.dumps(expected) got = marshal.loads(s) self.assertEqual(expected, got) marshal.dump(expected, file(test_support.TESTFN, "wb")) got = marshal.load(file(test_support.TESTFN, "rb")) self.assertEqual(expected, got) n = n >> 1 os.unlink(test_support.TESTFN)
Example #21
Source File: test_shutil.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_make_zipfile(self): # creating something to zip root_dir, base_dir = self._create_files() tmpdir2 = self.mkdtemp() # force shutil to create the directory os.rmdir(tmpdir2) # working with relative paths work_dir = os.path.dirname(tmpdir2) rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive') with support.change_cwd(work_dir): base_name = os.path.abspath(rel_base_name) res = make_archive(rel_base_name, 'zip', root_dir) self.assertEqual(res, base_name + '.zip') self.assertTrue(os.path.isfile(res)) self.assertTrue(zipfile.is_zipfile(res)) with zipfile.ZipFile(res) as zf: self.assertEqual(sorted(zf.namelist()), ['dist/', 'dist/file1', 'dist/file2', 'dist/sub/', 'dist/sub/file3', 'dist/sub2/', 'outer']) support.unlink(res) with support.change_cwd(work_dir): base_name = os.path.abspath(rel_base_name) res = make_archive(rel_base_name, 'zip', root_dir, base_dir) self.assertEqual(res, base_name + '.zip') self.assertTrue(os.path.isfile(res)) self.assertTrue(zipfile.is_zipfile(res)) with zipfile.ZipFile(res) as zf: self.assertEqual(sorted(zf.namelist()), ['dist/', 'dist/file1', 'dist/file2', 'dist/sub/', 'dist/sub/file3', 'dist/sub2/'])
Example #22
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_lchown(self): os.unlink(test_support.TESTFN) # create a symlink os.symlink(_DUMMY_SYMLINK, test_support.TESTFN) self._test_all_chown_common(posix.lchown, test_support.TESTFN, getattr(posix, 'lstat', None))
Example #23
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_fchown(self): os.unlink(test_support.TESTFN) # re-create the file test_file = open(test_support.TESTFN, 'w') try: fd = test_file.fileno() self._test_all_chown_common(posix.fchown, fd, getattr(posix, 'fstat', None)) finally: test_file.close()
Example #24
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_chown(self): # raise an OSError if the file does not exist os.unlink(test_support.TESTFN) self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1) # re-create the file open(test_support.TESTFN, 'w').close() self._test_all_chown_common(posix.chown, test_support.TESTFN, getattr(posix, 'stat', None))
Example #25
Source File: test_set.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_print(self): fo = open(test_support.TESTFN, "wb") try: print >> fo, self.set, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(self.set)) finally: fo.close() test_support.unlink(test_support.TESTFN)
Example #26
Source File: test_set.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_cyclical_print(self): w = ReprWrapper() s = self.thetype([w]) w.value = s fo = open(test_support.TESTFN, "wb") try: print >> fo, s, fo.close() fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(s)) finally: fo.close() test_support.unlink(test_support.TESTFN)
Example #27
Source File: test_os.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_mkdir(self): f = open(test_support.TESTFN, "w") try: self.assertRaises(WindowsError, os.mkdir, test_support.TESTFN) finally: f.close() os.unlink(test_support.TESTFN)
Example #28
Source File: test_os.py From ironpython2 with Apache License 2.0 | 5 votes |
def tearDown(self): os.unlink(self.fname) os.rmdir(test_support.TESTFN)
Example #29
Source File: test_os.py From ironpython2 with Apache License 2.0 | 5 votes |
def setUp(self): if os.path.exists(test_support.TESTFN): os.unlink(test_support.TESTFN)
Example #30
Source File: test_marshal.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_tuple(self): t = tuple(self.d.keys()) new = marshal.loads(marshal.dumps(t)) self.assertEqual(t, new) marshal.dump(t, file(test_support.TESTFN, "wb")) new = marshal.load(file(test_support.TESTFN, "rb")) self.assertEqual(t, new) os.unlink(test_support.TESTFN)