• Home
  • Raw
  • Download

Lines Matching full:os

12 import os
20 _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
121 "test needs os.initgroups()")
132 if os.getuid() != 0:
148 self.assertTrue(posix.statvfs(os.curdir))
179 …@unittest.skipUnless(getattr(os, 'execve', None) in os.supports_fd, "test needs execve() to suppor…
180 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
181 @unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
183 fp = os.open(sys.executable, os.O_RDONLY)
185 pid = os.fork()
187 os.chdir(os.path.split(sys.executable)[0])
188 posix.execve(fp, [sys.executable, '-c', 'pass'], os.environ)
190 self.assertEqual(os.waitpid(pid, 0), (pid, 0))
192 os.close(fp)
196 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
198 pid = os.fork()
200 os.chdir(os.path.split(sys.executable)[0])
201 posix.execve(sys.executable, [sys.executable, '-c', 'pass'], os.environ)
206 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
209 os.register_at_fork(lambda: None)
211 os.register_at_fork(before=2)
213 os.register_at_fork(after_in_child="three")
215 os.register_at_fork(after_in_parent=b"Five")
217 os.register_at_fork(before=None)
219 os.register_at_fork(after_in_child=None)
221 os.register_at_fork(after_in_parent=None)
224 os.register_at_fork(before=None, after_in_parent=lambda: 3)
227 os.register_at_fork(before=lambda: None, after_in_child='')
231 import os
233 r, w = os.pipe()
234 fin_r, fin_w = os.pipe()
236 os.register_at_fork(before=lambda: os.write(w, b'A'))
237 os.register_at_fork(after_in_parent=lambda: os.write(w, b'C'))
238 os.register_at_fork(after_in_child=lambda: os.write(w, b'E'))
239 os.register_at_fork(before=lambda: os.write(w, b'B'),
240 after_in_parent=lambda: os.write(w, b'D'),
241 after_in_child=lambda: os.write(w, b'F'))
243 pid = os.fork()
246 os.close(w)
248 os.read(fin_r, 1)
249 os._exit(0)
252 os.close(w)
263 os.write(fin_w, b'!')
269 fd = os.open(support.TESTFN, os.O_WRONLY | os.O_CREAT)
271 os.write(fd, b'test')
272 os.lseek(fd, 0, os.SEEK_SET)
277 os.close(fd)
281 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
283 os.write(fd, b'test')
284 os.lseek(fd, 0, os.SEEK_SET)
289 os.close(fd)
293 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
295 os.write(fd, b'test1tt2t3t5t6t6t8')
300 os.close(fd)
305 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
307 os.write(fd, b'test1tt2t3t5t6t6t8')
309 self.assertEqual(posix.preadv(fd, buf, 3, os.RWF_HIPRI), 10)
312 os.close(fd)
317 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
321 os.preadv(fd, buf, 0)
325 os.close(fd)
329 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
331 os.write(fd, b'test')
332 os.lseek(fd, 0, os.SEEK_SET)
336 os.close(fd)
340 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
342 os.write(fd, b"xx")
343 os.lseek(fd, 0, os.SEEK_SET)
344 n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2)
347 os.lseek(fd, 0, os.SEEK_SET)
350 os.close(fd)
353 @unittest.skipUnless(hasattr(posix, 'os.RWF_SYNC'), "test needs os.RWF_SYNC")
355 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
357 os.write(fd,b"xx")
358 os.lseek(fd, 0, os.SEEK_SET)
359 n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2, os.RWF_SYNC)
362 os.lseek(fd, 0, os.SEEK_SET)
365 os.close(fd)
370 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
373 os.pwritev(fd, [b"x" * 2**16] * 2**15, 0)
376 os.close(fd)
381 fd = os.open(support.TESTFN, os.O_WRONLY | os.O_CREAT)
395 os.close(fd)
410 fd = os.open(support.TESTFN, os.O_RDONLY)
414 os.close(fd)
425 @unittest.skipUnless(os.utime in os.supports_fd, "test needs fd support in os.utime")
428 fd = os.open(support.TESTFN, os.O_RDONLY)
444 os.close(fd)
446 …@unittest.skipUnless(os.utime in os.supports_follow_symlinks, "test needs follow_symlinks support …
459 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
461 n = os.writev(fd, (b'test1', b'tt2', b't3'))
464 os.lseek(fd, 0, os.SEEK_SET)
477 os.close(fd)
482 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
485 os.writev(fd, [b"x" * 2**16] * 2**15)
488 os.close(fd)
492 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
494 os.write(fd, b'test1tt2t3')
495 os.lseek(fd, 0, os.SEEK_SET)
510 os.close(fd)
515 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
519 os.readv(fd, buf)
523 os.close(fd)
532 os.close(fd)
553 @unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
556 fd = os.open(support.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
557 self.addCleanup(os.close, fd)
558 self.assertFalse(os.get_inheritable(fd))
563 fd = os.open(support.TESTFN,
564 os.O_WRONLY|os.O_EXLOCK|os.O_CREAT)
565 self.assertRaises(OSError, os.open, support.TESTFN,
566 os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
567 os.close(fd)
570 fd = os.open(support.TESTFN,
571 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
572 self.assertRaises(OSError, os.open, support.TESTFN,
573 os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
574 os.close(fd)
579 fd1 = os.open(support.TESTFN,
580 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
581 fd2 = os.open(support.TESTFN,
582 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
583 os.close(fd2)
584 os.close(fd1)
587 fd = os.open(support.TESTFN,
588 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
589 self.assertRaises(OSError, os.open, support.TESTFN,
590 os.O_RDONLY|os.O_EXLOCK|os.O_NONBLOCK)
591 os.close(fd)
602 'should be string, bytes, os.PathLike or integer, not',
611 self.assertTrue(posix.stat(os.fsencode(support.TESTFN)))
614 'should be string, bytes, os.PathLike or integer, not',
615 posix.stat, bytearray(os.fsencode(support.TESTFN)))
617 'should be string, bytes, os.PathLike or integer, not',
620 'should be string, bytes, os.PathLike or integer, not',
623 'should be string, bytes, os.PathLike or integer, not',
624 posix.stat, list(os.fsencode(support.TESTFN)))
701 uid = os.getuid()
702 gid = os.getgid()
743 if 0 not in os.getgroups():
753 @unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()")
756 os.unlink(support.TESTFN)
764 @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
766 os.unlink(support.TESTFN)
777 @unittest.skipUnless(hasattr(posix, 'lchown'), "test needs os.lchown()")
779 os.unlink(support.TESTFN)
781 os.symlink(_DUMMY_SYMLINK, support.TESTFN)
787 posix.chdir(os.curdir)
791 self.assertIn(support.TESTFN, posix.listdir(os.curdir))
795 # it's the same as listdir(os.curdir).
801 self.assertIn(os.fsencode(support.TESTFN), posix.listdir(b'.'))
807 self.assertIn(os.fsencode(support.TESTFN), names)
811 @unittest.skipUnless(posix.listdir in os.supports_fd,
828 self.assertTrue(posix.access(support.TESTFN, os.R_OK))
844 os.close(reader)
845 os.close(writer)
847 @unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
850 self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
851 self.assertRaises(TypeError, os.pipe2, 0, 0)
853 # try calling with flags = 0, like os.pipe()
854 r, w = os.pipe2(0)
855 os.close(r)
856 os.close(w)
859 r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
860 self.addCleanup(os.close, r)
861 self.addCleanup(os.close, w)
862 self.assertFalse(os.get_inheritable(r))
863 self.assertFalse(os.get_inheritable(w))
864 self.assertFalse(os.get_blocking(r))
865 self.assertFalse(os.get_blocking(w))
867 self.assertRaises(OSError, os.read, r, 1)
871 os.write(w, b'x' * support.PIPE_MAX_SIZE)
876 @unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
881 self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1)
882 self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1)
895 st = os.stat(target_file)
909 new_st = os.stat(target_file)
918 @unittest.skipUnless(hasattr(posix, 'chflags'), 'test needs os.chflags()')
922 @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
927 @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
929 testfn_st = os.stat(support.TESTFN)
933 os.symlink(support.TESTFN, _DUMMY_SYMLINK)
935 dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
951 new_testfn_st = os.stat(support.TESTFN)
952 new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
961 if os.name == "nt":
969 @unittest.skipUnless(hasattr(os, "putenv"), "requires os.putenv()")
972 os.putenv('FRUIT\0VEGETABLE', 'cabbage')
974 os.putenv(b'FRUIT\0VEGETABLE', b'cabbage')
976 os.putenv('FRUIT', 'orange\0VEGETABLE=cabbage')
978 os.putenv(b'FRUIT', b'orange\0VEGETABLE=cabbage')
980 os.putenv('FRUIT=ORANGE', 'lemon')
982 os.putenv(b'FRUIT=ORANGE', b'lemon')
987 curdir = os.getcwd()
988 base_path = os.path.abspath(support.TESTFN) + '.getcwd'
991 os.mkdir(base_path)
992 os.chdir(base_path)
1001 os.mkdir(dirname)
1005 os.chdir(dirname)
1007 os.getcwd()
1011 os.chdir('..')
1012 os.rmdir(dirname)
1017 os.chdir(curdir)
1022 @unittest.skipUnless(hasattr(os, 'getuid'), "test needs os.getuid()")
1024 user = pwd.getpwuid(os.getuid())[0]
1025 group = pwd.getpwuid(os.getuid())[3]
1029 @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()")
1031 with os.popen('id -G 2>/dev/null') as idg:
1042 # Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups()
1049 # 'id -G' and 'os.getgroups()' should return the same
1058 … @unittest.skipUnless(os.access in os.supports_dir_fd, "test needs dir_fd support for os.access()")
1062 self.assertTrue(posix.access(support.TESTFN, os.R_OK, dir_fd=f))
1066 @unittest.skipUnless(os.chmod in os.supports_dir_fd, "test needs dir_fd support in os.chmod()")
1068 os.chmod(support.TESTFN, stat.S_IRUSR)
1079 @unittest.skipUnless(os.chown in os.supports_dir_fd, "test needs dir_fd support in os.chown()")
1086 posix.chown(support.TESTFN, os.getuid(), os.getgid(), dir_fd=f)
1090 @unittest.skipUnless(os.stat in os.supports_dir_fd, "test needs dir_fd support in os.stat()")
1112 @unittest.skipUnless(os.utime in os.supports_dir_fd, "test needs dir_fd support in os.utime()")
1132 if os.utime in os.supports_follow_symlinks:
1142 @unittest.skipUnless(os.link in os.supports_dir_fd, "test needs dir_fd support in os.link()")
1157 @unittest.skipUnless(os.mkdir in os.supports_dir_fd, "test needs dir_fd support in os.mkdir()")
1167 @unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'),
1168 "test requires both stat.S_IFIFO and dir_fd support for os.mknod()")
1186 @unittest.skipUnless(os.open in os.supports_dir_fd, "test needs dir_fd support in os.open()")
1200 …@unittest.skipUnless(os.readlink in os.supports_dir_fd, "test needs dir_fd support in os.readlink(…
1202 os.symlink(support.TESTFN, support.TESTFN + 'link')
1211 … @unittest.skipUnless(os.rename in os.supports_dir_fd, "test needs dir_fd support in os.rename()")
1226 …@unittest.skipUnless(os.symlink in os.supports_dir_fd, "test needs dir_fd support in os.symlink()")
1236 … @unittest.skipUnless(os.unlink in os.supports_dir_fd, "test needs dir_fd support in os.unlink()")
1251 … @unittest.skipUnless(os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()")
1298 parent = posix.sched_getscheduler(os.getppid())
1378 @unittest.skipUnless(hasattr(os, 'SEEK_HOLE'),
1379 "test needs an OS that reports file holes")
1382 # if the OS supports it the SEEK_* constants
1385 # os.SEEK_DATA = current position
1386 # os.SEEK_HOLE = end of file position
1394 self.assertEqual(i, os.lseek(fno, i, os.SEEK_DATA))
1395 self.assertLessEqual(size, os.lseek(fno, i, os.SEEK_HOLE))
1396 self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_DATA)
1397 self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_HOLE)
1410 function = getattr(os, name, None)
1421 self.fail("No valid path_error2() test for os." + name)
1431 fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
1434 os.close(fd)
1435 self.assertFalse(os.path.exists(fn))
1436 self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
1437 self.assertFalse(os.path.exists(fn))
1439 self.assertRaises(ValueError, os.stat, fn_with_NUL)
1442 fn = os.fsencode(support.TESTFN)
1449 fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
1452 os.close(fd)
1453 self.assertFalse(os.path.exists(fn))
1454 self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
1455 self.assertFalse(os.path.exists(fn))
1457 self.assertRaises(ValueError, os.stat, fn_with_NUL)