Python test.support.unlink() Examples
The following are 30
code examples of 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.support
, or try the search function
.
Example #1
Source File: test_regrtest.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_fromfile(self): # test --fromfile tests = [self.create_test() for index in range(5)] # Write the list of files using a format similar to regrtest output: # [1/2] test_1 # [2/2] test_2 filename = support.TESTFN self.addCleanup(support.unlink, filename) # test format 'test_opcodes' with open(filename, "w") as fp: for name in tests: print(name, file=fp) output = self.run_tests('--fromfile', filename) self.check_executed_tests(output, tests)
Example #2
Source File: test_posixpath.py From Fluid-Designer with GNU General Public License v3.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: support.unlink(ABSTFN + "/k") safe_rmdir(ABSTFN + "/y") safe_rmdir(ABSTFN)
Example #3
Source File: test_posixpath.py From Fluid-Designer with GNU General Public License v3.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: support.unlink(ABSTFN + "/link-y") safe_rmdir(ABSTFN + "/k/y") safe_rmdir(ABSTFN + "/k") safe_rmdir(ABSTFN)
Example #4
Source File: test_posixpath.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_realpath_resolve_first(self): # Bug #1213894: The first component of the path, if not absolute, # must be resolved too. try: os.mkdir(ABSTFN) os.mkdir(ABSTFN + "/k") os.symlink(ABSTFN, ABSTFN + "link") with support.change_cwd(dirname(ABSTFN)): base = basename(ABSTFN) self.assertEqual(realpath(base + "link"), ABSTFN) self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k") finally: support.unlink(ABSTFN + "link") safe_rmdir(ABSTFN + "/k") safe_rmdir(ABSTFN)
Example #5
Source File: test_support.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_forget(self): mod_filename = TESTFN + '.py' with open(mod_filename, 'w') as f: print('foo = 1', file=f) sys.path.insert(0, os.curdir) importlib.invalidate_caches() 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__')
Example #6
Source File: test_tracemalloc.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_snapshot(self): obj, source = allocate_bytes(123) # take a snapshot snapshot = tracemalloc.take_snapshot() # write on disk snapshot.dump(support.TESTFN) self.addCleanup(support.unlink, support.TESTFN) # load from disk snapshot2 = tracemalloc.Snapshot.load(support.TESTFN) self.assertEqual(snapshot2.traces, snapshot.traces) # tracemalloc must be tracing memory allocations to take a snapshot tracemalloc.stop() with self.assertRaises(RuntimeError) as cm: tracemalloc.take_snapshot() self.assertEqual(str(cm.exception), "the tracemalloc module must be tracing memory " "allocations to take a snapshot")
Example #7
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_large_fd_transfer(self): # With fd > 256 (issue #11657) if self.TYPE != 'processes': self.skipTest("only makes sense with processes") conn, child_conn = self.Pipe(duplex=True) p = self.Process(target=self._writefd, args=(child_conn, b"bar", True)) p.daemon = True p.start() self.addCleanup(support.unlink, support.TESTFN) with open(support.TESTFN, "wb") as f: fd = f.fileno() for newfd in range(256, MAXFD): if not self._is_fd_assigned(newfd): break else: self.fail("could not find an unassigned large file descriptor") os.dup2(fd, newfd) try: reduction.send_handle(conn, newfd, p.pid) finally: os.close(newfd) p.join() with open(support.TESTFN, "rb") as f: self.assertEqual(f.read(), b"bar")
Example #8
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_fd_transfer(self): if self.TYPE != 'processes': self.skipTest("only makes sense with processes") conn, child_conn = self.Pipe(duplex=True) p = self.Process(target=self._writefd, args=(child_conn, b"foo")) p.daemon = True p.start() self.addCleanup(support.unlink, support.TESTFN) with open(support.TESTFN, "wb") as f: fd = f.fileno() if msvcrt: fd = msvcrt.get_osfhandle(fd) reduction.send_handle(conn, fd, p.pid) p.join() with open(support.TESTFN, "rb") as f: self.assertEqual(f.read(), b"foo")
Example #9
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_sys_exit(self): # See Issue 13854 if self.TYPE == 'threads': self.skipTest('test not appropriate for {}'.format(self.TYPE)) testfn = support.TESTFN self.addCleanup(support.unlink, testfn) for reason, code in (([1, 2, 3], 1), ('ignore this', 1)): p = self.Process(target=self._test_sys_exit, args=(reason, testfn)) p.daemon = True p.start() p.join(5) self.assertEqual(p.exitcode, code) with open(testfn, 'r') as f: self.assertEqual(f.read().rstrip(), str(reason)) for reason in (True, False, 8): p = self.Process(target=sys.exit, args=(reason,)) p.daemon = True p.start() p.join(5) self.assertEqual(p.exitcode, reason)
Example #10
Source File: test_contextlib.py From Fluid-Designer with GNU General Public License v3.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: support.unlink(tfn)
Example #11
Source File: test_ssl.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_sendfile(self): TEST_DATA = b"x" * 512 with open(support.TESTFN, 'wb') as f: f.write(TEST_DATA) self.addCleanup(support.unlink, support.TESTFN) context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.verify_mode = ssl.CERT_REQUIRED context.load_verify_locations(CERTFILE) context.load_cert_chain(CERTFILE) server = ThreadedEchoServer(context=context, chatty=False) with server: with context.wrap_socket(socket.socket()) as s: s.connect((HOST, server.port)) with open(support.TESTFN, 'rb') as file: s.sendfile(file) self.assertEqual(s.recv(1024), TEST_DATA)
Example #12
Source File: test_tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: tar.extract("ustar/regtype", TEMPDIR) self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/regtype")) tar.extract("ustar/lnktype", TEMPDIR) self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/lnktype")) with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) tar.extract("ustar/symtype", TEMPDIR) self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/symtype")) with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype)
Example #13
Source File: test_tarfile.py From Fluid-Designer with GNU General Public License v3.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(b"") 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_tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_link_size(self): link = os.path.join(TEMPDIR, "link") target = os.path.join(TEMPDIR, "link_target") with open(target, "wb") as fobj: fobj.write(b"aaa") os.link(target, link) try: tar = tarfile.open(tmpname, self.mode) try: # Record the link target in the inodes list. tar.gettarinfo(target) tarinfo = tar.gettarinfo(link) self.assertEqual(tarinfo.size, 0) finally: tar.close() finally: support.unlink(target) support.unlink(link)
Example #15
Source File: eintr_tester.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _test_open(self, do_open_close_reader, do_open_close_writer): filename = support.TESTFN # Use a fifo: until the child opens it for reading, the parent will # block when trying to open it for writing. support.unlink(filename) os.mkfifo(filename) self.addCleanup(support.unlink, filename) code = '\n'.join(( 'import os, time', '', 'path = %a' % filename, 'sleep_time = %r' % self.sleep_time, '', '# let the parent block', 'time.sleep(sleep_time)', '', do_open_close_reader, )) proc = self.subprocess(code) with kill_on_error(proc): do_open_close_writer(filename) self.assertEqual(proc.wait(), 0)
Example #16
Source File: test_gzip.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def tearDown(self): support.unlink(self.filename)
Example #17
Source File: test_gzip.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_binary_modes(self): uncompressed = data1 * 50 with gzip.open(self.filename, "wb") as f: f.write(uncompressed) with open(self.filename, "rb") as f: file_data = gzip.decompress(f.read()) self.assertEqual(file_data, uncompressed) with gzip.open(self.filename, "rb") as f: self.assertEqual(f.read(), uncompressed) with gzip.open(self.filename, "ab") as f: f.write(uncompressed) with open(self.filename, "rb") as f: file_data = gzip.decompress(f.read()) self.assertEqual(file_data, uncompressed * 2) with self.assertRaises(FileExistsError): gzip.open(self.filename, "xb") support.unlink(self.filename) with gzip.open(self.filename, "xb") as f: f.write(uncompressed) with open(self.filename, "rb") as f: file_data = gzip.decompress(f.read()) self.assertEqual(file_data, uncompressed)
Example #18
Source File: test_gzip.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_mode(self): self.test_write() with gzip.GzipFile(self.filename, 'r') as f: self.assertEqual(f.myfileobj.mode, 'rb') support.unlink(self.filename) with gzip.GzipFile(self.filename, 'x') as f: self.assertEqual(f.myfileobj.mode, 'xb')
Example #19
Source File: test_tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_symlink_size(self): path = os.path.join(TEMPDIR, "symlink") os.symlink("link_target", path) try: tar = tarfile.open(tmpname, self.mode) try: tarinfo = tar.gettarinfo(path) self.assertEqual(tarinfo.size, 0) finally: tar.close() finally: support.unlink(path)
Example #20
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def tearDown(self): try: os.unlink(support.TESTFN) except: pass
Example #21
Source File: test_tracemalloc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_snapshot_save_attr(self): # take a snapshot with a new attribute snapshot = tracemalloc.take_snapshot() snapshot.test_attr = "new" snapshot.dump(support.TESTFN) self.addCleanup(support.unlink, support.TESTFN) # load() should recreates the attribute snapshot2 = tracemalloc.Snapshot.load(support.TESTFN) self.assertEqual(snapshot2.test_attr, "new")
Example #22
Source File: test_posixpath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_realpath_relative(self): try: os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN) self.assertEqual(realpath(ABSTFN), ABSTFN+"1") finally: support.unlink(ABSTFN)
Example #23
Source File: test_gzip.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def setUp(self): support.unlink(self.filename)
Example #24
Source File: test_pathlib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_rmdir(self): p = self.cls(BASE) / 'dirA' for q in p.iterdir(): q.unlink() p.rmdir() self.assertFileNotFound(p.stat) self.assertFileNotFound(p.unlink)
Example #25
Source File: test_pathlib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def symlink_skip_reason(): if not pathlib.supports_symlinks: return "no system support for symlinks" try: os.symlink(__file__, BASE) except OSError as e: return str(e) else: support.unlink(BASE) return None
Example #26
Source File: test_urllibnet.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def urlretrieve(self, *args, **kwargs): resource = args[0] with support.transient_internet(resource): file_location, info = urllib.request.urlretrieve(*args, **kwargs) try: yield file_location, info finally: support.unlink(file_location)
Example #27
Source File: test_support.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_unlink(self): with open(TESTFN, "w") as f: pass support.unlink(TESTFN) self.assertFalse(os.path.exists(TESTFN)) support.unlink(TESTFN)
Example #28
Source File: test_support.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def setUp(self): support.unlink(TESTFN) support.rmtree(TESTDIRN)
Example #29
Source File: test_shelve.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def tearDown(self): for db in self._db: db.close() self._db = [] if not self._in_mem: for f in glob.glob(self.fn+"*"): support.unlink(f)
Example #30
Source File: test_shelve.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def tearDown(self): for f in glob.glob(self.fn+"*"): support.unlink(f)