Lines Matching full:os
9 import os
10 import os.path
58 builtin_rename = os.rename
59 os.rename = _fake_rename
62 os.rename = builtin_rename
68 If *path* is a tuple instead of a string, os.path.join will be used to
73 path = os.path.join(*path)
93 assert os.path.getsize(path) == size
98 If *path* is a tuple instead of a string, os.path.join will be used to
103 path = os.path.join(*path)
109 for name in sorted(os.listdir(path)):
110 p = os.path.join(path, name)
111 if os.path.isdir(p) and not os.path.islink(p):
121 if not hasattr(os, "sendfile"):
126 with tempfile.NamedTemporaryFile("wb", dir=os.getcwd(), delete=False) as f:
131 with tempfile.NamedTemporaryFile("wb", dir=os.getcwd(), delete=False) as dst:
136 os.sendfile(outfd, infd, 0, 2)
170 d = tempfile.mkdtemp(prefix=prefix, dir=os.getcwd())
179 victim = os.path.join(tmp, 'killme')
180 os.mkdir(victim)
181 write_file(os.path.join(victim, 'somefile'), 'foo')
182 victim = os.fsencode(victim)
189 dir_ = os.path.join(tmp, 'dir')
190 os.mkdir(dir_)
191 link = os.path.join(tmp, 'link')
192 os.symlink(dir_, link)
194 self.assertTrue(os.path.exists(dir_))
195 self.assertTrue(os.path.lexists(link))
201 self.assertIs(errors[0][0], os.path.islink)
208 dir1 = os.path.join(tmp, 'dir1')
209 dir2 = os.path.join(dir1, 'dir2')
210 dir3 = os.path.join(tmp, 'dir3')
212 os.mkdir(d)
213 file1 = os.path.join(tmp, 'file1')
215 link1 = os.path.join(dir1, 'link1')
216 os.symlink(dir2, link1)
217 link2 = os.path.join(dir1, 'link2')
218 os.symlink(dir3, link2)
219 link3 = os.path.join(dir1, 'link3')
220 os.symlink(file1, link3)
223 self.assertFalse(os.path.exists(dir1))
224 self.assertTrue(os.path.exists(dir3))
225 self.assertTrue(os.path.exists(file1))
230 dir_ = os.path.join(tmp, 'dir')
231 os.mkdir(dir_)
232 link = os.path.join(tmp, 'link')
236 self.assertTrue(os.path.exists(dir_))
237 self.assertTrue(os.path.lexists(link))
243 self.assertIs(errors[0][0], os.path.islink)
250 dir1 = os.path.join(tmp, 'dir1')
251 dir2 = os.path.join(dir1, 'dir2')
252 dir3 = os.path.join(tmp, 'dir3')
254 os.mkdir(d)
255 file1 = os.path.join(tmp, 'file1')
257 link1 = os.path.join(dir1, 'link1')
259 link2 = os.path.join(dir1, 'link2')
261 link3 = os.path.join(dir1, 'link3')
265 self.assertFalse(os.path.exists(dir1))
266 self.assertTrue(os.path.exists(dir3))
267 self.assertTrue(os.path.exists(file1))
279 filename = os.path.join(tmpdir, "tstfile")
284 possible_args = [filename, os.path.join(filename, '*.*')]
286 self.assertTrue(os.path.exists(filename))
289 self.assertTrue(os.path.exists(filename))
295 self.assertIs(errors[0][0], os.scandir)
299 self.assertIs(errors[1][0], os.rmdir)
307 @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
311 os.mkdir(TESTFN)
314 self.child_file_path = os.path.join(TESTFN, 'a')
315 self.child_dir_path = os.path.join(TESTFN, 'b')
317 os.mkdir(self.child_dir_path)
318 old_dir_mode = os.stat(TESTFN).st_mode
319 old_child_file_mode = os.stat(self.child_file_path).st_mode
320 old_child_dir_mode = os.stat(self.child_dir_path).st_mode
323 os.chmod(self.child_file_path, new_mode)
324 os.chmod(self.child_dir_path, new_mode)
325 os.chmod(TESTFN, new_mode)
327 self.addCleanup(os.chmod, TESTFN, old_dir_mode)
328 self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
329 self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
342 # func is os.remove.
345 # at os.listdir. The first failure may legally
348 if func is os.unlink:
350 elif func is os.rmdir:
353 self.assertIs(func, os.listdir)
358 self.assertEqual(func, os.rmdir)
365 orig_lstat = os.lstat
371 os.lstat = raiser
373 os.mkdir(TESTFN)
377 os.lstat = orig_lstat
380 _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
381 os.supports_dir_fd and
382 os.listdir in os.supports_fd and
383 os.stat in os.supports_follow_symlinks)
388 d = os.path.join(tmp_dir, 'a')
389 os.mkdir(d)
406 os.close(handle)
408 os.remove(path)
413 os.mkdir(TESTFN)
415 src = os.path.join(TESTFN, 'cheese')
416 dst = os.path.join(TESTFN, 'shop')
417 os.mkdir(src)
418 os.symlink(src, dst)
426 os.mkdir(TESTFN)
428 src = os.path.join(TESTFN, 'cheese')
429 dst = os.path.join(TESTFN, 'shop')
430 os.mkdir(src)
431 open(os.path.join(src, 'spam'), 'wb').close()
443 dst_dir = os.path.join(self.mkdtemp(), 'destination')
445 self.addCleanup(shutil.rmtree, os.path.dirname(dst_dir))
447 os.mkdir(os.path.join(src_dir, 'test_dir'))
451 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test.txt')))
452 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'test_dir')))
453 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test_dir',
467 os.mkdir(os.path.join(src_dir, 'existing_dir'))
468 os.mkdir(os.path.join(dst_dir, 'existing_dir'))
473 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'nonexisting.txt')))
474 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'existing_dir')))
475 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'existing_dir',
488 src_dir = os.path.join(tmp_dir, 'src')
489 dst_dir = os.path.join(tmp_dir, 'dst')
490 sub_dir = os.path.join(src_dir, 'sub')
491 os.mkdir(src_dir)
492 os.mkdir(sub_dir)
494 src_link = os.path.join(sub_dir, 'link')
495 dst_link = os.path.join(dst_dir, 'sub/link')
496 os.symlink(os.path.join(src_dir, 'file.txt'),
498 if hasattr(os, 'lchmod'):
499 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
500 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
501 os.lchflags(src_link, stat.UF_NODUMP)
502 src_stat = os.lstat(src_link)
504 self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link')))
505 actual = os.readlink(os.path.join(dst_dir, 'sub', 'link'))
508 if os.name == 'nt' and actual.startswith('\\\\?\\'):
510 self.assertEqual(actual, os.path.join(src_dir, 'file.txt'))
511 dst_stat = os.lstat(dst_link)
512 if hasattr(os, 'lchmod'):
514 if hasattr(os, 'lchflags'):
519 join = os.path.join
520 exists = os.path.exists
526 os.mkdir(join(src_dir, 'test_dir'))
528 os.mkdir(join(src_dir, 'test_dir2'))
530 os.mkdir(join(src_dir, 'test_dir2', 'subdir'))
531 os.mkdir(join(src_dir, 'test_dir2', 'subdir2'))
560 path = os.path.join(src, name)
562 if (os.path.isdir(path) and
565 elif os.path.splitext(path)[-1] in ('.py'):
580 shutil.rmtree(os.path.dirname(dst_dir))
583 join = os.path.join
584 exists = os.path.exists
589 os.mkdir(join(src_dir))
590 os.mkdir(join(src_dir, 'test_dir'))
591 os.mkdir(os.path.join(src_dir, 'test_dir', 'subdir'))
616 src_dir_entry = list(os.scandir(tmp_dir))[0]
617 self.assertIsInstance(src_dir_entry, os.DirEntry)
626 src_dir = os.path.join(tmp_dir, 'source')
627 os.mkdir(src_dir)
628 dst_dir = os.path.join(tmp_dir, 'destination')
631 os.chmod(src_dir, 0o777)
633 os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
635 os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
638 os.chmod(restrictive_subdir, 0o600)
641 self.assertEqual(os.stat(src_dir).st_mode, os.stat(dst_dir).st_mode)
642 self.assertEqual(os.stat(os.path.join(src_dir, 'permissive.txt')).st_mode,
643 os.stat(os.path.join(dst_dir, 'permissive.txt')).st_mode)
644 self.assertEqual(os.stat(os.path.join(src_dir, 'restrictive.txt')).st_mode,
645 os.stat(os.path.join(dst_dir, 'restrictive.txt')).st_mode)
646 restrictive_subdir_dst = os.path.join(dst_dir,
647 os.path.split(restrictive_subdir)[1])
648 self.assertEqual(os.stat(restrictive_subdir).st_mode,
649 os.stat(restrictive_subdir_dst).st_mode)
651 @unittest.mock.patch('os.chmod')
657 dst_dir = os.path.join(self.mkdtemp(), 'destination')
659 self.addCleanup(shutil.rmtree, os.path.dirname(dst_dir))
671 self.assertEqual(a, os.path.join(src, 'foo'))
672 self.assertEqual(b, os.path.join(dst, 'foo'))
677 with open(os.path.join(src, 'foo'), 'w') as f:
683 @unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
686 os.mkdir(TESTFN)
688 subdir = os.path.join(TESTFN, "subdir")
689 os.mkdir(subdir)
690 pipe = os.path.join(subdir, "mypipe")
692 os.mkfifo(pipe)
694 self.skipTest('os.mkfifo(): %s' % e)
710 dst_dir = os.path.join(self.mkdtemp(), 'destination')
712 os.mkdir(os.path.join(src_dir, 'test_dir'))
726 dst_dir = os.path.join(self.mkdtemp(), 'destination')
727 os.symlink('IDONTEXIST', os.path.join(src_dir, 'test.txt'))
728 os.mkdir(os.path.join(src_dir, 'test_dir'))
733 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
735 self.assertNotIn('test.txt', os.listdir(dst_dir))
738 dst_dir = os.path.join(self.mkdtemp(), 'destination3')
740 self.assertIn('test.txt', os.listdir(dst_dir))
745 dst_dir = os.path.join(self.mkdtemp(), 'destination')
746 os.mkdir(os.path.join(src_dir, 'real_dir'))
747 with open(os.path.join(src_dir, 'real_dir', 'test.txt'), 'w'):
749 os.symlink(os.path.join(src_dir, 'real_dir'),
750 os.path.join(src_dir, 'link_to_dir'),
754 self.assertFalse(os.path.islink(os.path.join(dst_dir, 'link_to_dir')))
755 self.assertIn('test.txt', os.listdir(os.path.join(dst_dir, 'link_to_dir')))
757 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
759 self.assertTrue(os.path.islink(os.path.join(dst_dir, 'link_to_dir')))
760 self.assertIn('test.txt', os.listdir(os.path.join(dst_dir, 'link_to_dir')))
767 src = os.path.join(src_dir, 'foo')
770 self.assertEqual(['foo'], os.listdir(rv))
776 src_dir = os.path.join(base_dir, "t", "pg")
777 dst_dir = os.path.join(src_dir, "somevendor", "1.0")
778 os.makedirs(src_dir)
779 src = os.path.join(src_dir, 'pol')
782 self.assertEqual(['pol'], os.listdir(rv))
791 src = os.path.join(tmp_dir, 'foo')
792 dst = os.path.join(tmp_dir, 'bar')
793 src_link = os.path.join(tmp_dir, 'baz')
794 dst_link = os.path.join(tmp_dir, 'quux')
797 os.symlink(src, src_link)
798 os.symlink(dst, dst_link)
799 os.chmod(src, stat.S_IRWXU|stat.S_IRWXG)
801 os.chmod(dst, stat.S_IRWXO)
802 self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
804 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
805 # On Windows, os.chmod does not follow symlinks (issue #15411)
806 if os.name != 'nt':
808 os.chmod(dst, stat.S_IRWXO)
810 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
812 os.chmod(dst, stat.S_IRWXO)
814 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
816 os.chmod(dst, stat.S_IRWXO)
818 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
820 @unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod')
824 src = os.path.join(tmp_dir, 'foo')
825 dst = os.path.join(tmp_dir, 'bar')
826 src_link = os.path.join(tmp_dir, 'baz')
827 dst_link = os.path.join(tmp_dir, 'quux')
830 os.symlink(src, src_link)
831 os.symlink(dst, dst_link)
832 os.chmod(src, stat.S_IRWXU|stat.S_IRWXG)
833 os.chmod(dst, stat.S_IRWXU)
834 os.lchmod(src_link, stat.S_IRWXO|stat.S_IRWXG)
836 os.lchmod(dst_link, stat.S_IRWXO)
838 self.assertEqual(os.lstat(src_link).st_mode,
839 os.lstat(dst_link).st_mode)
840 self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
842 os.lchmod(dst_link, stat.S_IRWXO)
844 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
846 os.lchmod(dst_link, stat.S_IRWXO)
848 self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
850 @unittest.skipIf(hasattr(os, 'lchmod'), 'requires os.lchmod to be missing')
854 src = os.path.join(tmp_dir, 'foo')
855 dst = os.path.join(tmp_dir, 'bar')
856 src_link = os.path.join(tmp_dir, 'baz')
857 dst_link = os.path.join(tmp_dir, 'quux')
860 os.symlink(src, src_link)
861 os.symlink(dst, dst_link)
869 src = os.path.join(tmp_dir, 'foo')
870 dst = os.path.join(tmp_dir, 'bar')
871 src_link = os.path.join(tmp_dir, 'baz')
872 dst_link = os.path.join(tmp_dir, 'qux')
874 src_stat = os.stat(src)
875 os.utime(src, (src_stat.st_atime,
878 self.assertNotEqual(os.stat(src).st_mtime, os.stat(dst).st_mtime)
879 os.symlink(src, src_link)
880 os.symlink(dst, dst_link)
881 if hasattr(os, 'lchmod'):
882 os.lchmod(src_link, stat.S_IRWXO)
883 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
884 os.lchflags(src_link, stat.UF_NODUMP)
885 src_link_stat = os.lstat(src_link)
887 if hasattr(os, 'lchmod'):
889 self.assertNotEqual(src_link_stat.st_mode, os.stat(dst).st_mode)
892 dst_link_stat = os.lstat(dst_link)
893 if os.utime in os.supports_follow_symlinks:
898 if hasattr(os, 'lchmod'):
900 if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'):
904 self.assertTrue(abs(os.stat(src).st_mtime - os.stat(dst).st_mtime) <
907 @unittest.skipUnless(hasattr(os, 'chflags') and
910 "requires os.chflags, EOPNOTSUPP & ENOTSUP")
913 file1 = os.path.join(tmpdir, 'file1')
914 file2 = os.path.join(tmpdir, 'file2')
925 old_chflags = os.chflags
928 os.chflags = make_chflags_raiser(err)
931 os.chflags = make_chflags_raiser(errno.EOPNOTSUPP + errno.ENOTSUP)
934 os.chflags = old_chflags
941 src = os.path.join(tmp_dir, 'foo')
943 dst = os.path.join(tmp_dir, 'bar')
949 os.setxattr(src, 'user.foo', b'42')
950 os.setxattr(src, 'user.bar', b'43')
952 self.assertEqual(sorted(os.listxattr(src)), sorted(os.listxattr(dst)))
954 os.getxattr(src, 'user.foo'),
955 os.getxattr(dst, 'user.foo'))
957 os.remove(dst)
967 orig_setxattr = os.setxattr
968 os.setxattr = _raise_on_user_foo
970 self.assertIn('user.bar', os.listxattr(dst))
972 os.setxattr = orig_setxattr
979 orig_listxattr = os.listxattr
980 os.listxattr = _raise_on_src
983 os.listxattr = orig_listxattr
986 src = os.path.join(tmp_dir, 'the_original')
987 srcro = os.path.join(tmp_dir, 'the_original_ro')
990 os.setxattr(src, 'user.the_value', b'fiddly')
991 os.setxattr(srcro, 'user.the_value', b'fiddly')
992 os.chmod(srcro, 0o444)
993 dst = os.path.join(tmp_dir, 'the_copy')
994 dstro = os.path.join(tmp_dir, 'the_copy_ro')
999 self.assertEqual(os.getxattr(dst, 'user.the_value'), b'fiddly')
1000 self.assertEqual(os.getxattr(dstro, 'user.the_value'), b'fiddly')
1004 @unittest.skipUnless(hasattr(os, 'geteuid') and os.geteuid() == 0,
1011 src = os.path.join(tmp_dir, 'foo')
1012 src_link = os.path.join(tmp_dir, 'baz')
1014 os.symlink(src, src_link)
1015 os.setxattr(src, 'trusted.foo', b'42')
1016 os.setxattr(src_link, 'trusted.foo', b'43', follow_symlinks=False)
1017 dst = os.path.join(tmp_dir, 'bar')
1018 dst_link = os.path.join(tmp_dir, 'qux')
1020 os.symlink(dst, dst_link)
1022 self.assertEqual(os.getxattr(dst_link, 'trusted.foo', follow_symlinks=False), b'43')
1023 self.assertRaises(OSError, os.getxattr, dst, 'trusted.foo')
1025 self.assertEqual(os.getxattr(dst, 'trusted.foo'), b'43')
1033 file1 = os.path.join(tmpdir, fname)
1036 file2 = os.path.join(tmpdir2, fname)
1042 self.assertTrue(os.path.exists(file2))
1043 self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode)
1048 src = os.path.join(tmp_dir, 'foo')
1049 dst = os.path.join(tmp_dir, 'bar')
1050 src_link = os.path.join(tmp_dir, 'baz')
1052 os.symlink(src, src_link)
1053 if hasattr(os, 'lchmod'):
1054 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
1057 self.assertFalse(os.path.islink(dst))
1059 os.remove(dst)
1062 self.assertTrue(os.path.islink(dst))
1063 self.assertEqual(os.readlink(dst), os.readlink(src_link))
1064 if hasattr(os, 'lchmod'):
1065 self.assertEqual(os.lstat(src_link).st_mode,
1066 os.lstat(dst).st_mode)
1070 @unittest.skipUnless(hasattr(os, 'utime'), 'requires os.utime')
1075 self.assertTrue(os.path.exists(file2))
1076 file1_stat = os.stat(file1)
1077 file2_stat = os.stat(file2)
1083 if hasattr(os, 'chflags') and hasattr(file1_stat, 'st_flags'):
1090 src = os.path.join(tmp_dir, 'foo')
1091 dst = os.path.join(tmp_dir, 'bar')
1092 src_link = os.path.join(tmp_dir, 'baz')
1094 os.symlink(src, src_link)
1095 if hasattr(os, 'lchmod'):
1096 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
1097 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
1098 os.lchflags(src_link, stat.UF_NODUMP)
1099 src_stat = os.stat(src)
1100 src_link_stat = os.lstat(src_link)
1103 self.assertFalse(os.path.islink(dst))
1105 os.remove(dst)
1108 self.assertTrue(os.path.islink(dst))
1109 self.assertEqual(os.readlink(dst), os.readlink(src_link))
1110 dst_stat = os.lstat(dst)
1111 if os.utime in os.supports_follow_symlinks:
1116 if hasattr(os, 'lchmod'):
1119 if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'):
1125 src = os.path.join(tmp_dir, 'foo')
1126 dst = os.path.join(tmp_dir, 'bar')
1128 os.setxattr(src, 'user.foo', b'42')
1131 os.getxattr(src, 'user.foo'),
1132 os.getxattr(dst, 'user.foo'))
1133 os.remove(dst)
1140 src = os.path.join(src_dir, 'foo')
1143 self.assertEqual(rv, os.path.join(dst_dir, 'foo'))
1144 rv = fn(src, os.path.join(dst_dir, 'bar'))
1145 self.assertEqual(rv, os.path.join(dst_dir, 'bar'))
1152 src = os.path.join(tmp_dir, 'src')
1153 dst = os.path.join(tmp_dir, 'dst')
1154 dst_link = os.path.join(tmp_dir, 'dst_link')
1155 link = os.path.join(tmp_dir, 'link')
1157 os.symlink(src, link)
1160 self.assertTrue(os.path.islink(dst_link))
1161 self.assertEqual(os.readlink(link), os.readlink(dst_link))
1164 self.assertFalse(os.path.islink(dst))
1166 @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
1169 os.mkdir(TESTFN)
1170 src = os.path.join(TESTFN, 'cheese')
1171 dst = os.path.join(TESTFN, 'shop')
1176 os.link(src, dst)
1178 self.skipTest('os.link(): %s' % e)
1182 os.remove(dst)
1189 os.mkdir(TESTFN)
1190 src = os.path.join(TESTFN, 'cheese')
1191 dst = os.path.join(TESTFN, 'shop')
1198 os.symlink('cheese', dst)
1202 os.remove(dst)
1207 @unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
1210 os.mkfifo(TESTFN)
1212 self.skipTest('os.mkfifo(): %s' % e)
1219 os.remove(TESTFN)
1225 dst_file = os.path.join(dst_dir, 'bar')
1226 src_file = os.path.join(src_dir, 'foo')
1229 self.assertTrue(os.path.exists(rv))
1236 src_file = os.path.join(src_dir, 'foo')
1256 os.rmdir(tmpdir2)
1258 work_dir = os.path.dirname(tmpdir2)
1259 rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
1262 base_name = os.path.abspath(rel_base_name)
1267 self.assertTrue(os.path.isfile(tarball))
1278 self.assertTrue(os.path.isfile(tarball))
1294 dist = os.path.join(root_dir, base_dir)
1295 os.makedirs(dist, exist_ok=True)
1298 os.mkdir(os.path.join(dist, 'sub'))
1300 os.mkdir(os.path.join(dist, 'sub2'))
1310 base_name = os.path.join(self.mkdtemp(), 'archive')
1315 self.assertTrue(os.path.isfile(tarball))
1318 tarball2 = os.path.join(root_dir, 'archive2.tar')
1323 self.assertTrue(os.path.isfile(tarball2))
1330 self.assertTrue(os.path.isfile(tarball))
1336 self.assertTrue(os.path.isfile(tarball))
1345 os.rmdir(tmpdir2)
1347 work_dir = os.path.dirname(tmpdir2)
1348 rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive')
1351 base_name = os.path.abspath(rel_base_name)
1355 self.assertTrue(os.path.isfile(res))
1364 base_name = os.path.abspath(rel_base_name)
1368 self.assertTrue(os.path.isfile(res))
1380 base_name = os.path.join(self.mkdtemp(), 'archive')
1385 self.assertTrue(os.path.isfile(archive))
1388 archive2 = os.path.join(root_dir, 'archive2.zip')
1393 self.assertTrue(os.path.isfile(archive2))
1406 base_name = os.path.join(self.mkdtemp(), 'archive')
1411 self.assertTrue(os.path.isfile(archive))
1427 base_name = os.path.join(tmpdir, 'archive')
1441 base_name = os.path.join(self.mkdtemp(), 'archive')
1444 self.assertTrue(os.path.isfile(res))
1447 self.assertTrue(os.path.isfile(res))
1451 self.assertTrue(os.path.isfile(res))
1455 self.assertTrue(os.path.isfile(res))
1462 base_name = os.path.join(self.mkdtemp(), 'archive')
1470 self.assertTrue(os.path.isfile(archive_name))
1482 current_dir = os.getcwd()
1492 self.assertEqual(os.getcwd(), current_dir)
1501 self.assertTrue(os.path.isfile('test.tar'))
1509 self.assertTrue(os.path.isfile('test.zip'))
1539 base_name = os.path.join(self.mkdtemp(), 'archive')
1607 usage = shutil.disk_usage(os.path.dirname(__file__))
1620 @unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
1641 uid = os.getuid()
1642 gid = os.getgid()
1645 s = os.stat(filename)
1691 os.chmod(self.temp_file.name, stat.S_IXUSR)
1693 self.dir, self.file = os.path.split(self.temp_file.name)
1695 self.curdir = os.curdir
1712 base_dir, tail_dir = os.path.split(self.dir)
1713 relpath = os.path.join(tail_dir, self.file)
1724 base_dir = os.path.dirname(self.dir)
1729 self.assertEqual(rv, os.path.join(self.curdir, self.file))
1734 @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
1738 os.chmod(self.temp_file.name, stat.S_IREAD)
1739 if os.access(self.temp_file.name, os.W_OK):
1741 rv = shutil.which(self.file, path=self.dir, mode=os.W_OK)
1745 base_dir, tail_dir = os.path.split(self.dir)
1748 self.assertEqual(rv, os.path.join(tail_dir, self.file))
1773 with unittest.mock.patch('os.confstr', return_value=self.dir, \
1775 support.swap_attr(os, 'defpath', self.dir), \
1781 expected_cwd = os.path.basename(self.temp_file.name)
1783 curdir = os.curdir
1785 curdir = os.fsencode(curdir)
1786 expected_cwd = os.path.join(curdir, expected_cwd)
1790 env['PATH'] = os.pathsep
1791 with unittest.mock.patch('os.confstr', return_value=self.dir, \
1793 support.swap_attr(os, 'defpath', self.dir):
1807 with unittest.mock.patch('os.confstr', side_effect=ValueError, \
1809 support.swap_attr(os, 'defpath', self.dir):
1814 with unittest.mock.patch('os.confstr', return_value=self.dir, \
1816 support.swap_attr(os, 'defpath', ''):
1821 base_dir = os.path.dirname(self.dir)
1839 os.chmod(temp_filexyz.name, stat.S_IXUSR)
1843 program = os.path.basename(temp_filexyz.name)
1844 program = os.path.splitext(program)[0]
1860 program = os.path.basename(temp_filexyz.name)
1861 program = os.path.splitext(program)[0]
1872 self.dir = os.fsencode(self.dir)
1873 self.file = os.fsencode(self.file)
1874 self.temp_file.name = os.fsencode(self.temp_file.name)
1875 self.curdir = os.fsencode(self.curdir)
1876 self.ext = os.fsencode(self.ext)
1885 self.src_file = os.path.join(self.src_dir, filename)
1886 self.dst_file = os.path.join(self.dst_dir, filename)
1896 self.assertFalse(os.path.exists(src))
1899 contents = sorted(os.listdir(src))
1901 self.assertEqual(contents, sorted(os.listdir(real_dst)))
1902 self.assertFalse(os.path.exists(src))
1948 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
1956 self._check_move_dir(self.src_dir + os.path.sep, self.dst_dir,
1957 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
1959 @unittest.skipUnless(os.path.altsep, 'requires os.path.altsep')
1961 self._check_move_dir(self.src_dir + os.path.altsep, self.dst_dir,
1962 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
1972 dst = os.path.join(self.src_dir, "bar")
1976 os.mkdir(TESTFN)
1979 src = os.path.join(TESTFN, src)
1980 dst = os.path.join(TESTFN, dst)
1988 os.mkdir(TESTFN)
1991 src = os.path.join(TESTFN, src)
1992 dst = os.path.join(TESTFN, dst)
2002 dst = os.path.join(self.src_dir, 'bar')
2003 os.symlink(self.src_file, dst)
2005 self.assertTrue(os.path.islink(self.dst_file))
2006 self.assertTrue(os.path.samefile(self.src_file, self.dst_file))
2012 dst = os.path.join(self.src_dir, filename)
2013 os.symlink(self.src_file, dst)
2015 final_link = os.path.join(self.dst_dir, filename)
2016 self.assertTrue(os.path.islink(final_link))
2017 self.assertTrue(os.path.samefile(self.src_file, final_link))
2022 src = os.path.join(self.src_dir, 'baz')
2023 dst = os.path.join(self.src_dir, 'bar')
2024 os.symlink(src, dst)
2025 dst_link = os.path.join(self.dst_dir, 'quux')
2027 self.assertTrue(os.path.islink(dst_link))
2028 self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
2033 src = os.path.join(self.src_dir, 'baz')
2034 dst = os.path.join(self.src_dir, 'bar')
2035 os.mkdir(src)
2036 os.symlink(src, dst)
2037 dst_link = os.path.join(self.dst_dir, 'quux')
2039 self.assertTrue(os.path.islink(dst_link))
2040 self.assertTrue(os.path.samefile(src, dst_link))
2045 os.path.join(self.dst_dir, os.path.basename(self.src_file)))
2048 rv = shutil.move(self.src_file, os.path.join(self.dst_dir, 'bar'))
2049 self.assertEqual(rv, os.path.join(self.dst_dir, 'bar'))
2064 support.create_empty_file(os.path.join(self.src_dir, 'child'))
2065 support.create_empty_file(os.path.join(self.src_dir, 'child1'))
2074 dst_dir = os.path.join(
2075 os.path.dirname(self.src_dir),
2076 os.path.basename(self.src_dir).upper())
2081 self.assertTrue(os.path.isdir(dst_dir))
2083 os.rmdir(dst_dir)
2221 @unittest.skipIf(os.name != 'nt', "Windows only")
2233 with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f:
2242 with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f:
2308 name = tempfile.mktemp(dir=os.getcwd())
2352 @unittest.skipIf(not SUPPORTS_SENDFILE, 'os.sendfile() not supported')
2354 PATCHPOINT = "os.sendfile"
2386 orig_sendfile = os.sendfile
2387 with unittest.mock.patch('os.sendfile', create=True,
2399 with unittest.mock.patch('os.fstat', side_effect=OSError) as m:
2412 with unittest.mock.patch('os.fstat', return_value=mock) as m:
2425 with unittest.mock.patch('os.fstat', return_value=mock) as m:
2432 with unittest.mock.patch('os.sendfile',
2439 self.assertEqual(blocksize, os.path.getsize(TESTFN))
2513 @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty")
2514 @unittest.skipUnless(hasattr(os, 'get_terminal_size'),
2515 'need os.get_terminal_size()')
2550 with open(os.devnull, 'w') as f, \
2570 if hasattr(os, 'statvfs') or os.name == 'nt':