Lines Matching defs:path

10 import os.path
59 # Pretend the destination path is on a different filesystem.
73 def write_file(path, content, binary=False):
74 """Write *content* to a file located at *path*.
76 If *path* is a tuple instead of a string, os.path.join will be used to
77 make a path. If *binary* is true, the file will be opened in binary
80 if isinstance(path, tuple):
81 path = os.path.join(*path)
84 with open(path, mode, encoding=encoding) as fp:
87 def write_test_file(path, size):
100 with open(path, 'wb') as f:
103 assert os.path.getsize(path) == size
105 def read_file(path, binary=False):
106 """Return contents from a file located at *path*.
108 If *path* is a tuple instead of a string, os.path.join will be used to
109 make a path. If *binary* is true, the file will be opened in binary
112 if isinstance(path, tuple):
113 path = os.path.join(*path)
116 with open(path, mode, encoding=encoding) as fp:
119 def rlistdir(path):
121 for name in sorted(os.listdir(path)):
122 p = os.path.join(path, name)
123 if os.path.isdir(p) and not os.path.islink(p):
180 Returns the path of the directory.
191 victim = os.path.join(tmp, 'killme')
193 write_file(os.path.join(victim, 'somefile'), 'foo')
201 dir_ = os.path.join(tmp, 'dir')
203 link = os.path.join(tmp, 'link')
206 self.assertTrue(os.path.exists(dir_))
207 self.assertTrue(os.path.lexists(link))
213 self.assertIs(errors[0][0], os.path.islink)
220 dir1 = os.path.join(tmp, 'dir1')
221 dir2 = os.path.join(dir1, 'dir2')
222 dir3 = os.path.join(tmp, 'dir3')
225 file1 = os.path.join(tmp, 'file1')
227 link1 = os.path.join(dir1, 'link1')
229 link2 = os.path.join(dir1, 'link2')
231 link3 = os.path.join(dir1, 'link3')
235 self.assertFalse(os.path.exists(dir1))
236 self.assertTrue(os.path.exists(dir3))
237 self.assertTrue(os.path.exists(file1))
242 dir_ = os.path.join(tmp, 'dir')
244 link = os.path.join(tmp, 'link')
248 self.assertTrue(os.path.exists(dir_))
249 self.assertTrue(os.path.lexists(link))
255 self.assertIs(errors[0][0], os.path.islink)
262 dir1 = os.path.join(tmp, 'dir1')
263 dir2 = os.path.join(dir1, 'dir2')
264 dir3 = os.path.join(tmp, 'dir3')
267 file1 = os.path.join(tmp, 'file1')
269 link1 = os.path.join(dir1, 'link1')
271 link2 = os.path.join(dir1, 'link2')
273 link3 = os.path.join(dir1, 'link3')
277 self.assertFalse(os.path.exists(dir1))
278 self.assertTrue(os.path.exists(dir3))
279 self.assertTrue(os.path.exists(file1))
291 filename = os.path.join(tmpdir, "tstfile")
295 self.assertTrue(os.path.exists(filename))
298 self.assertTrue(os.path.exists(filename))
323 self.child_file_path = os.path.join(TESTFN, 'a')
324 self.child_dir_path = os.path.join(TESTFN, 'b')
397 d = os.path.join(tmp_dir, 'a')
416 fullname = os.path.join(tmp_dir, victim)
420 os.mkdir(os.path.join(fullname, 'subdir'))
421 write_file(os.path.join(fullname, 'subdir', 'somefile'), 'foo')
422 self.assertTrue(os.path.exists(fullname))
424 self.assertFalse(os.path.exists(fullname))
431 self.assertTrue(os.path.exists(tmp_dir))
435 handle, path = tempfile.mkstemp(dir=self.mkdtemp())
437 self.assertRaises(NotADirectoryError, shutil.rmtree, path)
438 os.remove(path)
445 src = os.path.join(TESTFN, 'cheese')
446 dst = os.path.join(TESTFN, 'shop')
458 src = os.path.join(TESTFN, 'cheese')
459 dst = os.path.join(TESTFN, 'shop')
461 open(os.path.join(src, 'spam'), 'wb').close()
473 dst_dir = os.path.join(self.mkdtemp(), 'destination')
475 self.addCleanup(shutil.rmtree, os.path.dirname(dst_dir))
477 os.mkdir(os.path.join(src_dir, 'test_dir'))
481 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test.txt')))
482 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'test_dir')))
483 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test_dir',
497 os.mkdir(os.path.join(src_dir, 'existing_dir'))
498 os.mkdir(os.path.join(dst_dir, 'existing_dir'))
503 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'nonexisting.txt')))
504 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'existing_dir')))
505 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'existing_dir',
518 src_dir = os.path.join(tmp_dir, 'src')
519 dst_dir = os.path.join(tmp_dir, 'dst')
520 sub_dir = os.path.join(src_dir, 'sub')
524 src_link = os.path.join(sub_dir, 'link')
525 dst_link = os.path.join(dst_dir, 'sub/link')
526 os.symlink(os.path.join(src_dir, 'file.txt'),
534 self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link')))
535 actual = os.readlink(os.path.join(dst_dir, 'sub', 'link'))
540 self.assertEqual(actual, os.path.join(src_dir, 'file.txt'))
549 join = os.path.join
550 exists = os.path.exists
590 path = os.path.join(src, name)
592 if (os.path.isdir(path) and
593 path.split()[-1] == 'subdir'):
595 elif os.path.splitext(path)[-1] in ('.py'):
610 shutil.rmtree(os.path.dirname(dst_dir))
613 join = os.path.join
614 exists = os.path.exists
621 os.mkdir(os.path.join(src_dir, 'test_dir', 'subdir'))
656 src_dir = os.path.join(tmp_dir, 'source')
658 dst_dir = os.path.join(tmp_dir, 'destination')
663 os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
665 os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
672 self.assertEqual(os.stat(os.path.join(src_dir, 'permissive.txt')).st_mode,
673 os.stat(os.path.join(dst_dir, 'permissive.txt')).st_mode)
674 self.assertEqual(os.stat(os.path.join(src_dir, 'restrictive.txt')).st_mode,
675 os.stat(os.path.join(dst_dir, 'restrictive.txt')).st_mode)
676 restrictive_subdir_dst = os.path.join(dst_dir,
677 os.path.split(restrictive_subdir)[1])
687 dst_dir = os.path.join(self.mkdtemp(), 'destination')
689 self.addCleanup(shutil.rmtree, os.path.dirname(dst_dir))
701 self.assertEqual(a, os.path.join(src, 'foo'))
702 self.assertEqual(b, os.path.join(dst, 'foo'))
707 with open(os.path.join(src, 'foo'), 'w', encoding='utf-8') as f:
716 "fifo requires special path on VxWorks")
720 subdir = os.path.join(TESTFN, "subdir")
722 pipe = os.path.join(subdir, "mypipe")
742 dst_dir = os.path.join(self.mkdtemp(), 'destination')
744 os.mkdir(os.path.join(src_dir, 'test_dir'))
757 valid_file = os.path.join(src_dir, 'test.txt')
759 dir_a = os.path.join(src_dir, 'dir_a')
762 os.symlink('IDONTEXIST', os.path.join(d, 'broken'))
763 os.symlink(valid_file, os.path.join(d, 'valid'))
766 dst_dir = os.path.join(self.mkdtemp(), 'destination')
770 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
777 dst_dir = os.path.join(self.mkdtemp(), 'destination3')
784 dst_dir = os.path.join(self.mkdtemp(), 'destination')
785 os.mkdir(os.path.join(src_dir, 'real_dir'))
786 with open(os.path.join(src_dir, 'real_dir', 'test.txt'), 'wb'):
788 os.symlink(os.path.join(src_dir, 'real_dir'),
789 os.path.join(src_dir, 'link_to_dir'),
793 self.assertFalse(os.path.islink(os.path.join(dst_dir, 'link_to_dir')))
794 self.assertIn('test.txt', os.listdir(os.path.join(dst_dir, 'link_to_dir')))
796 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
798 self.assertTrue(os.path.islink(os.path.join(dst_dir, 'link_to_dir')))
799 self.assertIn('test.txt', os.listdir(os.path.join(dst_dir, 'link_to_dir')))
802 # copytree returns its destination path.
806 src = os.path.join(src_dir, 'foo')
815 src_dir = os.path.join(base_dir, "t", "pg")
816 dst_dir = os.path.join(src_dir, "somevendor", "1.0")
818 src = os.path.join(src_dir, 'pol')
830 src = os.path.join(tmp_dir, 'foo')
831 dst = os.path.join(tmp_dir, 'bar')
832 src_link = os.path.join(tmp_dir, 'baz')
833 dst_link = os.path.join(tmp_dir, 'quux')
863 src = os.path.join(tmp_dir, 'foo')
864 dst = os.path.join(tmp_dir, 'bar')
865 src_link = os.path.join(tmp_dir, 'baz')
866 dst_link = os.path.join(tmp_dir, 'quux')
893 src = os.path.join(tmp_dir, 'foo')
894 dst = os.path.join(tmp_dir, 'bar')
895 src_link = os.path.join(tmp_dir, 'baz')
896 dst_link = os.path.join(tmp_dir, 'quux')
908 src = os.path.join(tmp_dir, 'foo')
909 dst = os.path.join(tmp_dir, 'bar')
910 src_link = os.path.join(tmp_dir, 'baz')
911 dst_link = os.path.join(tmp_dir, 'qux')
952 file1 = os.path.join(tmpdir, 'file1')
953 file2 = os.path.join(tmpdir, 'file2')
960 def _chflags_raiser(path, flags, *, follow_symlinks=True):
980 src = os.path.join(tmp_dir, 'foo')
982 dst = os.path.join(tmp_dir, 'bar')
1025 src = os.path.join(tmp_dir, 'the_original')
1026 srcro = os.path.join(tmp_dir, 'the_original_ro')
1032 dst = os.path.join(tmp_dir, 'the_copy')
1033 dstro = os.path.join(tmp_dir, 'the_copy_ro')
1049 src = os.path.join(tmp_dir, 'foo')
1050 src_link = os.path.join(tmp_dir, 'baz')
1055 dst = os.path.join(tmp_dir, 'bar')
1056 dst_link = os.path.join(tmp_dir, 'qux')
1071 file1 = os.path.join(tmpdir, fname)
1074 file2 = os.path.join(tmpdir2, fname)
1080 self.assertTrue(os.path.exists(file2))
1086 src = os.path.join(tmp_dir, 'foo')
1087 dst = os.path.join(tmp_dir, 'bar')
1088 src_link = os.path.join(tmp_dir, 'baz')
1095 self.assertFalse(os.path.islink(dst))
1100 self.assertTrue(os.path.islink(dst))
1113 self.assertTrue(os.path.exists(file2))
1128 src = os.path.join(tmp_dir, 'foo')
1129 dst = os.path.join(tmp_dir, 'bar')
1130 src_link = os.path.join(tmp_dir, 'baz')
1141 self.assertFalse(os.path.islink(dst))
1146 self.assertTrue(os.path.islink(dst))
1163 src = os.path.join(tmp_dir, 'foo')
1164 dst = os.path.join(tmp_dir, 'bar')
1174 # copy and copy2 both return their destination path.
1178 src = os.path.join(src_dir, 'foo')
1181 self.assertEqual(rv, os.path.join(dst_dir, 'foo'))
1182 rv = fn(src, os.path.join(dst_dir, 'bar'))
1183 self.assertEqual(rv, os.path.join(dst_dir, 'bar'))
1193 src_file = os.path.join(src_dir, 'foo')
1195 dst = os.path.join(src_dir, 'does_not_exist/')
1212 src = os.path.join(tmp_dir, 'src')
1213 dst = os.path.join(tmp_dir, 'dst')
1214 dst_link = os.path.join(tmp_dir, 'dst_link')
1215 link = os.path.join(tmp_dir, 'link')
1220 self.assertTrue(os.path.islink(dst_link))
1224 self.assertFalse(os.path.islink(dst))
1230 src = os.path.join(TESTFN, 'cheese')
1231 dst = os.path.join(TESTFN, 'shop')
1250 src = os.path.join(TESTFN, 'cheese')
1251 dst = os.path.join(TESTFN, 'shop')
1269 "fifo requires special path on VxWorks")
1284 # copytree returns its destination path.
1287 dst_file = os.path.join(dst_dir, 'bar')
1288 src_file = os.path.join(src_dir, 'foo')
1291 self.assertTrue(os.path.exists(rv))
1298 src_file = os.path.join(src_dir, 'foo')
1308 # the path as a directory, but on AIX the trailing slash has no effect
1314 src_file = os.path.join(src_dir, 'foo')
1315 dst = os.path.join(src_dir, 'does_not_exist/')
1324 src_file = os.path.join(src_dir, 'foo')
1326 dst = os.path.join(src_dir, 'does_not_exist/')
1351 work_dir = os.path.dirname(tmpdir2)
1352 rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
1355 base_name = os.path.abspath(rel_base_name)
1360 self.assertTrue(os.path.isfile(tarball))
1371 self.assertTrue(os.path.isfile(tarball))
1378 def _tarinfo(self, path):
1379 with tarfile.open(path) as tar:
1387 dist = os.path.join(root_dir, base_dir)
1391 os.mkdir(os.path.join(dist, 'sub'))
1393 os.mkdir(os.path.join(dist, 'sub2'))
1403 base_name = os.path.join(self.mkdtemp(), 'archive')
1409 self.assertTrue(os.path.isfile(tarball))
1412 tarball2 = os.path.join(root_dir, 'archive2.tar')
1417 self.assertTrue(os.path.isfile(tarball2))
1425 self.assertTrue(os.path.isfile(tarball))
1432 self.assertTrue(os.path.isfile(tarball))
1443 work_dir = os.path.dirname(tmpdir2)
1444 rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
1447 base_name = os.path.abspath(rel_base_name)
1451 self.assertTrue(os.path.isfile(res))
1460 base_name = os.path.abspath(rel_base_name)
1464 self.assertTrue(os.path.isfile(res))
1476 base_name = os.path.join(self.mkdtemp(), 'archive')
1482 self.assertTrue(os.path.isfile(archive))
1485 archive2 = os.path.join(root_dir, 'archive2.zip')
1490 self.assertTrue(os.path.isfile(archive2))
1503 base_name = os.path.join(self.mkdtemp(), 'archive')
1509 self.assertTrue(os.path.isfile(archive))
1525 base_name = os.path.join(tmpdir, 'archive')
1539 base_name = os.path.join(self.mkdtemp(), 'archive')
1542 self.assertTrue(os.path.isfile(res))
1545 self.assertTrue(os.path.isfile(res))
1549 self.assertTrue(os.path.isfile(res))
1553 self.assertTrue(os.path.isfile(res))
1560 base_name = os.path.join(self.mkdtemp(), 'archive')
1568 self.assertTrue(os.path.isfile(archive_name))
1585 def _chdir(path):
1586 dirs.append(path)
1587 orig_chdir(path)
1606 self.assertTrue(os.path.isfile('test.tar'))
1614 self.assertTrue(os.path.isfile('test.zip'))
1636 format, lambda path: path, **kwargs)
1646 base_name = os.path.join(self.mkdtemp(), 'archive')
1725 usage = shutil.disk_usage(os.path.dirname(__file__))
1762 def check_chown(path, uid=None, gid=None):
1811 self.dir, self.file = os.path.split(self.temp_file.name)
1818 rv = shutil.which(self.file, path=self.dir)
1822 # When given the fully qualified path to an executable that exists,
1824 rv = shutil.which(self.temp_file.name, path=self.temp_dir)
1828 # When given the relative path with a directory part to an executable
1830 base_dir, tail_dir = os.path.split(self.dir)
1831 relpath = os.path.join(tail_dir, self.file)
1832 with os_helper.change_cwd(path=base_dir):
1833 rv = shutil.which(relpath, path=self.temp_dir)
1836 with os_helper.change_cwd(path=self.dir):
1837 rv = shutil.which(relpath, path=base_dir)
1842 base_dir = os.path.dirname(self.dir)
1843 with os_helper.change_cwd(path=self.dir):
1844 rv = shutil.which(self.file, path=base_dir)
1847 self.assertEqual(rv, os.path.join(self.curdir, self.file))
1858 rv = shutil.which(self.file, path=self.dir, mode=os.W_OK)
1862 base_dir, tail_dir = os.path.split(self.dir)
1863 with os_helper.change_cwd(path=base_dir):
1864 rv = shutil.which(self.file, path=tail_dir)
1865 self.assertEqual(rv, os.path.join(tail_dir, self.file))
1868 # Return None when no matching executable file is found on the path.
1869 rv = shutil.which("foo.exe", path=self.dir)
1877 rv = shutil.which(self.file[:-4], path=self.dir)
1898 expected_cwd = os.path.basename(self.temp_file.name)
1903 expected_cwd = os.path.join(curdir, expected_cwd)
1938 base_dir = os.path.dirname(self.dir)
1939 with os_helper.change_cwd(path=self.dir), \
1942 rv = shutil.which(self.file, path='')
1959 # strip path and extension
1960 program = os.path.basename(temp_filexyz.name)
1961 program = os.path.splitext(program)[0]
1965 rv = shutil.which(program, path=self.temp_dir)
1976 # strip path and extension
1977 program = os.path.basename(temp_filexyz.name)
1978 program = os.path.splitext(program)[0]
1982 rv = shutil.which(program, path=self.temp_dir)
2002 self.src_file = os.path.join(self.src_dir, filename)
2003 self.dst_file = os.path.join(self.dst_dir, filename)
2013 self.assertFalse(os.path.exists(src))
2019 self.assertFalse(os.path.exists(src))
2065 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
2073 self._check_move_dir(self.src_dir + os.path.sep, self.dst_dir,
2074 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
2076 @unittest.skipUnless(os.path.altsep, 'requires os.path.altsep')
2078 self._check_move_dir(self.src_dir + os.path.altsep, self.dst_dir,
2079 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
2089 dst = os.path.join(self.src_dir, "bar")
2096 src = os.path.join(TESTFN, src)
2097 dst = os.path.join(TESTFN, dst)
2108 src = os.path.join(TESTFN, src)
2109 dst = os.path.join(TESTFN, dst)
2119 dst = os.path.join(self.src_dir, 'bar')
2122 self.assertTrue(os.path.islink(self.dst_file))
2123 self.assertTrue(os.path.samefile(self.src_file, self.dst_file))
2129 dst = os.path.join(self.src_dir, filename)
2132 final_link = os.path.join(self.dst_dir, filename)
2133 self.assertTrue(os.path.islink(final_link))
2134 self.assertTrue(os.path.samefile(self.src_file, final_link))
2139 src = os.path.join(self.src_dir, 'baz')
2140 dst = os.path.join(self.src_dir, 'bar')
2142 dst_link = os.path.join(self.dst_dir, 'quux')
2144 self.assertTrue(os.path.islink(dst_link))
2145 self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
2150 src = os.path.join(self.src_dir, 'baz')
2151 dst = os.path.join(self.src_dir, 'bar')
2154 dst_link = os.path.join(self.dst_dir, 'quux')
2156 self.assertTrue(os.path.islink(dst_link))
2157 self.assertTrue(os.path.samefile(src, dst_link))
2162 os.path.join(self.dst_dir, os.path.basename(self.src_file)))
2165 rv = shutil.move(self.src_file, os.path.join(self.dst_dir, 'bar'))
2166 self.assertEqual(rv, os.path.join(self.dst_dir, 'bar'))
2181 os_helper.create_empty_file(os.path.join(self.src_dir, 'child'))
2182 os_helper.create_empty_file(os.path.join(self.src_dir, 'child1'))
2191 dst_dir = os.path.join(
2192 os.path.dirname(self.src_dir),
2193 os.path.basename(self.src_dir).upper())
2198 self.assertTrue(os.path.isdir(dst_dir))
2222 os_helper.create_empty_file(os.path.join(TESTFN_SRC, 'child'))
2230 if os.path.exists(TESTFN_SRC):
2233 if os.path.exists(TESTFN_DST):
2591 self.assertEqual(blocksize, os.path.getsize(TESTFN))