Lines Matching full:os
1 # As a test suite for the os module, this is woefully inadequate, but this
16 import os
47 if hasattr(os, 'getgid'):
48 process_gid = os.getgid()
68 if hasattr(os, 'geteuid'):
69 root_in_posix = (os.geteuid() == 0)
81 HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0
85 return unittest.skipUnless(hasattr(os, name), 'requires os.%s' % name)
96 if os.path.lexists(support.TESTFN):
97 os.unlink(support.TESTFN)
101 f = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
102 os.close(f)
103 self.assertTrue(os.access(support.TESTFN, os.W_OK))
106 first = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
110 second = os.dup(first)
114 os.close(first)
119 first, second = second, os.dup(second)
121 os.close(second)
123 os.closerange(first, first + 2)
124 self.assertRaises(OSError, os.write, first, b"a")
130 self.assertRaises(TypeError, os.rename, path, 0)
139 os.lseek(fd, 0, 0)
140 s = os.read(fd, 4)
154 # Issue #21932: Make sure that os.read() does not raise an
157 data = os.read(fp.fileno(), size)
164 # os.write() accepts bytes- and buffer-like objects but not strings
165 fd = os.open(support.TESTFN, os.O_CREAT | os.O_WRONLY)
166 self.assertRaises(TypeError, os.write, fd, "beans")
167 os.write(fd, b"bacon\n")
168 os.write(fd, bytearray(b"eggs\n"))
169 os.write(fd, memoryview(b"spam\n"))
170 os.close(fd)
195 fd = os.open(support.TESTFN, os.O_RDONLY)
196 f = os.fdopen(fd, *args)
200 fd = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
201 os.close(fd)
215 os.replace(support.TESTFN, TESTFN2)
216 self.assertRaises(FileNotFoundError, os.stat, support.TESTFN)
221 f = os.open(path=__file__, flags=os.O_RDONLY, mode=0o777,
223 os.close(f)
226 symlink = support.get_attribute(os, "symlink")
231 pass # No OS support or unprivileged user
234 # Test attributes on return values from os.*stat* family.
241 @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()')
243 result = os.stat(fname)
296 result2 = os.stat_result((10,))
303 result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
318 result = os.stat(self.fname)
327 @unittest.skipUnless(hasattr(os, 'statvfs'), 'test needs os.statvfs()')
329 result = os.statvfs(self.fname)
360 result2 = os.statvfs_result((10,))
367 result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
371 @unittest.skipUnless(hasattr(os, 'statvfs'),
372 "need os.statvfs()")
374 result = os.statvfs(self.fname)
388 os.stat(r"c:\pagefile.sys")
395 @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
398 r, w = os.pipe()
400 os.stat(r) # should not raise error
402 os.close(r)
403 os.close(w)
405 os.stat(r)
417 result = os.stat(self.fname)
425 os.mkdir(dirname)
426 self.addCleanup(os.rmdir, dirname)
428 result = os.stat(dirname)
438 # os.environ['TEMP'] should be located on a volume that
440 fname = os.path.join(os.environ['TEMP'], self.fname)
452 result = os.stat(fname)
459 self.fname = os.path.join(self.dirname, "f1")
462 os.mkdir(self.dirname)
468 st = os.stat(filename)
481 # The resolution of the C internal function used by os.utime()
493 st = os.stat(filename)
507 os.utime(filename, ns=ns)
514 # issue, os.utime() rounds towards minus infinity.
525 os.utime(filename, (atime, mtime))
534 os.utime(filename, times=(atime, mtime))
537 @unittest.skipUnless(os.utime in os.supports_follow_symlinks,
544 os.utime(filename, ns=ns, follow_symlinks=False)
547 @unittest.skipUnless(os.utime in os.supports_fd,
554 os.utime(fp.fileno(), ns=ns)
557 @unittest.skipUnless(os.utime in os.supports_dir_fd,
561 dirname, name = os.path.split(filename)
562 dirfd = os.open(dirname, os.O_RDONLY)
565 os.utime(name, dir_fd=dirfd, ns=ns)
567 os.close(dirfd)
572 # test calling os.utime() on a directory
573 os.utime(filename, ns=ns)
580 # Call os.utime() to set the timestamp to the current system clock
592 st = os.stat(self.fname)
601 os.utime(self.fname)
607 os.utime(self.fname, None)
612 root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
630 os.utime(self.fname, (large, large))
631 self.assertEqual(os.stat(self.fname).st_mtime, large)
636 os.utime(self.fname, (5, 5), ns=(5, 5))
638 os.utime(self.fname, [5, 5])
640 os.utime(self.fname, (5,))
642 os.utime(self.fname, (5, 5, 5))
644 os.utime(self.fname, ns=[5, 5])
646 os.utime(self.fname, ns=(5,))
648 os.utime(self.fname, ns=(5, 5, 5))
650 if os.utime not in os.supports_follow_symlinks:
652 os.utime(self.fname, (5, 5), follow_symlinks=False)
653 if os.utime not in os.supports_fd:
656 os.utime(fp.fileno(), (5, 5))
657 if os.utime not in os.supports_dir_fd:
659 os.utime(self.fname, (5, 5), dir_fd=0)
671 os.utime(self.fname, ns=(get_bad_int(42), 1))
673 os.utime(self.fname, ns=(get_bad_int(()), 1))
675 os.utime(self.fname, ns=(get_bad_int((1, 2, 3)), 1))
681 """check that os.environ object conform to mapping protocol"""
685 self.__save = dict(os.environ)
686 if os.supports_bytes_environ:
687 self.__saveb = dict(os.environb)
689 os.environ[key] = value
692 os.environ.clear()
693 os.environ.update(self.__save)
694 if os.supports_bytes_environ:
695 os.environb.clear()
696 os.environb.update(self.__saveb)
702 os.environ.clear()
703 return os.environ
706 @unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
709 os.environ.clear()
710 os.environ.update(HELLO="World")
711 with os.popen("%s -c 'echo $HELLO'" % unix_shell) as popen:
715 @unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
718 with os.popen("%s -c 'echo \"line1\nline2\nline3\"'"
726 # Verify environ keys and values from the OS are of the
729 for key, val in os.environ.items():
735 self.assertEqual(os.environ.get(key), value)
739 """Check that the repr() of os.environ looks like environ({...})."""
740 env = os.environ
746 defpath_list = os.defpath.split(os.pathsep)
748 test_env = {'PATH': os.pathsep.join(test_path)}
750 saved_environ = os.environ
752 os.environ = dict(test_env)
753 # Test that defaulting to os.environ works.
754 self.assertSequenceEqual(test_path, os.get_exec_path())
755 self.assertSequenceEqual(test_path, os.get_exec_path(env=None))
757 os.environ = saved_environ
760 self.assertSequenceEqual(defpath_list, os.get_exec_path({}))
762 self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''}))
764 self.assertSequenceEqual(test_path, os.get_exec_path(test_env))
766 if os.supports_bytes_environ:
776 self.assertRaises(ValueError, os.get_exec_path, mixed_env)
779 self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}),
781 self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}),
783 self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}),
786 @unittest.skipUnless(os.supports_bytes_environ,
787 "os.environb required for this test.")
789 # os.environ -> os.environb
798 os.environ['unicode'] = value
799 self.assertEqual(os.environ['unicode'], value)
800 self.assertEqual(os.environb[b'unicode'], value_bytes)
802 # os.environb -> os.environ
804 os.environb[b'bytes'] = value
805 self.assertEqual(os.environb[b'bytes'], value)
807 self.assertEqual(os.environ['bytes'], value_str)
809 # On OS X < 10.6, unsetenv() doesn't return a value (bpo-13415).
815 self.assertRaises(ValueError, os.environ.__delitem__, key)
819 self.assertRaises(OSError, os.environ.__delitem__, key)
823 self.assertNotIn(missing, os.environ)
826 os.environ[missing]
831 del os.environ[missing]
839 next(iterator) # start iteration over os.environ.items
841 # add a new key in os.environ mapping
842 os.environ[new_key] = "test_environ_iteration"
846 self.assertEqual(os.environ[new_key], "test_environ_iteration")
848 del os.environ[new_key]
851 self._test_environ_iteration(os.environ)
854 self._test_environ_iteration(os.environ.items())
857 self._test_environ_iteration(os.environ.values())
861 """Tests for os.walk()."""
863 # Wrapper to hide minor differences between os.walk and os.fwalk
868 return os.walk(top, **kwargs)
871 join = os.path.join
908 os.makedirs(self.sub11_path)
909 os.makedirs(sub2_path)
910 os.makedirs(sub21_path)
911 os.makedirs(t2_path)
918 os.symlink(os.path.abspath(t2_path), self.link_path)
919 os.symlink('broken', broken_link_path, True)
920 os.symlink(join('tmp3', 'broken'), broken_link2_path, True)
921 os.symlink(join('SUB21', 'tmp5'), broken_link3_path, True)
928 os.chmod(sub21_path, 0)
930 os.listdir(sub21_path)
932 self.addCleanup(os.chmod, sub21_path, stat.S_IRWXU)
934 os.chmod(sub21_path, stat.S_IRWXU)
935 os.unlink(tmp5_path)
936 os.rmdir(sub21_path)
1020 path1 = os.path.join(root, dir1)
1021 path1new = os.path.join(root, dir1 + '.new')
1022 os.rename(path1, path1new)
1030 self.assertIn(os.path.join(root, dir2), roots)
1032 os.rename(path1new, path1)
1035 @unittest.skipUnless(hasattr(os, 'fwalk'), "Test needs os.fwalk()")
1037 """Tests for os.fwalk()."""
1044 return os.fwalk(*args, **kwargs)
1057 for root, dirs, files in os.walk(**walk_kwargs):
1070 fd = os.open(".", os.O_RDONLY)
1076 os.close(fd)
1084 os.fstat(rootfd)
1086 os.stat(rootfd)
1088 self.assertEqual(set(os.listdir(rootfd)), set(dirs) | set(files))
1094 minfd = os.dup(1)
1095 os.close(minfd)
1099 newfd = os.dup(1)
1100 self.addCleanup(os.close, newfd)
1104 """Tests for os.walk() with bytes."""
1108 for broot, bdirs, bfiles in os.walk(os.fsencode(top), **kwargs):
1109 root = os.fsdecode(broot)
1110 dirs = list(map(os.fsdecode, bdirs))
1111 files = list(map(os.fsdecode, bfiles))
1113 bdirs[:] = list(map(os.fsencode, dirs))
1114 bfiles[:] = list(map(os.fsencode, files))
1116 @unittest.skipUnless(hasattr(os, 'fwalk'), "Test needs os.fwalk()")
1118 """Tests for os.walk() with bytes."""
1120 for broot, bdirs, bfiles, topfd in os.fwalk(os.fsencode(top), *args, **kwargs):
1121 root = os.fsdecode(broot)
1122 dirs = list(map(os.fsdecode, bdirs))
1123 files = list(map(os.fsdecode, bfiles))
1125 bdirs[:] = list(map(os.fsencode, dirs))
1126 bfiles[:] = list(map(os.fsencode, files))
1131 os.mkdir(support.TESTFN)
1135 path = os.path.join(base, 'dir1', 'dir2', 'dir3')
1136 os.makedirs(path) # Should work
1137 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
1138 os.makedirs(path)
1141 self.assertRaises(OSError, os.makedirs, os.curdir)
1142 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
1143 os.makedirs(path)
1144 path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
1146 os.makedirs(path)
1151 parent = os.path.join(base, 'dir1')
1152 path = os.path.join(parent, 'dir2')
1153 os.makedirs(path, 0o555)
1154 self.assertTrue(os.path.exists(path))
1155 self.assertTrue(os.path.isdir(path))
1156 if os.name != 'nt':
1157 self.assertEqual(os.stat(path).st_mode & 0o777, 0o555)
1158 self.assertEqual(os.stat(parent).st_mode & 0o777, 0o775)
1161 path = os.path.join(support.TESTFN, 'dir1')
1163 old_mask = os.umask(0o022)
1164 os.makedirs(path, mode)
1165 self.assertRaises(OSError, os.makedirs, path, mode)
1166 self.assertRaises(OSError, os.makedirs, path, mode, exist_ok=False)
1167 os.makedirs(path, 0o776, exist_ok=True)
1168 os.makedirs(path, mode=mode, exist_ok=True)
1169 os.umask(old_mask)
1172 os.makedirs(os.path.abspath('/'), exist_ok=True)
1175 path = os.path.join(support.TESTFN, 'dir1')
1178 old_mask = os.umask(0o022)
1181 os.lstat(support.TESTFN).st_mode)
1183 os.chmod(support.TESTFN, existing_testfn_mode | S_ISGID)
1186 if (os.lstat(support.TESTFN).st_mode & S_ISGID != S_ISGID):
1188 # The os should apply S_ISGID from the parent dir for us, but
1190 os.makedirs(path, mode | S_ISGID)
1193 os.makedirs(path, mode, exist_ok=True)
1195 os.chmod(path, stat.S_IMODE(os.lstat(path).st_mode) & ~S_ISGID)
1197 os.makedirs(path, mode | S_ISGID, exist_ok=True)
1199 os.umask(old_mask)
1203 path = os.path.join(support.TESTFN, 'dir1')
1207 self.assertRaises(OSError, os.makedirs, path)
1208 self.assertRaises(OSError, os.makedirs, path, exist_ok=False)
1209 self.assertRaises(OSError, os.makedirs, path, exist_ok=True)
1210 os.remove(path)
1213 path = os.path.join(support.TESTFN, 'dir1', 'dir2', 'dir3',
1218 while not os.path.exists(path) and path != support.TESTFN:
1219 path = os.path.dirname(path)
1221 os.removedirs(path)
1224 @unittest.skipUnless(hasattr(os, 'chown'), "Test needs chown")
1229 os.mkdir(support.TESTFN)
1232 stat = os.stat(support.TESTFN)
1236 self.assertRaises(TypeError, os.chown, support.TESTFN, value, gid)
1237 self.assertRaises(TypeError, os.chown, support.TESTFN, uid, value)
1238 self.assertIsNone(os.chown(support.TESTFN, uid, gid))
1239 self.assertIsNone(os.chown(support.TESTFN, -1, -1))
1244 uid = os.stat(support.TESTFN).st_uid
1245 os.chown(support.TESTFN, uid, gid_1)
1246 gid = os.stat(support.TESTFN).st_gid
1248 os.chown(support.TESTFN, uid, gid_2)
1249 gid = os.stat(support.TESTFN).st_gid
1256 gid = os.stat(support.TESTFN).st_gid
1257 os.chown(support.TESTFN, uid_1, gid)
1258 uid = os.stat(support.TESTFN).st_uid
1260 os.chown(support.TESTFN, uid_2, gid)
1261 uid = os.stat(support.TESTFN).st_uid
1268 gid = os.stat(support.TESTFN).st_gid
1270 os.chown(support.TESTFN, uid_1, gid)
1271 os.chown(support.TESTFN, uid_2, gid)
1275 os.rmdir(support.TESTFN)
1280 os.makedirs(support.TESTFN)
1286 dira = os.path.join(support.TESTFN, 'dira')
1287 os.mkdir(dira)
1288 dirb = os.path.join(dira, 'dirb')
1289 os.mkdir(dirb)
1290 os.removedirs(dirb)
1291 self.assertFalse(os.path.exists(dirb))
1292 self.assertFalse(os.path.exists(dira))
1293 self.assertFalse(os.path.exists(support.TESTFN))
1296 dira = os.path.join(support.TESTFN, 'dira')
1297 os.mkdir(dira)
1298 dirb = os.path.join(dira, 'dirb')
1299 os.mkdir(dirb)
1300 create_file(os.path.join(dira, 'file.txt'))
1301 os.removedirs(dirb)
1302 self.assertFalse(os.path.exists(dirb))
1303 self.assertTrue(os.path.exists(dira))
1304 self.assertTrue(os.path.exists(support.TESTFN))
1307 dira = os.path.join(support.TESTFN, 'dira')
1308 os.mkdir(dira)
1309 dirb = os.path.join(dira, 'dirb')
1310 os.mkdir(dirb)
1311 create_file(os.path.join(dirb, 'file.txt'))
1313 os.removedirs(dirb)
1314 self.assertTrue(os.path.exists(dirb))
1315 self.assertTrue(os.path.exists(dira))
1316 self.assertTrue(os.path.exists(support.TESTFN))
1321 with open(os.devnull, 'wb', 0) as f:
1324 with open(os.devnull, 'rb') as f:
1330 self.assertEqual(len(os.urandom(0)), 0)
1331 self.assertEqual(len(os.urandom(1)), 1)
1332 self.assertEqual(len(os.urandom(10)), 10)
1333 self.assertEqual(len(os.urandom(100)), 100)
1334 self.assertEqual(len(os.urandom(1000)), 1000)
1337 data1 = os.urandom(16)
1339 data2 = os.urandom(16)
1344 'import os, sys',
1345 'data = os.urandom(%s)' % count,
1359 @unittest.skipUnless(hasattr(os, 'getrandom'), 'need os.getrandom()')
1364 os.getrandom(1)
1374 data = os.getrandom(16)
1379 empty = os.getrandom(0)
1383 self.assertTrue(hasattr(os, 'GRND_RANDOM'))
1385 # Don't test os.getrandom(1, os.GRND_RANDOM) to not consume the rare
1391 os.getrandom(1, os.GRND_NONBLOCK)
1397 data1 = os.getrandom(16)
1398 data2 = os.getrandom(16)
1402 # os.urandom() doesn't use a file descriptor when it is implemented with the
1410 "os.random() does not use a file descriptor")
1417 # test suite would crash; this actually happened on the OS X Tiger
1421 import os
1427 os.urandom(16)
1439 import os
1442 os.urandom(4)
1444 os.closerange(3, 256)
1445 sys.stdout.buffer.write(os.urandom(4))
1456 import os
1459 os.urandom(4)
1463 os.close(fd)
1469 os.closerange(3, 256)
1476 os.dup2(new_fd, fd)
1477 sys.stdout.buffer.write(os.urandom(4))
1478 sys.stdout.buffer.write(os.urandom(4))
1508 orig_execv = os.execv
1509 orig_execve = os.execve
1510 orig_defpath = os.defpath
1511 os.execv = mock_execv
1512 os.execve = mock_execve
1514 os.defpath = defpath
1517 os.execv = orig_execv
1518 os.execve = orig_execve
1519 os.defpath = orig_defpath
1526 self.assertRaises(OSError, os.execvpe, 'no such app-',
1530 self.assertRaises(ValueError, os.execv, 'notepad', ())
1531 self.assertRaises(ValueError, os.execv, 'notepad', [])
1532 self.assertRaises(ValueError, os.execv, 'notepad', ('',))
1533 self.assertRaises(ValueError, os.execv, 'notepad', [''])
1536 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
1537 self.assertRaises(ValueError, os.execvpe, 'notepad', [], {})
1538 self.assertRaises(ValueError, os.execvpe, 'notepad', [''], {})
1540 @unittest.skipUnless(hasattr(os, '_execvpe'),
1541 "No internal os._execvpe function to test.")
1543 program_path = os.sep + 'absolutepath'
1546 fullpath = os.path.join(os.fsencode(program_path), program)
1552 fullpath = os.path.join(program_path, program)
1553 if os.name != "nt":
1554 native_fullpath = os.fsencode(fullpath)
1559 # test os._execvpe() with an absolute path
1562 os._execvpe, fullpath, arguments)
1566 # test os._execvpe() with a relative path:
1567 # os.get_exec_path() returns defpath
1570 os._execvpe, program, arguments, env=env)
1575 # test os._execvpe() with a relative path:
1576 # os.get_exec_path() reads the 'PATH' variable
1584 os._execvpe, program, arguments, env=env_path)
1591 if os.name != "nt":
1598 newenv = os.environ.copy()
1601 os.execve(args[0], args, newenv)
1604 newenv = os.environ.copy()
1607 os.execve(args[0], args, newenv)
1610 newenv = os.environ.copy()
1613 os.execve(args[0], args, newenv)
1619 os.execve('', ['arg'], {})
1630 os.stat(support.TESTFN)
1635 self.fail("file %s must not exist; os.stat failed with %s"
1641 self.assertRaises(OSError, os.rename, support.TESTFN, support.TESTFN+".bak")
1644 self.assertRaises(OSError, os.remove, support.TESTFN)
1647 self.assertRaises(OSError, os.chdir, support.TESTFN)
1653 self.assertRaises(OSError, os.mkdir, support.TESTFN)
1656 self.assertRaises(OSError, os.utime, support.TESTFN, None)
1659 self.assertRaises(OSError, os.chmod, support.TESTFN, 0)
1669 if hasattr(os, f):
1670 self.check(getattr(os, f))
1684 @unittest.skipUnless(hasattr(os, 'isatty'), 'test needs os.isatty()')
1686 self.assertEqual(os.isatty(support.make_bad_fd()), False)
1688 @unittest.skipUnless(hasattr(os, 'closerange'), 'test needs os.closerange()')
1694 try: os.fstat(fd+i)
1702 self.assertEqual(os.closerange(fd, fd + i-1), None)
1704 @unittest.skipUnless(hasattr(os, 'dup2'), 'test needs os.dup2()')
1706 self.check(os.dup2, 20)
1708 @unittest.skipUnless(hasattr(os, 'fchmod'), 'test needs os.fchmod()')
1710 self.check(os.fchmod, 0)
1712 @unittest.skipUnless(hasattr(os, 'fchown'), 'test needs os.fchown()')
1714 self.check(os.fchown, -1, -1)
1716 @unittest.skipUnless(hasattr(os, 'fpathconf'), 'test needs os.fpathconf()')
1718 self.check(os.pathconf, "PC_NAME_MAX")
1719 self.check(os.fpathconf, "PC_NAME_MAX")
1721 @unittest.skipUnless(hasattr(os, 'ftruncate'), 'test needs os.ftruncate()')
1723 self.check(os.truncate, 0)
1724 self.check(os.ftruncate, 0)
1726 @unittest.skipUnless(hasattr(os, 'lseek'), 'test needs os.lseek()')
1728 self.check(os.lseek, 0, 0)
1730 @unittest.skipUnless(hasattr(os, 'read'), 'test needs os.read()')
1732 self.check(os.read, 1)
1734 @unittest.skipUnless(hasattr(os, 'readv'), 'test needs os.readv()')
1737 self.check(os.readv, [buf])
1739 @unittest.skipUnless(hasattr(os, 'tcsetpgrp'), 'test needs os.tcsetpgrp()')
1741 self.check(os.tcsetpgrp, 0)
1743 @unittest.skipUnless(hasattr(os, 'write'), 'test needs os.write()')
1745 self.check(os.write, b" ")
1747 @unittest.skipUnless(hasattr(os, 'writev'), 'test needs os.writev()')
1749 self.check(os.writev, [b'abc'])
1752 self.check(os.get_inheritable)
1753 self.check(os.set_inheritable, True)
1755 @unittest.skipUnless(hasattr(os, 'get_blocking'),
1756 'needs os.get_blocking() and os.set_blocking()')
1758 self.check(os.get_blocking)
1759 self.check(os.set_blocking, True)
1765 self.file2 = os.path.join(support.TESTFN + "2")
1769 if os.path.exists(file):
1770 os.unlink(file)
1776 os.link(file1, file2)
1778 self.skipTest('os.link(): %s' % e)
1780 self.assertTrue(os.path.sameopenfile(f1.fileno(), f2.fileno()))
1791 os.fsencode("\xf1")
1805 @unittest.skipUnless(hasattr(os, 'setuid'), 'test needs os.setuid()')
1807 if os.getuid() != 0:
1808 self.assertRaises(OSError, os.setuid, 0)
1809 self.assertRaises(TypeError, os.setuid, 'not an int')
1810 self.assertRaises(OverflowError, os.setuid, self.UID_OVERFLOW)
1812 @unittest.skipUnless(hasattr(os, 'setgid'), 'test needs os.setgid()')
1814 if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
1815 self.assertRaises(OSError, os.setgid, 0)
1816 self.assertRaises(TypeError, os.setgid, 'not an int')
1817 self.assertRaises(OverflowError, os.setgid, self.GID_OVERFLOW)
1819 @unittest.skipUnless(hasattr(os, 'seteuid'), 'test needs os.seteuid()')
1821 if os.getuid() != 0:
1822 self.assertRaises(OSError, os.seteuid, 0)
1823 self.assertRaises(TypeError, os.setegid, 'not an int')
1824 self.assertRaises(OverflowError, os.seteuid, self.UID_OVERFLOW)
1826 @unittest.skipUnless(hasattr(os, 'setegid'), 'test needs os.setegid()')
1828 if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
1829 self.assertRaises(OSError, os.setegid, 0)
1830 self.assertRaises(TypeError, os.setegid, 'not an int')
1831 self.assertRaises(OverflowError, os.setegid, self.GID_OVERFLOW)
1833 @unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
1835 if os.getuid() != 0:
1836 self.assertRaises(OSError, os.setreuid, 0, 0)
1837 self.assertRaises(TypeError, os.setreuid, 'not an int', 0)
1838 self.assertRaises(TypeError, os.setreuid, 0, 'not an int')
1839 self.assertRaises(OverflowError, os.setreuid, self.UID_OVERFLOW, 0)
1840 self.assertRaises(OverflowError, os.setreuid, 0, self.UID_OVERFLOW)
1842 @unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
1848 'import os,sys;os.setreuid(-1,-1);sys.exit(0)'])
1850 @unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
1852 if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
1853 self.assertRaises(OSError, os.setregid, 0, 0)
1854 self.assertRaises(TypeError, os.setregid, 'not an int', 0)
1855 self.assertRaises(TypeError, os.setregid, 0, 'not an int')
1856 self.assertRaises(OverflowError, os.setregid, self.GID_OVERFLOW, 0)
1857 self.assertRaises(OverflowError, os.setregid, 0, self.GID_OVERFLOW)
1859 @unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
1865 'import os,sys;os.setregid(-1,-1);sys.exit(0)'])
1876 self.bdir = os.fsencode(self.dir)
1881 fn = os.fsencode(fn)
1894 os.mkdir(self.dir)
1897 support.create_empty_file(os.path.join(self.bdir, fn))
1898 fn = os.fsdecode(fn)
1911 found = set(os.listdir(self.dir))
1914 current_directory = os.getcwd()
1916 os.chdir(os.sep)
1917 self.assertEqual(set(os.listdir()), set(os.listdir(os.sep)))
1919 os.chdir(current_directory)
1923 f = open(os.path.join(self.dir, fn), 'rb')
1926 @unittest.skipUnless(hasattr(os, 'statvfs'),
1927 "need os.statvfs()")
1932 fullname = os.path.join(self.dir, fn)
1933 os.statvfs(fullname)
1937 os.stat(os.path.join(self.dir, fn))
1944 # becomes ready, send *sig* via os.kill to the subprocess and check
1992 os.kill(proc.pid, sig)
2000 # os.kill on Windows can take an int which gets set as the exit code
2009 os.path.join(os.path.dirname(__file__),
2021 os.kill(proc.pid, signal.SIGINT)
2023 os.kill(proc.pid, event)
2029 os.kill(proc.pid, signal.SIGINT)
2063 dir_path = os.path.join(support.TESTFN, dir_name)
2065 file_path = os.path.join(support.TESTFN, file_name)
2066 os.makedirs(dir_path)
2079 sorted(os.listdir(support.TESTFN)),
2084 sorted(os.listdir(os.fsencode(support.TESTFN))),
2085 [os.fsencode(path) for path in self.created_paths])
2091 path = '\\\\?\\' + os.path.abspath(support.TESTFN)
2093 sorted(os.listdir(path)),
2097 path = b'\\\\?\\' + os.fsencode(os.path.abspath(support.TESTFN))
2099 sorted(os.listdir(path)),
2100 [os.fsencode(path) for path in self.created_paths])
2107 filelink_target = os.path.abspath(__file__)
2109 dirlink_target = os.path.dirname(filelink_target)
2113 assert os.path.exists(self.dirlink_target)
2114 assert os.path.exists(self.filelink_target)
2115 assert not os.path.exists(self.dirlink)
2116 assert not os.path.exists(self.filelink)
2117 assert not os.path.exists(self.missing_link)
2120 if os.path.exists(self.filelink):
2121 os.remove(self.filelink)
2122 if os.path.exists(self.dirlink):
2123 os.rmdir(self.dirlink)
2124 if os.path.lexists(self.missing_link):
2125 os.remove(self.missing_link)
2128 os.symlink(self.dirlink_target, self.dirlink)
2129 self.assertTrue(os.path.exists(self.dirlink))
2130 self.assertTrue(os.path.isdir(self.dirlink))
2131 self.assertTrue(os.path.islink(self.dirlink))
2135 os.symlink(self.filelink_target, self.filelink)
2136 self.assertTrue(os.path.exists(self.filelink))
2137 self.assertTrue(os.path.isfile(self.filelink))
2138 self.assertTrue(os.path.islink(self.filelink))
2144 if os.path.lexists(linkname):
2145 os.remove(linkname)
2147 assert not os.path.exists(target)
2149 os.symlink(target, linkname, target_is_dir)
2153 # For compatibility with Unix, os.remove will check the
2156 os.remove(self.missing_link)
2162 self.assertTrue(os.path.isdir(self.missing_link))
2168 os.rmdir(self.missing_link)
2171 self.assertEqual(os.stat(link), os.stat(target))
2172 self.assertNotEqual(os.lstat(link), os.stat(link))
2174 bytes_link = os.fsencode(link)
2175 self.assertEqual(os.stat(bytes_link), os.stat(target))
2176 self.assertNotEqual(os.lstat(bytes_link), os.stat(bytes_link))
2179 level1 = os.path.abspath(support.TESTFN)
2180 level2 = os.path.join(level1, "level2")
2181 level3 = os.path.join(level2, "level3")
2184 os.mkdir(level1)
2185 os.mkdir(level2)
2186 os.mkdir(level3)
2188 file1 = os.path.abspath(os.path.join(level1, "file1"))
2191 orig_dir = os.getcwd()
2193 os.chdir(level2)
2194 link = os.path.join(level2, "link")
2195 os.symlink(os.path.relpath(file1), "link")
2196 self.assertIn("link", os.listdir(os.getcwd()))
2198 # Check os.stat calls from the same dir as the link
2199 self.assertEqual(os.stat(file1), os.stat("link"))
2201 # Check os.stat calls from a dir below the link
2202 os.chdir(level1)
2203 self.assertEqual(os.stat(file1),
2204 os.stat(os.path.relpath(link)))
2206 # Check os.stat calls from a dir above the link
2207 os.chdir(level3)
2208 self.assertEqual(os.stat(file1),
2209 os.stat(os.path.relpath(link)))
2211 os.chdir(orig_dir)
2213 @unittest.skipUnless(os.path.lexists(r'C:\Users\All Users')
2214 and os.path.exists(r'C:\ProgramData'),
2217 # os.symlink() calls CreateSymbolicLink, which creates
2225 target = os.readlink(r'C:\Users\All Users')
2226 self.assertTrue(os.path.samefile(target, r'C:\ProgramData'))
2233 path = os.path.join(*[segment] * 10)
2244 os.symlink(src, dest)
2249 os.remove(dest)
2254 os.symlink(os.fsencode(src), os.fsencode(dest))
2259 os.remove(dest)
2266 junction_target = os.path.dirname(os.path.abspath(__file__))
2269 assert os.path.exists(self.junction_target)
2270 assert not os.path.exists(self.junction)
2273 if os.path.exists(self.junction):
2274 # os.rmdir delegates to Windows' RemoveDirectoryW,
2276 os.rmdir(self.junction)
2280 self.assertTrue(os.path.exists(self.junction))
2281 self.assertTrue(os.path.isdir(self.junction))
2284 self.assertFalse(os.path.islink(self.junction))
2288 self.assertTrue(os.path.exists(self.junction))
2290 os.unlink(self.junction)
2291 self.assertFalse(os.path.exists(self.junction))
2339 tmp = os.stat(name)
2360 os.makedirs('base/some_dir')
2377 src = os.path.join('base', 'some_link')
2378 os.symlink('some_dir', src)
2379 assert os.path.isdir(src)
2384 self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff')
2385 self.assertEqual(os.fsdecode('abc\u0141'), 'abc\u0141')
2391 bytesfn = os.fsencode(fn)
2394 self.assertEqual(os.fsdecode(bytesfn), fn)
2402 self.assertIsNone(os.device_encoding(123456))
2404 @unittest.skipUnless(os.isatty(0) and (sys.platform.startswith('win') or
2408 encoding = os.device_encoding(0)
2414 @unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
2417 'import os; print(os.getppid())'],
2421 self.assertEqual(int(stdout), os.getpid())
2426 pid = os.spawnv(os.P_NOWAIT, FakePath(args[0]), args)
2427 status = os.waitpid(pid, 0)
2441 self.env = dict(os.environ)
2445 # read the variable from os.environ to check that it exists
2446 code = ('import sys, os; magic = os.environ[%r]; sys.exit(%s)'
2454 args = [os.fsencode(a) for a in args]
2455 self.env = {os.fsencode(k): os.fsencode(v)
2463 exitcode = os.spawnl(os.P_WAIT, args[0], *args)
2469 exitcode = os.spawnle(os.P_WAIT, args[0], *args, self.env)
2475 exitcode = os.spawnlp(os.P_WAIT, args[0], *args)
2481 exitcode = os.spawnlpe(os.P_WAIT, args[0], *args, self.env)
2487 exitcode = os.spawnv(os.P_WAIT, args[0], args)
2493 exitcode = os.spawnve(os.P_WAIT, args[0], args, self.env)
2499 exitcode = os.spawnvp(os.P_WAIT, args[0], args)
2505 exitcode = os.spawnvpe(os.P_WAIT, args[0], args, self.env)
2511 pid = os.spawnv(os.P_NOWAIT, args[0], args)
2512 result = os.waitpid(pid, 0)
2515 if hasattr(os, 'WIFEXITED'):
2516 self.assertTrue(os.WIFEXITED(status))
2517 self.assertEqual(os.WEXITSTATUS(status), self.exitcode)
2525 exitcode = os.spawnve(os.P_WAIT, args[0], args, self.env)
2531 self.assertRaises(ValueError, os.spawnl, os.P_NOWAIT, args[0])
2532 self.assertRaises(ValueError, os.spawnl, os.P_NOWAIT, args[0], '')
2537 self.assertRaises(ValueError, os.spawnle, os.P_NOWAIT, args[0], {})
2538 self.assertRaises(ValueError, os.spawnle, os.P_NOWAIT, args[0], '', {})
2543 self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], ())
2544 self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], [])
2545 self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], ('',))
2546 self.assertRaises(ValueError, os.spawnv, os.P_NOWAIT, args[0], [''])
2551 self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], (), {})
2552 self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [], {})
2553 self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], ('',), {})
2554 self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [''], {})
2560 newenv = os.environ.copy()
2563 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
2570 newenv = os.environ.copy()
2573 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
2580 newenv = os.environ.copy()
2583 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
2593 fp.write('import sys, os\n'
2594 'if os.getenv("FRUIT") != "orange=lemon":\n'
2597 newenv = os.environ.copy()
2599 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
2604 self._test_invalid_env(os.spawnve)
2608 self._test_invalid_env(os.spawnvpe)
2614 @unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin")
2617 user_name = os.getlogin()
2621 @unittest.skipUnless(hasattr(os, 'getpriority') and hasattr(os, 'setpriority'),
2622 "needs os.getpriority and os.setpriority")
2624 """Tests for os.getpriority() and os.setpriority()."""
2628 base = os.getpriority(os.PRIO_PROCESS, os.getpid())
2629 os.setpriority(os.PRIO_PROCESS, os.getpid(), base + 1)
2631 new_prio = os.getpriority(os.PRIO_PROCESS, os.getpid())
2639 os.setpriority(os.PRIO_PROCESS, os.getpid(), base)
2731 @unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()")
2778 return os.sendfile(*args, **kwargs)
2838 sent = os.sendfile(self.sockno, self.fileno, offset, 4096)
2853 os.sendfile(self.sockno, self.fileno, -1, 4096)
2858 os.sendfile(out=self.sockno, offset=0, count=4096,
2861 os.sendfile(self.sockno, self.fileno, offset=0, count=4096,
2870 sent = os.sendfile(self.sockno, self.fileno, 0, 4096,
2900 os.sendfile(self.sockno, f.fileno(), 0, 5,
2912 os.sendfile(self.sockno, self.fileno, 0, 0,
2921 os.sendfile(self.sockno, self.fileno, 0, 0,
2926 @unittest.skipUnless(hasattr(os, 'SF_NODISKIO'),
2927 'test needs os.SF_NODISKIO')
2930 os.sendfile(self.sockno, self.fileno, 0, 4096,
2931 flags=os.SF_NODISKIO)
2938 if not hasattr(os, "setxattr"):
2944 os.setxattr(fp.fileno(), b"user.test", b"")
2976 setxattr(fn, s("user.test"), b"hello", os.XATTR_REPLACE, **kwargs)
2980 setxattr(fn, s("user.test"), b"bye", os.XATTR_CREATE, **kwargs)
2984 setxattr(fn, s("user.test2"), b"bye", os.XATTR_REPLACE, **kwargs)
2987 setxattr(fn, s("user.test2"), b"foo", os.XATTR_CREATE, **kwargs)
3011 self._check_xattrs_str(os.fsencode, *args, **kwargs)
3015 self._check_xattrs(os.getxattr, os.setxattr, os.removexattr,
3016 os.listxattr)
3019 self._check_xattrs(os.getxattr, os.setxattr, os.removexattr,
3020 os.listxattr, follow_symlinks=False)
3025 return os.getxattr(fp.fileno(), *args)
3028 os.setxattr(fp.fileno(), *args)
3031 os.removexattr(fp.fileno(), *args)
3034 return os.listxattr(fp.fileno(), *args)
3038 @unittest.skipUnless(hasattr(os, 'get_terminal_size'), "requires os.get_terminal_size")
3047 size = os.get_terminal_size()
3073 actual = os.get_terminal_size(sys.__stdin__.fileno())
3099 encoded = os.fsencode(support.TESTFN)
3108 (self.filenames, os.chdir,),
3109 (self.filenames, os.chmod, 0o777),
3110 (self.filenames, os.lstat,),
3111 (self.filenames, os.open, os.O_RDONLY),
3112 (self.filenames, os.rmdir,),
3113 (self.filenames, os.stat,),
3114 (self.filenames, os.unlink,),
3118 (self.bytes_filenames, os.rename, b"dst"),
3119 (self.bytes_filenames, os.replace, b"dst"),
3120 (self.unicode_filenames, os.rename, "dst"),
3121 (self.unicode_filenames, os.replace, "dst"),
3122 (self.unicode_filenames, os.listdir, ),
3126 (self.filenames, os.listdir,),
3127 (self.filenames, os.rename, "dst"),
3128 (self.filenames, os.replace, "dst"),
3130 if hasattr(os, "chown"):
3131 funcs.append((self.filenames, os.chown, 0, 0))
3132 if hasattr(os, "lchown"):
3133 funcs.append((self.filenames, os.lchown, 0, 0))
3134 if hasattr(os, "truncate"):
3135 funcs.append((self.filenames, os.truncate, 0))
3136 if hasattr(os, "chflags"):
3137 funcs.append((self.filenames, os.chflags, 0))
3138 if hasattr(os, "lchflags"):
3139 funcs.append((self.filenames, os.lchflags, 0))
3140 if hasattr(os, "chroot"):
3141 funcs.append((self.filenames, os.chroot,))
3142 if hasattr(os, "link"):
3144 funcs.append((self.bytes_filenames, os.link, b"dst"))
3145 funcs.append((self.unicode_filenames, os.link, "dst"))
3147 funcs.append((self.filenames, os.link, "dst"))
3148 if hasattr(os, "listxattr"):
3150 (self.filenames, os.listxattr,),
3151 (self.filenames, os.getxattr, "user.test"),
3152 (self.filenames, os.setxattr, "user.test", b'user'),
3153 (self.filenames, os.removexattr, "user.test"),
3155 if hasattr(os, "lchmod"):
3156 funcs.append((self.filenames, os.lchmod, 0o777))
3157 if hasattr(os, "readlink"):
3159 funcs.append((self.unicode_filenames, os.readlink,))
3161 funcs.append((self.filenames, os.readlink,))
3181 cpus = os.cpu_count()
3191 fd = os.open(__file__, os.O_RDONLY)
3192 self.addCleanup(os.close, fd)
3193 self.assertEqual(os.get_inheritable(fd), False)
3195 os.set_inheritable(fd, True)
3196 self.assertEqual(os.get_inheritable(fd), True)
3200 fd = os.open(__file__, os.O_RDONLY)
3201 self.addCleanup(os.close, fd)
3202 self.assertEqual(os.get_inheritable(fd), False)
3209 self.assertEqual(os.get_inheritable(fd), True)
3213 fd = os.open(__file__, os.O_RDONLY)
3214 self.addCleanup(os.close, fd)
3218 os.set_inheritable(fd, True)
3223 fd = os.open(__file__, os.O_RDONLY)
3224 self.addCleanup(os.close, fd)
3225 self.assertEqual(os.get_inheritable(fd), False)
3227 @unittest.skipUnless(hasattr(os, 'pipe'), "need os.pipe()")
3229 rfd, wfd = os.pipe()
3230 self.addCleanup(os.close, rfd)
3231 self.addCleanup(os.close, wfd)
3232 self.assertEqual(os.get_inheritable(rfd), False)
3233 self.assertEqual(os.get_inheritable(wfd), False)
3236 fd1 = os.open(__file__, os.O_RDONLY)
3237 self.addCleanup(os.close, fd1)
3239 fd2 = os.dup(fd1)
3240 self.addCleanup(os.close, fd2)
3241 self.assertEqual(os.get_inheritable(fd2), False)
3243 @unittest.skipUnless(hasattr(os, 'dup2'), "need os.dup2()")
3245 fd = os.open(__file__, os.O_RDONLY)
3246 self.addCleanup(os.close, fd)
3249 fd2 = os.open(__file__, os.O_RDONLY)
3250 self.addCleanup(os.close, fd2)
3251 self.assertEqual(os.dup2(fd, fd2), fd2)
3252 self.assertTrue(os.get_inheritable(fd2))
3255 fd3 = os.open(__file__, os.O_RDONLY)
3256 self.addCleanup(os.close, fd3)
3257 self.assertEqual(os.dup2(fd, fd3, inheritable=False), fd3)
3258 self.assertFalse(os.get_inheritable(fd3))
3260 @unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()")
3262 master_fd, slave_fd = os.openpty()
3263 self.addCleanup(os.close, master_fd)
3264 self.addCleanup(os.close, slave_fd)
3265 self.assertEqual(os.get_inheritable(master_fd), False)
3266 self.assertEqual(os.get_inheritable(slave_fd), False)
3275 ('access', False, (os.F_OK,), None),
3278 ('open', False, (0,), getattr(os, 'close', None)),
3283 if os.name == 'nt':
3288 fd = os.open(FakePath(str_filename), os.O_WRONLY|os.O_CREAT)
3290 self.addCleanup(os.close, fd)
3298 fn = getattr(os, name)
3322 'os.PathLike'):
3328 os.stat(FakePath(2))
3330 os.stat(FakePath(2.34))
3332 os.stat(FakePath(object()))
3335 @unittest.skipUnless(hasattr(os, 'get_blocking'),
3336 'needs os.get_blocking() and os.set_blocking()')
3339 fd = os.open(__file__, os.O_RDONLY)
3340 self.addCleanup(os.close, fd)
3341 self.assertEqual(os.get_blocking(fd), True)
3343 os.set_blocking(fd, False)
3344 self.assertEqual(os.get_blocking(fd), False)
3346 os.set_blocking(fd, True)
3347 self.assertEqual(os.get_blocking(fd), True)
3353 self.assertIn('open', os.__all__)
3354 self.assertIn('walk', os.__all__)
3361 self.path = os.path.realpath(support.TESTFN)
3362 self.bytes_path = os.fsencode(self.path)
3364 os.mkdir(self.path)
3368 filename = os.path.join(path, name)
3374 for entry in os.scandir(self.path))
3392 self.assertIsInstance(entry, os.DirEntry)
3394 self.assertEqual(entry.path, os.path.join(self.path, name))
3396 os.stat(entry.path, follow_symlinks=False).st_ino)
3398 entry_stat = os.stat(entry.path)
3404 os.path.islink(entry.path))
3406 entry_lstat = os.stat(entry.path, follow_symlinks=False)
3414 os.name == 'nt' and not is_symlink)
3417 os.name == 'nt')
3420 link = hasattr(os, 'link')
3423 dirname = os.path.join(self.path, "dir")
3424 os.mkdir(dirname)
3428 os.link(filename, os.path.join(self.path, "link_file.txt"))
3430 self.skipTest('os.link(): %s' % e)
3432 os.symlink(dirname, os.path.join(self.path, "symlink_dir"),
3434 os.symlink(filename, os.path.join(self.path, "symlink_file.txt"))
3462 entries = list(os.scandir(path))
3471 return self.get_entry(os.path.basename(filename))
3475 old_dir = os.getcwd()
3477 os.chdir(self.path)
3481 entries = dict((entry.name, entry) for entry in os.scandir())
3483 [os.path.basename(filename)])
3485 os.chdir(old_dir)
3493 self.assertEqual(os.fspath(entry), os.path.join(self.path, 'file.txt'))
3496 bytes_filename = os.fsencode('bytesfile.txt')
3498 fspath = os.fspath(bytes_entry)
3501 os.path.join(os.fsencode(self.path),bytes_filename))
3504 path = os.path.join(self.path, 'dir')
3506 os.mkdir(path)
3508 os.rmdir(path)
3511 if os.name == 'nt':
3515 if os.name == 'nt':
3527 os.unlink(entry.path)
3531 if os.name == 'nt':
3534 if os.name == 'nt':
3549 os.symlink(filename,
3550 os.path.join(self.path, "symlink.txt"))
3553 os.unlink(filename)
3568 path_bytes = os.fsencode(self.path)
3569 entries = list(os.scandir(path_bytes))
3575 os.fsencode(os.path.join(self.path, 'file.txt')))
3581 path_bytes = cls(os.fsencode(self.path))
3583 entries = list(os.scandir(path_bytes))
3589 os.fsencode(os.path.join(self.path, 'file.txt')))
3593 @unittest.skipUnless(os.listdir in os.supports_fd,
3596 self.assertIn(os.scandir, os.supports_fd)
3600 os.symlink('file.txt', os.path.join(self.path, 'link'))
3603 fd = os.open(self.path, os.O_RDONLY)
3605 with os.scandir(fd) as it:
3609 self.assertEqual(names, os.listdir(fd))
3612 self.assertEqual(os.fspath(entry), entry.name)
3614 if os.stat in os.supports_dir_fd:
3615 st = os.stat(entry.name, dir_fd=fd)
3617 st = os.stat(entry.name, dir_fd=fd, follow_symlinks=False)
3620 os.close(fd)
3623 self.assertRaises(FileNotFoundError, os.scandir, '')
3627 iterator = os.scandir(self.path)
3638 self.assertRaises(TypeError, os.scandir, obj)
3643 iterator = os.scandir(self.path)
3654 with os.scandir(self.path) as iterator:
3662 with os.scandir(self.path) as iterator:
3670 with os.scandir(self.path) as iterator:
3679 iterator = os.scandir(self.path)
3685 iterator = os.scandir(self.path)
3695 fspath = staticmethod(os.fspath)
3710 self.assertEqual(b"path/like/object", os.fsencode(pathlike))
3711 self.assertEqual("path/like/object", os.fsdecode(pathlike))
3715 self.assertTrue(issubclass(FakePath, os.PathLike))
3716 self.assertTrue(isinstance(FakePath('x'), os.PathLike))
3720 for o in int, type, os, vapor():
3740 times = os.times()
3741 self.assertIsInstance(times, os.times_result)
3748 if os.name == 'nt':
3756 if hasattr(os, "_fspath"):
3759 """Explicitly test the pure Python implementation of os.fspath()."""
3761 fspath = staticmethod(os._fspath)