• Home
  • Raw
  • Download

Lines Matching full:os

16 import os
30 _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
130 "test needs os.initgroups()")
142 if os.getuid() != 0:
158 self.assertTrue(posix.statvfs(os.curdir))
189 …@unittest.skipUnless(getattr(os, 'execve', None) in os.supports_fd, "test needs execve() to suppor…
192 fp = os.open(sys.executable, os.O_RDONLY)
194 pid = os.fork()
196 os.chdir(os.path.split(sys.executable)[0])
197 posix.execve(fp, [sys.executable, '-c', 'pass'], os.environ)
201 os.close(fp)
207 pid = os.fork()
209 os.chdir(os.path.split(sys.executable)[0])
210 posix.execve(sys.executable, [sys.executable, '-c', 'pass'], os.environ)
218 os.register_at_fork(lambda: None)
220 os.register_at_fork(before=2)
222 os.register_at_fork(after_in_child="three")
224 os.register_at_fork(after_in_parent=b"Five")
226 os.register_at_fork(before=None)
228 os.register_at_fork(after_in_child=None)
230 os.register_at_fork(after_in_parent=None)
233 os.register_at_fork(before=None, after_in_parent=lambda: 3)
236 os.register_at_fork(before=lambda: None, after_in_child='')
240 import os
242 r, w = os.pipe()
243 fin_r, fin_w = os.pipe()
245 os.register_at_fork(before=lambda: os.write(w, b'A'))
246 os.register_at_fork(after_in_parent=lambda: os.write(w, b'C'))
247 os.register_at_fork(after_in_child=lambda: os.write(w, b'E'))
248 os.register_at_fork(before=lambda: os.write(w, b'B'),
249 after_in_parent=lambda: os.write(w, b'D'),
250 after_in_child=lambda: os.write(w, b'F'))
252 pid = os.fork()
255 os.close(w)
257 os.read(fin_r, 1)
258 os._exit(0)
261 os.close(w)
272 os.write(fin_w, b'!')
278 fd = os.open(os_helper.TESTFN, os.O_WRONLY | os.O_CREAT)
280 os.write(fd, b'test')
281 os.lseek(fd, 0, os.SEEK_SET)
286 os.close(fd)
290 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
292 os.write(fd, b'test')
293 os.lseek(fd, 0, os.SEEK_SET)
298 os.close(fd)
302 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
304 os.write(fd, b'test1tt2t3t5t6t6t8')
309 os.close(fd)
314 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
316 os.write(fd, b'test1tt2t3t5t6t6t8')
318 self.assertEqual(posix.preadv(fd, buf, 3, os.RWF_HIPRI), 10)
331 os.close(fd)
336 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
340 os.preadv(fd, buf, 0)
344 os.close(fd)
348 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
350 os.write(fd, b'test')
351 os.lseek(fd, 0, os.SEEK_SET)
355 os.close(fd)
359 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
361 os.write(fd, b"xx")
362 os.lseek(fd, 0, os.SEEK_SET)
363 n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2)
366 os.lseek(fd, 0, os.SEEK_SET)
369 os.close(fd)
372 @unittest.skipUnless(hasattr(posix, 'os.RWF_SYNC'), "test needs os.RWF_SYNC")
374 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
376 os.write(fd,b"xx")
377 os.lseek(fd, 0, os.SEEK_SET)
378 n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2, os.RWF_SYNC)
381 os.lseek(fd, 0, os.SEEK_SET)
384 os.close(fd)
389 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
392 os.pwritev(fd, [b"x" * 2**16] * 2**15, 0)
395 os.close(fd)
400 fd = os.open(os_helper.TESTFN, os.O_WRONLY | os.O_CREAT)
414 os.close(fd)
429 fd = os.open(os_helper.TESTFN, os.O_RDONLY)
433 os.close(fd)
444 @unittest.skipUnless(os.utime in os.supports_fd, "test needs fd support in os.utime")
447 fd = os.open(os_helper.TESTFN, os.O_RDONLY)
463 os.close(fd)
465 …@unittest.skipUnless(os.utime in os.supports_follow_symlinks, "test needs follow_symlinks support …
482 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
484 n = os.writev(fd, (b'test1', b'tt2', b't3'))
487 os.lseek(fd, 0, os.SEEK_SET)
500 os.close(fd)
505 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
508 os.writev(fd, [b"x" * 2**16] * 2**15)
511 os.close(fd)
515 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
517 os.write(fd, b'test1tt2t3')
518 os.lseek(fd, 0, os.SEEK_SET)
533 os.close(fd)
538 fd = os.open(os_helper.TESTFN, os.O_RDWR | os.O_CREAT)
542 os.readv(fd, buf)
546 os.close(fd)
556 os.close(fd)
578 @unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
582 fd = os.open(os_helper.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
583 self.addCleanup(os.close, fd)
584 self.assertFalse(os.get_inheritable(fd))
589 fd = os.open(os_helper.TESTFN,
590 os.O_WRONLY|os.O_EXLOCK|os.O_CREAT)
591 self.assertRaises(OSError, os.open, os_helper.TESTFN,
592 os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
593 os.close(fd)
596 fd = os.open(os_helper.TESTFN,
597 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
598 self.assertRaises(OSError, os.open, os_helper.TESTFN,
599 os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
600 os.close(fd)
605 fd1 = os.open(os_helper.TESTFN,
606 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
607 fd2 = os.open(os_helper.TESTFN,
608 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
609 os.close(fd2)
610 os.close(fd1)
613 fd = os.open(os_helper.TESTFN,
614 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
615 self.assertRaises(OSError, os.open, os_helper.TESTFN,
616 os.O_RDONLY|os.O_EXLOCK|os.O_NONBLOCK)
617 os.close(fd)
628 'should be string, bytes, os.PathLike or integer, not',
635 self.assertTrue(posix.stat(os.fsencode(os_helper.TESTFN)))
638 'should be string, bytes, os.PathLike or integer, not',
639 posix.stat, bytearray(os.fsencode(os_helper.TESTFN)))
641 'should be string, bytes, os.PathLike or integer, not',
644 'should be string, bytes, os.PathLike or integer, not',
647 'should be string, bytes, os.PathLike or integer, not',
648 posix.stat, list(os.fsencode(os_helper.TESTFN)))
653 fifo_path = os.path.join("/fifos/", os_helper.TESTFN)
724 uid = os.getuid()
725 gid = os.getgid()
779 if 0 not in os.getgroups():
793 os.unlink(os_helper.TESTFN)
801 @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
804 os.unlink(os_helper.TESTFN)
816 @unittest.skipUnless(hasattr(posix, 'lchown'), "test needs os.lchown()")
818 os.unlink(os_helper.TESTFN)
820 os.symlink(_DUMMY_SYMLINK, os_helper.TESTFN)
826 posix.chdir(os.curdir)
830 self.assertIn(os_helper.TESTFN, posix.listdir(os.curdir))
834 # it's the same as listdir(os.curdir).
840 self.assertIn(os.fsencode(os_helper.TESTFN), posix.listdir(b'.'))
846 self.assertIn(os.fsencode(os_helper.TESTFN), names)
850 @unittest.skipUnless(posix.listdir in os.supports_fd,
867 self.assertTrue(posix.access(os_helper.TESTFN, os.R_OK))
883 os.close(reader)
884 os.close(writer)
886 @unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
889 self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
890 self.assertRaises(TypeError, os.pipe2, 0, 0)
892 # try calling with flags = 0, like os.pipe()
893 r, w = os.pipe2(0)
894 os.close(r)
895 os.close(w)
898 r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
899 self.addCleanup(os.close, r)
900 self.addCleanup(os.close, w)
901 self.assertFalse(os.get_inheritable(r))
902 self.assertFalse(os.get_inheritable(w))
903 self.assertFalse(os.get_blocking(r))
904 self.assertFalse(os.get_blocking(w))
906 self.assertRaises(OSError, os.read, r, 1)
910 os.write(w, b'x' * support.PIPE_MAX_SIZE)
915 @unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
920 self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1)
921 self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1)
937 st = os.stat(target_file)
951 new_st = os.stat(target_file)
960 @unittest.skipUnless(hasattr(posix, 'chflags'), 'test needs os.chflags()')
964 @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
970 @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
972 testfn_st = os.stat(os_helper.TESTFN)
977 os.symlink(os_helper.TESTFN, _DUMMY_SYMLINK)
978 dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
994 new_testfn_st = os.stat(os_helper.TESTFN)
995 new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
1004 if os.name == "nt":
1014 os.putenv('FRUIT\0VEGETABLE', 'cabbage')
1016 os.putenv(b'FRUIT\0VEGETABLE', b'cabbage')
1018 os.putenv('FRUIT', 'orange\0VEGETABLE=cabbage')
1020 os.putenv(b'FRUIT', b'orange\0VEGETABLE=cabbage')
1022 os.putenv('FRUIT=ORANGE', 'lemon')
1024 os.putenv(b'FRUIT=ORANGE', b'lemon')
1029 curdir = os.getcwd()
1030 base_path = os.path.abspath(os_helper.TESTFN) + '.getcwd'
1033 os.mkdir(base_path)
1034 os.chdir(base_path)
1043 os.mkdir(dirname)
1047 os.chdir(dirname)
1049 os.getcwd()
1053 os.chdir('..')
1054 os.rmdir(dirname)
1059 os.chdir(curdir)
1064 @unittest.skipUnless(hasattr(os, 'getuid'), "test needs os.getuid()")
1066 user = pwd.getpwuid(os.getuid())[0]
1067 group = pwd.getpwuid(os.getuid())[3]
1071 @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()")
1072 @unittest.skipUnless(hasattr(os, 'popen'), "test needs os.popen()")
1075 with os.popen('id -G 2>/dev/null') as idg:
1086 # Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups()
1093 # 'id -G' and 'os.getgroups()' should return the same
1101 @unittest.skipUnless(hasattr(os, 'waitid_result'), "test needs os.waitid_result")
1103 os.CLD_EXITED
1104 os.CLD_KILLED
1105 os.CLD_DUMPED
1106 os.CLD_TRAPPED
1107 os.CLD_STOPPED
1108 os.CLD_CONTINUED
1143 parent = posix.sched_getscheduler(os.getppid())
1229 @unittest.skipUnless(hasattr(os, 'SEEK_HOLE'),
1230 "test needs an OS that reports file holes")
1233 # if the OS supports it the SEEK_* constants
1236 # os.SEEK_DATA = current position
1237 # os.SEEK_HOLE = end of file position
1245 self.assertEqual(i, os.lseek(fno, i, os.SEEK_DATA))
1246 self.assertLessEqual(size, os.lseek(fno, i, os.SEEK_HOLE))
1247 self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_DATA)
1248 self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_HOLE)
1261 function = getattr(os, name, None)
1272 self.fail("No valid path_error2() test for os." + name)
1282 fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
1285 os.close(fd)
1286 self.assertFalse(os.path.exists(fn))
1287 self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
1288 self.assertFalse(os.path.exists(fn))
1290 self.assertRaises(ValueError, os.stat, fn_with_NUL)
1293 fn = os.fsencode(os_helper.TESTFN)
1300 fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
1303 os.close(fd)
1304 self.assertFalse(os.path.exists(fn))
1305 self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
1306 self.assertFalse(os.path.exists(fn))
1308 self.assertRaises(ValueError, os.stat, fn_with_NUL)
1310 @unittest.skipUnless(hasattr(os, "pidfd_open"), "pidfd_open unavailable")
1313 os.pidfd_open(-1)
1319 os.close(os.pidfd_open(os.getpid(), 0))
1333 fullname = os.path.join(base_dir, name)
1334 assert not os.path.exists(fullname)
1345 … @unittest.skipUnless(os.access in os.supports_dir_fd, "test needs dir_fd support for os.access()")
1348 self.assertTrue(posix.access(name, os.R_OK, dir_fd=dir_fd))
1350 @unittest.skipUnless(os.chmod in os.supports_dir_fd, "test needs dir_fd support in os.chmod()")
1359 @unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd),
1360 "test needs dir_fd support in os.chown()")
1364 posix.chown(name, os.getuid(), os.getgid(), dir_fd=dir_fd)
1366 @unittest.skipUnless(os.stat in os.supports_dir_fd, "test needs dir_fd support in os.stat()")
1386 @unittest.skipUnless(os.utime in os.supports_dir_fd, "test needs dir_fd support in os.utime()")
1410 if os.utime in os.supports_follow_symlinks:
1422 hasattr(os, "link") and os.link in os.supports_dir_fd,
1423 "test needs dir_fd support in os.link()"
1437 @unittest.skipUnless(os.mkdir in os.supports_dir_fd, "test needs dir_fd support in os.mkdir()")
1444 @unittest.skipUnless(hasattr(os, 'mknod')
1445 and (os.mknod in os.supports_dir_fd)
1447 "test requires both stat.S_IFIFO and dir_fd support for os.mknod()")
1463 @unittest.skipUnless(os.open in os.supports_dir_fd, "test needs dir_fd support in os.open()")
1476 @unittest.skipUnless(hasattr(os, 'readlink') and (os.readlink in os.supports_dir_fd),
1477 "test needs dir_fd support in os.readlink()")
1480 os.symlink('symlink', fullname)
1484 … @unittest.skipUnless(os.rename in os.supports_dir_fd, "test needs dir_fd support in os.rename()")
1493 …@unittest.skipUnless(os.symlink in os.supports_dir_fd, "test needs dir_fd support in os.symlink()")
1500 … @unittest.skipUnless(os.unlink in os.supports_dir_fd, "test needs dir_fd support in os.unlink()")
1512 …@unittest.skipUnless(hasattr(os, 'mkfifo') and os.mkfifo in os.supports_dir_fd, "test needs dir_fd…
1576 import os
1578 pidfile.write(str(os.getpid()))
1581 pid = self.spawn_func(args[0], args, os.environ)
1591 os.environ)
1597 pid2, status = os.waitpid(pid, 0)
1605 import os
1607 envfile.write(os.environ['foo'])
1611 {**os.environ, 'foo': 'bar'})
1620 os.environ,
1629 os.environ,
1638 os.environ,
1647 os.environ,
1656 os.environ, resetids=None)
1662 os.environ,
1663 setpgroup=os.getpgrp()
1671 os.environ, setpgroup="023")
1683 os.environ,
1692 os.environ, setsigmask=34)
1696 os.environ, setsigmask=["j"])
1700 os.environ, setsigmask=[signal.NSIG,
1704 rfd, wfd = os.pipe()
1705 self.addCleanup(os.close, rfd)
1707 os.set_inheritable(wfd, True)
1710 import os
1712 sid = os.getsid(0)
1713 os.write(fd, str(sid).encode())
1719 os.environ, setsid=True)
1725 os.close(wfd)
1729 output = os.read(rfd, 100)
1731 parent_sid = os.getsid(os.getpid())
1745 os.environ,
1757 os.environ, setsigdef=34)
1761 os.environ, setsigdef=["j"])
1765 os.environ, setsigdef=[signal.NSIG, signal.NSIG+1])
1771 policy = os.sched_getscheduler(0)
1772 priority = os.sched_get_priority_min(policy)
1774 import os, sys
1775 if os.sched_getscheduler(0) != {policy}:
1777 if os.sched_getparam(0).sched_priority != {priority}:
1782 os.environ,
1783 scheduler=(None, os.sched_param(priority))
1791 policy = os.sched_getscheduler(0)
1792 priority = os.sched_get_priority_min(policy)
1794 import os, sys
1795 if os.sched_getscheduler(0) != {policy}:
1797 if os.sched_getparam(0).sched_priority != {priority}:
1802 os.environ,
1803 scheduler=(policy, os.sched_param(priority))
1809 (os.POSIX_SPAWN_OPEN, 3, os.path.realpath(__file__), os.O_RDONLY, 0),
1810 (os.POSIX_SPAWN_CLOSE, 0),
1811 (os.POSIX_SPAWN_DUP2, 1, 4),
1815 os.environ,
1822 self.spawn_func(args[0], args, os.environ,
1825 self.spawn_func(args[0], args, os.environ,
1828 self.spawn_func(args[0], args, os.environ,
1831 self.spawn_func(args[0], args, os.environ,
1834 self.spawn_func(args[0], args, os.environ,
1835 file_actions=[(os.POSIX_SPAWN_CLOSE,)])
1837 self.spawn_func(args[0], args, os.environ,
1838 file_actions=[(os.POSIX_SPAWN_CLOSE, 1, 2)])
1840 self.spawn_func(args[0], args, os.environ,
1841 file_actions=[(os.POSIX_SPAWN_CLOSE, None)])
1843 self.spawn_func(args[0], args, os.environ,
1844 file_actions=[(os.POSIX_SPAWN_OPEN,
1846 os.O_RDONLY, 0)])
1856 (os.POSIX_SPAWN_OPEN, 1, outfile,
1857 os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
1861 pid = self.spawn_func(args[0], args, os.environ,
1872 import os
1874 os.fstat(0)
1880 pid = self.spawn_func(args[0], args, os.environ,
1881 file_actions=[(os.POSIX_SPAWN_CLOSE, 0)])
1896 (os.POSIX_SPAWN_DUP2, childfile.fileno(), 1),
1899 pid = self.spawn_func(args[0], args, os.environ,
1906 @unittest.skipUnless(hasattr(os, 'posix_spawn'), "test needs os.posix_spawn")
1911 @unittest.skipUnless(hasattr(os, 'posix_spawnp'), "test needs os.posix_spawnp")
1922 program_fullpath = os.path.join(temp_dir, program)
1923 os.symlink(sys.executable, program_fullpath)
1926 path = os.pathsep.join((temp_dir, os.environ['PATH']))
1932 import os
1936 pid = os.posix_spawnp(args[0], args, os.environ)
1941 # Use a subprocess to test os.posix_spawnp() with a modified PATH
1970 self.assertTrue(hasattr(os, "pwritev"), "os.pwritev is not available")
1971 self.assertTrue(hasattr(os, "preadv"), "os.readv is not available")
1974 self.assertFalse(hasattr(os, "pwritev"), "os.pwritev is available")
1975 self.assertFalse(hasattr(os, "preadv"), "os.readv is available")
1986 os.stat("file", dir_fd=0)
1997 os.access("file", os.R_OK, dir_fd=0)
2000 os.access("file", os.R_OK, follow_symlinks=False)
2003 os.access("file", os.R_OK, effective_ids=True)
2015 os.chmod("file", 0o644, dir_fd=0)
2027 os.chown("file", 0, 0, dir_fd=0)
2038 os.link("source", "target", src_dir_fd=0)
2041 os.link("source", "target", dst_dir_fd=0)
2044 os.link("source", "target", src_dir_fd=0, dst_dir_fd=0)
2048 link_path = os.path.join(base_path, "link")
2049 target_path = os.path.join(base_path, "target")
2050 source_path = os.path.join(base_path, "source")
2055 os.symlink("target", link_path)
2057 # Calling os.link should fail in the link(2) call, and
2062 os.link(source_path, link_path, follow_symlinks=True)
2065 os.link(source_path, link_path, follow_symlinks=False)
2076 …with self.assertRaisesRegex(TypeError, "listdir: path should be string, bytes, os.PathLike or None…
2077 os.listdir(0)
2079 …with self.assertRaisesRegex(TypeError, "scandir: path should be string, bytes, os.PathLike or None…
2080 os.scandir(0)
2091 os.mkdir("dir", dir_fd=0)
2102 os.mkfifo("path", dir_fd=0)
2113 os.mknod("path", dir_fd=0)
2124 os.rename("a", "b", src_dir_fd=0)
2127 os.rename("a", "b", dst_dir_fd=0)
2130 os.replace("a", "b", src_dir_fd=0)
2133 os.replace("a", "b", dst_dir_fd=0)
2144 os.unlink("path", dir_fd=0)
2147 os.rmdir("path", dir_fd=0)
2158 os.open("path", os.O_RDONLY, dir_fd=0)
2169 os.readlink("path", dir_fd=0)
2180 os.symlink("a", "b", dir_fd=0)
2194 os.utime("path", dir_fd=0)