Lines Matching refs:os
5 import os
31 if os.path.exists(test_support.TESTFN):
32 os.unlink(test_support.TESTFN)
36 f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
37 os.close(f)
38 self.assertTrue(os.access(test_support.TESTFN, os.W_OK))
41 first = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
45 second = os.dup(first)
49 os.close(first)
54 first, second = second, os.dup(second)
56 os.close(second)
58 os.closerange(first, first + 2)
59 self.assertRaises(OSError, os.write, first, "a")
65 self.assertRaises(TypeError, os.rename, path, 0)
73 os.mkdir(test_support.TESTFN)
77 os.unlink(name)
78 os.rmdir(test_support.TESTFN)
82 self.assertFalse(os.path.exists(name),
88 @unittest.skipUnless(hasattr(os, 'tempnam'), 'test needs os.tempnam()')
94 self.check_tempfile(os.tempnam())
96 name = os.tempnam(test_support.TESTFN)
99 name = os.tempnam(test_support.TESTFN, "pfx")
100 self.assertTrue(os.path.basename(name)[:3] == "pfx")
103 @unittest.skipUnless(hasattr(os, 'tmpfile'), 'test needs os.tmpfile()')
124 if os.path.exists(name):
125 os.remove(name)
134 fp = os.tmpfile()
144 os.remove(name)
146 fp = os.tmpfile()
153 @unittest.skipUnless(hasattr(os, 'tmpnam'), 'test needs os.tmpnam()')
160 name = os.tmpnam()
177 self.assertFalse(os.path.exists(name),
185 os.mkdir(test_support.TESTFN)
186 self.fname = os.path.join(test_support.TESTFN, "f1")
192 os.unlink(self.fname)
193 os.rmdir(test_support.TESTFN)
195 @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()')
198 result = os.stat(self.fname)
244 result2 = os.stat_result((10,))
251 result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
256 @unittest.skipUnless(hasattr(os, 'statvfs'), 'test needs os.statvfs()')
259 result = os.statvfs(self.fname)
289 result2 = os.statvfs_result((10,))
296 result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
302 st = os.stat(test_support.TESTFN)
305 os.utime(test_support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
306 st2 = os.stat(test_support.TESTFN)
313 root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
325 os.utime(self.fname, (t1, t1))
326 self.assertEqual(os.stat(self.fname).st_mtime, t1)
333 os.utime(self.fname, (t1, t1))
334 self.assertEqual(os.stat(self.fname).st_mtime, t1)
340 os.stat(r"c:\pagefile.sys")
354 os.environ.clear()
355 return os.environ
357 self.__save = dict(os.environ)
358 os.environ.clear()
360 os.environ.clear()
361 os.environ.update(self.__save)
365 if os.path.exists("/bin/sh"):
366 os.environ.update(HELLO="World")
367 with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
379 self.assertRaises(ValueError, os.environ.__delitem__, key)
383 self.assertRaises(OSError, os.environ.__delitem__, key)
389 import os
390 from os.path import join
416 os.makedirs(sub11_path)
417 os.makedirs(sub2_path)
418 os.makedirs(t2_path)
423 if hasattr(os, "symlink"):
424 os.symlink(os.path.abspath(t2_path), link_path)
430 all = list(os.walk(walk_path))
444 for root, dirs, files in os.walk(walk_path):
455 all = list(os.walk(walk_path, topdown=False))
467 if hasattr(os, "symlink"):
469 for root, dirs, files in os.walk(walk_path, followlinks=True):
482 for root, dirs, files in os.walk(test_support.TESTFN, topdown=False):
484 os.remove(os.path.join(root, name))
486 dirname = os.path.join(root, name)
487 if not os.path.islink(dirname):
488 os.rmdir(dirname)
490 os.remove(dirname)
491 os.rmdir(test_support.TESTFN)
495 os.mkdir(test_support.TESTFN)
499 path = os.path.join(base, 'dir1', 'dir2', 'dir3')
500 os.makedirs(path) # Should work
501 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
502 os.makedirs(path)
505 self.assertRaises(OSError, os.makedirs, os.curdir)
506 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
507 os.makedirs(path)
508 path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
510 os.makedirs(path)
516 path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
521 while not os.path.exists(path) and path != test_support.TESTFN:
522 path = os.path.dirname(path)
524 os.removedirs(path)
528 f = file(os.devnull, 'w')
531 f = file(os.devnull, 'r')
538 self.assertEqual(len(os.urandom(0)), 0)
539 self.assertEqual(len(os.urandom(1)), 1)
540 self.assertEqual(len(os.urandom(10)), 10)
541 self.assertEqual(len(os.urandom(100)), 100)
542 self.assertEqual(len(os.urandom(1000)), 1000)
545 data1 = os.urandom(16)
546 data2 = os.urandom(16)
605 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
611 newenv = os.environ.copy()
614 os.execve(args[0], args, newenv)
617 newenv = os.environ.copy()
620 os.execve(args[0], args, newenv)
623 newenv = os.environ.copy()
626 os.execve(args[0], args, newenv)
632 self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak")
635 self.assertRaises(WindowsError, os.remove, test_support.TESTFN)
638 self.assertRaises(WindowsError, os.chdir, test_support.TESTFN)
643 self.assertRaises(WindowsError, os.mkdir, test_support.TESTFN)
646 os.unlink(test_support.TESTFN)
649 self.assertRaises(WindowsError, os.utime, test_support.TESTFN, None)
652 self.assertRaises(WindowsError, os.chmod, test_support.TESTFN, 0)
661 if hasattr(os, f):
662 self.check(getattr(os, f))
676 @unittest.skipUnless(hasattr(os, 'isatty'), 'test needs os.isatty()')
678 self.assertEqual(os.isatty(test_support.make_bad_fd()), False)
680 @unittest.skipUnless(hasattr(os, 'closerange'), 'test needs os.closerange()')
686 try: os.fstat(fd+i)
694 self.assertEqual(os.closerange(fd, fd + i-1), None)
696 @unittest.skipUnless(hasattr(os, 'dup2'), 'test needs os.dup2()')
698 self.check(os.dup2, 20)
700 @unittest.skipUnless(hasattr(os, 'fchmod'), 'test needs os.fchmod()')
702 self.check(os.fchmod, 0)
704 @unittest.skipUnless(hasattr(os, 'fchown'), 'test needs os.fchown()')
706 self.check(os.fchown, -1, -1)
708 @unittest.skipUnless(hasattr(os, 'fpathconf'), 'test needs os.fpathconf()')
710 self.check(os.fpathconf, "PC_NAME_MAX")
712 @unittest.skipUnless(hasattr(os, 'ftruncate'), 'test needs os.ftruncate()')
714 self.check(os.ftruncate, 0)
716 @unittest.skipUnless(hasattr(os, 'lseek'), 'test needs os.lseek()')
718 self.check(os.lseek, 0, 0)
720 @unittest.skipUnless(hasattr(os, 'read'), 'test needs os.read()')
722 self.check(os.read, 1)
724 @unittest.skipUnless(hasattr(os, 'tcsetpgrp'), 'test needs os.tcsetpgrp()')
726 self.check(os.tcsetpgrp, 0)
728 @unittest.skipUnless(hasattr(os, 'write'), 'test needs os.write()')
730 self.check(os.write, " ")
734 @unittest.skipUnless(hasattr(os, 'setuid'), 'test needs os.setuid()')
736 if os.getuid() != 0:
737 self.assertRaises(os.error, os.setuid, 0)
738 self.assertRaises(OverflowError, os.setuid, 1<<32)
740 @unittest.skipUnless(hasattr(os, 'setgid'), 'test needs os.setgid()')
742 if os.getuid() != 0:
743 self.assertRaises(os.error, os.setgid, 0)
744 self.assertRaises(OverflowError, os.setgid, 1<<32)
746 @unittest.skipUnless(hasattr(os, 'seteuid'), 'test needs os.seteuid()')
748 if os.getuid() != 0:
749 self.assertRaises(os.error, os.seteuid, 0)
750 self.assertRaises(OverflowError, os.seteuid, 1<<32)
752 @unittest.skipUnless(hasattr(os, 'setegid'), 'test needs os.setegid()')
754 if os.getuid() != 0:
755 self.assertRaises(os.error, os.setegid, 0)
756 self.assertRaises(OverflowError, os.setegid, 1<<32)
758 @unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
760 if os.getuid() != 0:
761 self.assertRaises(os.error, os.setreuid, 0, 0)
762 self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
763 self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
765 @unittest.skipUnless(hasattr(os, 'setreuid'), 'test needs os.setreuid()')
773 @unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
775 if os.getuid() != 0:
776 self.assertRaises(os.error, os.setregid, 0, 0)
777 self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
778 self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
780 @unittest.skipUnless(hasattr(os, 'setregid'), 'test needs os.setregid()')
842 os.kill(proc.pid, sig)
859 os.path.join(os.path.dirname(__file__),
871 os.kill(proc.pid, event)
877 os.kill(proc.pid, signal.SIGINT)
911 dir_path = os.path.join(support.TESTFN, dir_name)
913 file_path = os.path.join(support.TESTFN, file_name)
914 os.makedirs(dir_path)
928 sorted(os.listdir(support.TESTFN.decode(fs_encoding))),
933 sorted(os.listdir(os.fsencode(support.TESTFN))),
941 path = u'\\\\?\\' + os.path.abspath(support.TESTFN.decode(fs_encoding))
943 sorted(os.listdir(path)),
947 path = b'\\\\?\\' + os.path.abspath(support.TESTFN)
949 sorted(os.listdir(path)),
958 newenv = os.environ.copy()
961 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
968 newenv = os.environ.copy()
971 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
978 newenv = os.environ.copy()
981 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
995 newenv = os.environ.copy()
997 exitcode = spawn(os.P_WAIT, args[0], args, newenv)
1000 @unittest.skipUnless(hasattr(os, 'spawnve'), 'test needs os.spawnve()')
1002 self._test_invalid_env(os.spawnve)
1004 @unittest.skipUnless(hasattr(os, 'spawnvpe'), 'test needs os.spawnvpe()')
1006 self._test_invalid_env(os.spawnvpe)