Lines Matching full:os
9 import os
10 import os.path
55 no_chdir = unittest.mock.patch('os.chdir',
56 side_effect=AssertionError("shouldn't call os.chdir()"))
66 builtin_rename = os.rename
67 os.rename = _fake_rename
70 os.rename = builtin_rename
76 If *path* is a tuple instead of a string, os.path.join will be used to
81 path = os.path.join(*path)
103 assert os.path.getsize(path) == size
108 If *path* is a tuple instead of a string, os.path.join will be used to
113 path = os.path.join(*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):
133 if not hasattr(os, "sendfile"):
138 with tempfile.NamedTemporaryFile("wb", dir=os.getcwd(), delete=False) as f:
143 with tempfile.NamedTemporaryFile("wb", dir=os.getcwd(), delete=False) as dst:
148 os.sendfile(outfd, infd, 0, 2)
182 d = tempfile.mkdtemp(prefix=prefix, dir=os.getcwd())
191 victim = os.path.join(tmp, 'killme')
192 os.mkdir(victim)
193 write_file(os.path.join(victim, 'somefile'), 'foo')
194 victim = os.fsencode(victim)
201 dir_ = os.path.join(tmp, 'dir')
202 os.mkdir(dir_)
203 link = os.path.join(tmp, 'link')
204 os.symlink(dir_, 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')
224 os.mkdir(d)
225 file1 = os.path.join(tmp, 'file1')
227 link1 = os.path.join(dir1, 'link1')
228 os.symlink(dir2, link1)
229 link2 = os.path.join(dir1, 'link2')
230 os.symlink(dir3, link2)
231 link3 = os.path.join(dir1, 'link3')
232 os.symlink(file1, 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')
243 os.mkdir(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')
266 os.mkdir(d)
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))
304 self.assertIs(errors[0][0], os.scandir)
308 self.assertIs(errors[1][0], os.rmdir)
320 os.mkdir(TESTFN)
323 self.child_file_path = os.path.join(TESTFN, 'a')
324 self.child_dir_path = os.path.join(TESTFN, 'b')
326 os.mkdir(self.child_dir_path)
327 old_dir_mode = os.stat(TESTFN).st_mode
328 old_child_file_mode = os.stat(self.child_file_path).st_mode
329 old_child_dir_mode = os.stat(self.child_dir_path).st_mode
332 os.chmod(self.child_file_path, new_mode)
333 os.chmod(self.child_dir_path, new_mode)
334 os.chmod(TESTFN, new_mode)
336 self.addCleanup(os.chmod, TESTFN, old_dir_mode)
337 self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
338 self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
351 # func is os.remove.
354 # at os.listdir. The first failure may legally
357 if func is os.unlink:
359 elif func is os.rmdir:
362 self.assertIs(func, os.listdir)
367 self.assertEqual(func, os.rmdir)
374 orig_lstat = os.lstat
380 os.lstat = raiser
382 os.mkdir(TESTFN)
386 os.lstat = orig_lstat
389 _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
390 os.supports_dir_fd and
391 os.listdir in os.supports_fd and
392 os.stat in os.supports_follow_symlinks)
397 d = os.path.join(tmp_dir, 'a')
398 os.mkdir(d)
416 fullname = os.path.join(tmp_dir, victim)
417 dir_fd = os.open(tmp_dir, os.O_RDONLY)
418 self.addCleanup(os.close, dir_fd)
419 os.mkdir(fullname)
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))
436 os.close(handle)
438 os.remove(path)
443 os.mkdir(TESTFN)
445 src = os.path.join(TESTFN, 'cheese')
446 dst = os.path.join(TESTFN, 'shop')
447 os.mkdir(src)
448 os.symlink(src, dst)
456 os.mkdir(TESTFN)
458 src = os.path.join(TESTFN, 'cheese')
459 dst = os.path.join(TESTFN, 'shop')
460 os.mkdir(src)
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')
521 os.mkdir(src_dir)
522 os.mkdir(sub_dir)
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'),
528 if hasattr(os, 'lchmod'):
529 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
530 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
531 os.lchflags(src_link, stat.UF_NODUMP)
532 src_stat = os.lstat(src_link)
534 self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link')))
535 actual = os.readlink(os.path.join(dst_dir, 'sub', 'link'))
538 if os.name == 'nt' and actual.startswith('\\\\?\\'):
540 self.assertEqual(actual, os.path.join(src_dir, 'file.txt'))
541 dst_stat = os.lstat(dst_link)
542 if hasattr(os, 'lchmod'):
544 if hasattr(os, 'lchflags'):
549 join = os.path.join
550 exists = os.path.exists
556 os.mkdir(join(src_dir, 'test_dir'))
558 os.mkdir(join(src_dir, 'test_dir2'))
560 os.mkdir(join(src_dir, 'test_dir2', 'subdir'))
561 os.mkdir(join(src_dir, 'test_dir2', 'subdir2'))
590 path = os.path.join(src, name)
592 if (os.path.isdir(path) and
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
619 os.mkdir(join(src_dir))
620 os.mkdir(join(src_dir, 'test_dir'))
621 os.mkdir(os.path.join(src_dir, 'test_dir', 'subdir'))
646 src_dir_entry = list(os.scandir(tmp_dir))[0]
647 self.assertIsInstance(src_dir_entry, os.DirEntry)
656 src_dir = os.path.join(tmp_dir, 'source')
657 os.mkdir(src_dir)
658 dst_dir = os.path.join(tmp_dir, 'destination')
661 os.chmod(src_dir, 0o777)
663 os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
665 os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
668 os.chmod(restrictive_subdir, 0o600)
671 self.assertEqual(os.stat(src_dir).st_mode, os.stat(dst_dir).st_mode)
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])
678 self.assertEqual(os.stat(restrictive_subdir).st_mode,
679 os.stat(restrictive_subdir_dst).st_mode)
681 @unittest.mock.patch('os.chmod')
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:
713 @unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
718 os.mkdir(TESTFN)
720 subdir = os.path.join(TESTFN, "subdir")
721 os.mkdir(subdir)
722 pipe = os.path.join(subdir, "mypipe")
724 os.mkfifo(pipe)
726 self.skipTest('os.mkfifo(): %s' % e)
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')
760 os.mkdir(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')
772 for root, dirs, files in os.walk(dst_dir):
777 dst_dir = os.path.join(self.mkdtemp(), 'destination3')
779 self.assertIn('test.txt', os.listdir(dst_dir))
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')))
806 src = os.path.join(src_dir, 'foo')
809 self.assertEqual(['foo'], os.listdir(rv))
815 src_dir = os.path.join(base_dir, "t", "pg")
816 dst_dir = os.path.join(src_dir, "somevendor", "1.0")
817 os.makedirs(src_dir)
818 src = os.path.join(src_dir, 'pol')
821 self.assertEqual(['pol'], os.listdir(rv))
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')
836 os.symlink(src, src_link)
837 os.symlink(dst, dst_link)
838 os.chmod(src, stat.S_IRWXU|stat.S_IRWXG)
840 os.chmod(dst, stat.S_IRWXO)
841 self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
843 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
844 # On Windows, os.chmod does not follow symlinks (issue #15411)
845 if os.name != 'nt':
847 os.chmod(dst, stat.S_IRWXO)
849 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
851 os.chmod(dst, stat.S_IRWXO)
853 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
855 os.chmod(dst, stat.S_IRWXO)
857 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
859 @unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod')
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')
869 os.symlink(src, src_link)
870 os.symlink(dst, dst_link)
871 os.chmod(src, stat.S_IRWXU|stat.S_IRWXG)
872 os.chmod(dst, stat.S_IRWXU)
873 os.lchmod(src_link, stat.S_IRWXO|stat.S_IRWXG)
875 os.lchmod(dst_link, stat.S_IRWXO)
877 self.assertEqual(os.lstat(src_link).st_mode,
878 os.lstat(dst_link).st_mode)
879 self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
881 os.lchmod(dst_link, stat.S_IRWXO)
883 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
885 os.lchmod(dst_link, stat.S_IRWXO)
887 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
889 @unittest.skipIf(hasattr(os, 'lchmod'), 'requires os.lchmod to be missing')
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')
899 os.symlink(src, src_link)
900 os.symlink(dst, dst_link)
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')
913 src_stat = os.stat(src)
914 os.utime(src, (src_stat.st_atime,
917 self.assertNotEqual(os.stat(src).st_mtime, os.stat(dst).st_mtime)
918 os.symlink(src, src_link)
919 os.symlink(dst, dst_link)
920 if hasattr(os, 'lchmod'):
921 os.lchmod(src_link, stat.S_IRWXO)
922 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
923 os.lchflags(src_link, stat.UF_NODUMP)
924 src_link_stat = os.lstat(src_link)
926 if hasattr(os, 'lchmod'):
928 self.assertNotEqual(src_link_stat.st_mode, os.stat(dst).st_mode)
931 dst_link_stat = os.lstat(dst_link)
932 if os.utime in os.supports_follow_symlinks:
937 if hasattr(os, 'lchmod'):
939 if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'):
943 self.assertTrue(abs(os.stat(src).st_mtime - os.stat(dst).st_mtime) <
946 @unittest.skipUnless(hasattr(os, 'chflags') and
949 "requires os.chflags, EOPNOTSUPP & ENOTSUP")
952 file1 = os.path.join(tmpdir, 'file1')
953 file2 = os.path.join(tmpdir, 'file2')
964 old_chflags = os.chflags
967 os.chflags = make_chflags_raiser(err)
970 os.chflags = make_chflags_raiser(errno.EOPNOTSUPP + errno.ENOTSUP)
973 os.chflags = old_chflags
980 src = os.path.join(tmp_dir, 'foo')
982 dst = os.path.join(tmp_dir, 'bar')
988 os.setxattr(src, 'user.foo', b'42')
989 os.setxattr(src, 'user.bar', b'43')
991 self.assertEqual(sorted(os.listxattr(src)), sorted(os.listxattr(dst)))
993 os.getxattr(src, 'user.foo'),
994 os.getxattr(dst, 'user.foo'))
996 os.remove(dst)
1006 orig_setxattr = os.setxattr
1007 os.setxattr = _raise_on_user_foo
1009 self.assertIn('user.bar', os.listxattr(dst))
1011 os.setxattr = orig_setxattr
1018 orig_listxattr = os.listxattr
1019 os.listxattr = _raise_on_src
1022 os.listxattr = orig_listxattr
1025 src = os.path.join(tmp_dir, 'the_original')
1026 srcro = os.path.join(tmp_dir, 'the_original_ro')
1029 os.setxattr(src, 'user.the_value', b'fiddly')
1030 os.setxattr(srcro, 'user.the_value', b'fiddly')
1031 os.chmod(srcro, 0o444)
1032 dst = os.path.join(tmp_dir, 'the_copy')
1033 dstro = os.path.join(tmp_dir, 'the_copy_ro')
1038 self.assertEqual(os.getxattr(dst, 'user.the_value'), b'fiddly')
1039 self.assertEqual(os.getxattr(dstro, 'user.the_value'), b'fiddly')
1049 src = os.path.join(tmp_dir, 'foo')
1050 src_link = os.path.join(tmp_dir, 'baz')
1052 os.symlink(src, src_link)
1053 os.setxattr(src, 'trusted.foo', b'42')
1054 os.setxattr(src_link, 'trusted.foo', b'43', follow_symlinks=False)
1055 dst = os.path.join(tmp_dir, 'bar')
1056 dst_link = os.path.join(tmp_dir, 'qux')
1058 os.symlink(dst, dst_link)
1060 self.assertEqual(os.getxattr(dst_link, 'trusted.foo', follow_symlinks=False), b'43')
1061 self.assertRaises(OSError, os.getxattr, dst, 'trusted.foo')
1063 self.assertEqual(os.getxattr(dst, 'trusted.foo'), b'43')
1071 file1 = os.path.join(tmpdir, fname)
1074 file2 = os.path.join(tmpdir2, fname)
1080 self.assertTrue(os.path.exists(file2))
1081 self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode)
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')
1090 os.symlink(src, src_link)
1091 if hasattr(os, 'lchmod'):
1092 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
1095 self.assertFalse(os.path.islink(dst))
1097 os.remove(dst)
1100 self.assertTrue(os.path.islink(dst))
1101 self.assertEqual(os.readlink(dst), os.readlink(src_link))
1102 if hasattr(os, 'lchmod'):
1103 self.assertEqual(os.lstat(src_link).st_mode,
1104 os.lstat(dst).st_mode)
1108 @unittest.skipUnless(hasattr(os, 'utime'), 'requires os.utime')
1113 self.assertTrue(os.path.exists(file2))
1114 file1_stat = os.stat(file1)
1115 file2_stat = os.stat(file2)
1121 if hasattr(os, 'chflags') and hasattr(file1_stat, 'st_flags'):
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')
1132 os.symlink(src, src_link)
1133 if hasattr(os, 'lchmod'):
1134 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
1135 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
1136 os.lchflags(src_link, stat.UF_NODUMP)
1137 src_stat = os.stat(src)
1138 src_link_stat = os.lstat(src_link)
1141 self.assertFalse(os.path.islink(dst))
1143 os.remove(dst)
1146 self.assertTrue(os.path.islink(dst))
1147 self.assertEqual(os.readlink(dst), os.readlink(src_link))
1148 dst_stat = os.lstat(dst)
1149 if os.utime in os.supports_follow_symlinks:
1154 if hasattr(os, 'lchmod'):
1157 if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'):
1163 src = os.path.join(tmp_dir, 'foo')
1164 dst = os.path.join(tmp_dir, 'bar')
1166 os.setxattr(src, 'user.foo', b'42')
1169 os.getxattr(src, 'user.foo'),
1170 os.getxattr(dst, 'user.foo'))
1171 os.remove(dst)
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')
1217 os.symlink(src, link)
1220 self.assertTrue(os.path.islink(dst_link))
1221 self.assertEqual(os.readlink(link), os.readlink(dst_link))
1224 self.assertFalse(os.path.islink(dst))
1226 @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
1229 os.mkdir(TESTFN)
1230 src = os.path.join(TESTFN, 'cheese')
1231 dst = os.path.join(TESTFN, 'shop')
1236 os.link(src, dst)
1238 self.skipTest('os.link(): %s' % e)
1242 os.remove(dst)
1249 os.mkdir(TESTFN)
1250 src = os.path.join(TESTFN, 'cheese')
1251 dst = os.path.join(TESTFN, 'shop')
1258 os.symlink('cheese', dst)
1262 os.remove(dst)
1267 @unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
1272 os.mkfifo(TESTFN)
1274 self.skipTest('os.mkfifo(): %s' % e)
1281 os.remove(TESTFN)
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')
1307 # gh-92670: The test uses a trailing slash to force the OS consider
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/')
1349 os.rmdir(tmpdir2)
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))
1387 dist = os.path.join(root_dir, base_dir)
1388 os.makedirs(dist, exist_ok=True)
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))
1441 os.rmdir(tmpdir2)
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))
1580 current_dir = os.getcwd()
1591 with support.swap_attr(os, 'chdir', _chdir) as orig_chdir:
1596 self.assertEqual(os.getcwd(), current_dir)
1606 self.assertTrue(os.path.isfile('test.tar'))
1614 self.assertTrue(os.path.isfile('test.zip'))
1646 base_name = os.path.join(self.mkdtemp(), 'archive')
1725 usage = shutil.disk_usage(os.path.dirname(__file__))
1738 @unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
1759 uid = os.getuid()
1760 gid = os.getgid()
1763 s = os.stat(filename)
1809 os.chmod(self.temp_file.name, stat.S_IXUSR)
1811 self.dir, self.file = os.path.split(self.temp_file.name)
1813 self.curdir = os.curdir
1830 base_dir, tail_dir = os.path.split(self.dir)
1831 relpath = os.path.join(tail_dir, self.file)
1842 base_dir = os.path.dirname(self.dir)
1847 self.assertEqual(rv, os.path.join(self.curdir, self.file))
1855 os.chmod(self.temp_file.name, stat.S_IREAD)
1856 if os.access(self.temp_file.name, os.W_OK):
1858 rv = shutil.which(self.file, path=self.dir, mode=os.W_OK)
1862 base_dir, tail_dir = os.path.split(self.dir)
1865 self.assertEqual(rv, os.path.join(tail_dir, self.file))
1890 with unittest.mock.patch('os.confstr', return_value=self.dir, \
1892 support.swap_attr(os, 'defpath', self.dir), \
1898 expected_cwd = os.path.basename(self.temp_file.name)
1900 curdir = os.curdir
1902 curdir = os.fsencode(curdir)
1903 expected_cwd = os.path.join(curdir, expected_cwd)
1907 env['PATH'] = os.pathsep
1908 with unittest.mock.patch('os.confstr', return_value=self.dir, \
1910 support.swap_attr(os, 'defpath', self.dir):
1924 with unittest.mock.patch('os.confstr', side_effect=ValueError, \
1926 support.swap_attr(os, 'defpath', self.dir):
1931 with unittest.mock.patch('os.confstr', return_value=self.dir, \
1933 support.swap_attr(os, 'defpath', ''):
1938 base_dir = os.path.dirname(self.dir)
1956 os.chmod(temp_filexyz.name, stat.S_IXUSR)
1960 program = os.path.basename(temp_filexyz.name)
1961 program = os.path.splitext(program)[0]
1977 program = os.path.basename(temp_filexyz.name)
1978 program = os.path.splitext(program)[0]
1989 self.dir = os.fsencode(self.dir)
1990 self.file = os.fsencode(self.file)
1991 self.temp_file.name = os.fsencode(self.temp_file.name)
1992 self.curdir = os.fsencode(self.curdir)
1993 self.ext = os.fsencode(self.ext)
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))
2016 contents = sorted(os.listdir(src))
2018 self.assertEqual(contents, sorted(os.listdir(real_dst)))
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")
2093 os.mkdir(TESTFN)
2096 src = os.path.join(TESTFN, src)
2097 dst = os.path.join(TESTFN, dst)
2105 os.mkdir(TESTFN)
2108 src = os.path.join(TESTFN, src)
2109 dst = os.path.join(TESTFN, dst)
2119 dst = os.path.join(self.src_dir, 'bar')
2120 os.symlink(self.src_file, dst)
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)
2130 os.symlink(self.src_file, dst)
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')
2141 os.symlink(src, dst)
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')
2152 os.mkdir(src)
2153 os.symlink(src, dst)
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))
2200 os.rmdir(dst_dir)
2204 @unittest.skipUnless(hasattr(os, 'lchflags')
2212 os.mkdir(TESTFN_SRC)
2213 os.lchflags(TESTFN_SRC, stat.SF_IMMUTABLE)
2218 self.assertFalse(TESTFN_DST in os.listdir())
2221 os.lchflags(TESTFN_SRC, stat.UF_OPAQUE)
2222 os_helper.create_empty_file(os.path.join(TESTFN_SRC, 'child'))
2223 os.lchflags(TESTFN_SRC, stat.SF_IMMUTABLE)
2228 self.assertFalse(TESTFN_DST in os.listdir())
2230 if os.path.exists(TESTFN_SRC):
2231 os.lchflags(TESTFN_SRC, stat.UF_OPAQUE)
2233 if os.path.exists(TESTFN_DST):
2234 os.lchflags(TESTFN_DST, stat.UF_OPAQUE)
2373 @unittest.skipIf(os.name != 'nt', "Windows only")
2385 with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f:
2394 with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f:
2460 name = tempfile.mktemp(dir=os.getcwd())
2504 @unittest.skipIf(not SUPPORTS_SENDFILE, 'os.sendfile() not supported')
2506 PATCHPOINT = "os.sendfile"
2538 orig_sendfile = os.sendfile
2539 with unittest.mock.patch('os.sendfile', create=True,
2551 with unittest.mock.patch('os.fstat', side_effect=OSError) as m:
2564 with unittest.mock.patch('os.fstat', return_value=mock) as m:
2577 with unittest.mock.patch('os.fstat', return_value=mock) as m:
2584 with unittest.mock.patch('os.sendfile',
2591 self.assertEqual(blocksize, os.path.getsize(TESTFN))
2665 @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty")
2666 @unittest.skipUnless(hasattr(os, 'get_terminal_size'),
2667 'need os.get_terminal_size()')
2703 with open(os.devnull, 'w', encoding='utf-8') as f, \
2723 if hasattr(os, 'statvfs') or os.name == 'nt':