Fred Drake | 38c2ef0 | 2001-07-17 20:52:51 +0000 | [diff] [blame] | 1 | # As a test suite for the os module, this is woefully inadequate, but this |
| 2 | # does add tests for a few functions which have been determined to be more |
Walter Dörwald | f0dfc7a | 2003-10-20 14:01:56 +0000 | [diff] [blame] | 3 | # portable than they had been thought to be. |
Fred Drake | 38c2ef0 | 2001-07-17 20:52:51 +0000 | [diff] [blame] | 4 | |
| 5 | import os |
Benjamin Peterson | 5c6d787 | 2009-02-06 02:40:07 +0000 | [diff] [blame] | 6 | import errno |
Fred Drake | 38c2ef0 | 2001-07-17 20:52:51 +0000 | [diff] [blame] | 7 | import unittest |
Jeremy Hylton | a7fc21b | 2001-08-20 20:10:01 +0000 | [diff] [blame] | 8 | import warnings |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 9 | import sys |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 10 | import signal |
| 11 | import subprocess |
| 12 | import time |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 13 | import shutil |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 14 | from test import support |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 15 | import contextlib |
Hirokazu Yamamoto | 54c950f | 2010-10-08 08:38:15 +0000 | [diff] [blame] | 16 | import mmap |
| 17 | import uuid |
Fred Drake | 38c2ef0 | 2001-07-17 20:52:51 +0000 | [diff] [blame] | 18 | |
Mark Dickinson | 7cf0389 | 2010-04-16 13:45:35 +0000 | [diff] [blame] | 19 | # Detect whether we're on a Linux system that uses the (now outdated |
| 20 | # and unmaintained) linuxthreads threading library. There's an issue |
| 21 | # when combining linuxthreads with a failed execv call: see |
| 22 | # http://bugs.python.org/issue4970. |
Mark Dickinson | 89589c9 | 2010-04-16 13:51:27 +0000 | [diff] [blame] | 23 | if (hasattr(os, "confstr_names") and |
| 24 | "CS_GNU_LIBPTHREAD_VERSION" in os.confstr_names): |
Mark Dickinson | 7cf0389 | 2010-04-16 13:45:35 +0000 | [diff] [blame] | 25 | libpthread = os.confstr("CS_GNU_LIBPTHREAD_VERSION") |
| 26 | USING_LINUXTHREADS= libpthread.startswith("linuxthreads") |
| 27 | else: |
| 28 | USING_LINUXTHREADS= False |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 29 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 30 | # Tests creating TESTFN |
| 31 | class FileTests(unittest.TestCase): |
| 32 | def setUp(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 33 | if os.path.exists(support.TESTFN): |
| 34 | os.unlink(support.TESTFN) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 35 | tearDown = setUp |
| 36 | |
| 37 | def test_access(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 38 | f = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 39 | os.close(f) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 40 | self.assertTrue(os.access(support.TESTFN, os.W_OK)) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 41 | |
Christian Heimes | fdab48e | 2008-01-20 09:06:41 +0000 | [diff] [blame] | 42 | def test_closerange(self): |
Antoine Pitrou | b9ee06c | 2008-08-16 22:03:17 +0000 | [diff] [blame] | 43 | first = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR) |
| 44 | # We must allocate two consecutive file descriptors, otherwise |
| 45 | # it will mess up other file descriptors (perhaps even the three |
| 46 | # standard ones). |
| 47 | second = os.dup(first) |
| 48 | try: |
| 49 | retries = 0 |
| 50 | while second != first + 1: |
| 51 | os.close(first) |
| 52 | retries += 1 |
| 53 | if retries > 10: |
| 54 | # XXX test skipped |
Benjamin Peterson | fa0d703 | 2009-06-01 22:42:33 +0000 | [diff] [blame] | 55 | self.skipTest("couldn't allocate two consecutive fds") |
Antoine Pitrou | b9ee06c | 2008-08-16 22:03:17 +0000 | [diff] [blame] | 56 | first, second = second, os.dup(second) |
| 57 | finally: |
| 58 | os.close(second) |
Christian Heimes | fdab48e | 2008-01-20 09:06:41 +0000 | [diff] [blame] | 59 | # close a fd that is open, and one that isn't |
Antoine Pitrou | b9ee06c | 2008-08-16 22:03:17 +0000 | [diff] [blame] | 60 | os.closerange(first, first + 2) |
Antoine Pitrou | 9cadb1b | 2008-09-15 23:02:56 +0000 | [diff] [blame] | 61 | self.assertRaises(OSError, os.write, first, b"a") |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 62 | |
Benjamin Peterson | 1cc6df9 | 2010-06-30 17:39:45 +0000 | [diff] [blame] | 63 | @support.cpython_only |
Hirokazu Yamamoto | 4c19e6e | 2008-09-08 23:41:21 +0000 | [diff] [blame] | 64 | def test_rename(self): |
| 65 | path = support.TESTFN |
| 66 | old = sys.getrefcount(path) |
| 67 | self.assertRaises(TypeError, os.rename, path, 0) |
| 68 | new = sys.getrefcount(path) |
| 69 | self.assertEqual(old, new) |
| 70 | |
Antoine Pitrou | 9cadb1b | 2008-09-15 23:02:56 +0000 | [diff] [blame] | 71 | def test_read(self): |
| 72 | with open(support.TESTFN, "w+b") as fobj: |
| 73 | fobj.write(b"spam") |
| 74 | fobj.flush() |
| 75 | fd = fobj.fileno() |
| 76 | os.lseek(fd, 0, 0) |
| 77 | s = os.read(fd, 4) |
| 78 | self.assertEqual(type(s), bytes) |
| 79 | self.assertEqual(s, b"spam") |
| 80 | |
| 81 | def test_write(self): |
| 82 | # os.write() accepts bytes- and buffer-like objects but not strings |
| 83 | fd = os.open(support.TESTFN, os.O_CREAT | os.O_WRONLY) |
| 84 | self.assertRaises(TypeError, os.write, fd, "beans") |
| 85 | os.write(fd, b"bacon\n") |
| 86 | os.write(fd, bytearray(b"eggs\n")) |
| 87 | os.write(fd, memoryview(b"spam\n")) |
| 88 | os.close(fd) |
| 89 | with open(support.TESTFN, "rb") as fobj: |
Antoine Pitrou | d62269f | 2008-09-15 23:54:52 +0000 | [diff] [blame] | 90 | self.assertEqual(fobj.read().splitlines(), |
| 91 | [b"bacon", b"eggs", b"spam"]) |
Antoine Pitrou | 9cadb1b | 2008-09-15 23:02:56 +0000 | [diff] [blame] | 92 | |
| 93 | |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 94 | class TemporaryFileTests(unittest.TestCase): |
| 95 | def setUp(self): |
| 96 | self.files = [] |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 97 | os.mkdir(support.TESTFN) |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 98 | |
| 99 | def tearDown(self): |
| 100 | for name in self.files: |
| 101 | os.unlink(name) |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 102 | os.rmdir(support.TESTFN) |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 103 | |
| 104 | def check_tempfile(self, name): |
| 105 | # make sure it doesn't already exist: |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 106 | self.assertFalse(os.path.exists(name), |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 107 | "file already exists for temporary file") |
| 108 | # make sure we can create the file |
| 109 | open(name, "w") |
| 110 | self.files.append(name) |
| 111 | |
| 112 | def test_tempnam(self): |
| 113 | if not hasattr(os, "tempnam"): |
| 114 | return |
| 115 | warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, |
| 116 | r"test_os$") |
| 117 | self.check_tempfile(os.tempnam()) |
| 118 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 119 | name = os.tempnam(support.TESTFN) |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 120 | self.check_tempfile(name) |
| 121 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 122 | name = os.tempnam(support.TESTFN, "pfx") |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 123 | self.assertTrue(os.path.basename(name)[:3] == "pfx") |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 124 | self.check_tempfile(name) |
| 125 | |
| 126 | def test_tmpfile(self): |
| 127 | if not hasattr(os, "tmpfile"): |
| 128 | return |
| 129 | # As with test_tmpnam() below, the Windows implementation of tmpfile() |
| 130 | # attempts to create a file in the root directory of the current drive. |
| 131 | # On Vista and Server 2008, this test will always fail for normal users |
| 132 | # as writing to the root directory requires elevated privileges. With |
| 133 | # XP and below, the semantics of tmpfile() are the same, but the user |
| 134 | # running the test is more likely to have administrative privileges on |
| 135 | # their account already. If that's the case, then os.tmpfile() should |
| 136 | # work. In order to make this test as useful as possible, rather than |
| 137 | # trying to detect Windows versions or whether or not the user has the |
| 138 | # right permissions, just try and create a file in the root directory |
| 139 | # and see if it raises a 'Permission denied' OSError. If it does, then |
| 140 | # test that a subsequent call to os.tmpfile() raises the same error. If |
| 141 | # it doesn't, assume we're on XP or below and the user running the test |
| 142 | # has administrative privileges, and proceed with the test as normal. |
| 143 | if sys.platform == 'win32': |
| 144 | name = '\\python_test_os_test_tmpfile.txt' |
| 145 | if os.path.exists(name): |
| 146 | os.remove(name) |
| 147 | try: |
| 148 | fp = open(name, 'w') |
| 149 | except IOError as first: |
| 150 | # open() failed, assert tmpfile() fails in the same way. |
| 151 | # Although open() raises an IOError and os.tmpfile() raises an |
| 152 | # OSError(), 'args' will be (13, 'Permission denied') in both |
| 153 | # cases. |
| 154 | try: |
| 155 | fp = os.tmpfile() |
| 156 | except OSError as second: |
| 157 | self.assertEqual(first.args, second.args) |
| 158 | else: |
| 159 | self.fail("expected os.tmpfile() to raise OSError") |
| 160 | return |
| 161 | else: |
| 162 | # open() worked, therefore, tmpfile() should work. Close our |
| 163 | # dummy file and proceed with the test as normal. |
| 164 | fp.close() |
| 165 | os.remove(name) |
| 166 | |
| 167 | fp = os.tmpfile() |
| 168 | fp.write("foobar") |
| 169 | fp.seek(0,0) |
| 170 | s = fp.read() |
| 171 | fp.close() |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 172 | self.assertTrue(s == "foobar") |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 173 | |
| 174 | def test_tmpnam(self): |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 175 | if not hasattr(os, "tmpnam"): |
| 176 | return |
| 177 | warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, |
| 178 | r"test_os$") |
| 179 | name = os.tmpnam() |
| 180 | if sys.platform in ("win32",): |
| 181 | # The Windows tmpnam() seems useless. From the MS docs: |
| 182 | # |
| 183 | # The character string that tmpnam creates consists of |
| 184 | # the path prefix, defined by the entry P_tmpdir in the |
| 185 | # file STDIO.H, followed by a sequence consisting of the |
| 186 | # digit characters '0' through '9'; the numerical value |
| 187 | # of this string is in the range 1 - 65,535. Changing the |
| 188 | # definitions of L_tmpnam or P_tmpdir in STDIO.H does not |
| 189 | # change the operation of tmpnam. |
| 190 | # |
| 191 | # The really bizarre part is that, at least under MSVC6, |
| 192 | # P_tmpdir is "\\". That is, the path returned refers to |
| 193 | # the root of the current drive. That's a terrible place to |
| 194 | # put temp files, and, depending on privileges, the user |
| 195 | # may not even be able to open a file in the root directory. |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 196 | self.assertFalse(os.path.exists(name), |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 197 | "file already exists for temporary file") |
| 198 | else: |
| 199 | self.check_tempfile(name) |
| 200 | |
Amaury Forgeot d'Arc | e2e36ba | 2008-08-01 00:14:22 +0000 | [diff] [blame] | 201 | def fdopen_helper(self, *args): |
| 202 | fd = os.open(support.TESTFN, os.O_RDONLY) |
| 203 | fp2 = os.fdopen(fd, *args) |
| 204 | fp2.close() |
| 205 | |
| 206 | def test_fdopen(self): |
| 207 | self.fdopen_helper() |
| 208 | self.fdopen_helper('r') |
| 209 | self.fdopen_helper('r', 100) |
| 210 | |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 211 | # Test attributes on return values from os.*stat* family. |
| 212 | class StatAttributeTests(unittest.TestCase): |
| 213 | def setUp(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 214 | os.mkdir(support.TESTFN) |
| 215 | self.fname = os.path.join(support.TESTFN, "f1") |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 216 | f = open(self.fname, 'wb') |
Guido van Rossum | 26d95c3 | 2007-08-27 23:18:54 +0000 | [diff] [blame] | 217 | f.write(b"ABC") |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 218 | f.close() |
Tim Peters | e0c446b | 2001-10-18 21:57:37 +0000 | [diff] [blame] | 219 | |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 220 | def tearDown(self): |
| 221 | os.unlink(self.fname) |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 222 | os.rmdir(support.TESTFN) |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 223 | |
Antoine Pitrou | 3842529 | 2010-09-21 18:19:07 +0000 | [diff] [blame] | 224 | def check_stat_attributes(self, fname): |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 225 | if not hasattr(os, "stat"): |
| 226 | return |
| 227 | |
| 228 | import stat |
Antoine Pitrou | 3842529 | 2010-09-21 18:19:07 +0000 | [diff] [blame] | 229 | result = os.stat(fname) |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 230 | |
| 231 | # Make sure direct access works |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 232 | self.assertEqual(result[stat.ST_SIZE], 3) |
| 233 | self.assertEqual(result.st_size, 3) |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 234 | |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 235 | # Make sure all the attributes are there |
| 236 | members = dir(result) |
| 237 | for name in dir(stat): |
| 238 | if name[:3] == 'ST_': |
| 239 | attr = name.lower() |
Martin v. Löwis | 4d394df | 2005-01-23 09:19:22 +0000 | [diff] [blame] | 240 | if name.endswith("TIME"): |
| 241 | def trunc(x): return int(x) |
| 242 | else: |
| 243 | def trunc(x): return x |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 244 | self.assertEqual(trunc(getattr(result, attr)), |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 245 | result[getattr(stat, name)]) |
Benjamin Peterson | 577473f | 2010-01-19 00:09:57 +0000 | [diff] [blame] | 246 | self.assertIn(attr, members) |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 247 | |
| 248 | try: |
| 249 | result[200] |
| 250 | self.fail("No exception thrown") |
| 251 | except IndexError: |
| 252 | pass |
| 253 | |
| 254 | # Make sure that assignment fails |
| 255 | try: |
| 256 | result.st_mode = 1 |
| 257 | self.fail("No exception thrown") |
Collin Winter | 42dae6a | 2007-03-28 21:44:53 +0000 | [diff] [blame] | 258 | except AttributeError: |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 259 | pass |
| 260 | |
| 261 | try: |
| 262 | result.st_rdev = 1 |
| 263 | self.fail("No exception thrown") |
Guido van Rossum | 1fff878 | 2001-10-18 21:19:31 +0000 | [diff] [blame] | 264 | except (AttributeError, TypeError): |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 265 | pass |
| 266 | |
| 267 | try: |
| 268 | result.parrot = 1 |
| 269 | self.fail("No exception thrown") |
| 270 | except AttributeError: |
| 271 | pass |
| 272 | |
| 273 | # Use the stat_result constructor with a too-short tuple. |
| 274 | try: |
| 275 | result2 = os.stat_result((10,)) |
| 276 | self.fail("No exception thrown") |
| 277 | except TypeError: |
| 278 | pass |
| 279 | |
| 280 | # Use the constructr with a too-long tuple. |
| 281 | try: |
| 282 | result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) |
| 283 | except TypeError: |
| 284 | pass |
| 285 | |
Antoine Pitrou | 3842529 | 2010-09-21 18:19:07 +0000 | [diff] [blame] | 286 | def test_stat_attributes(self): |
| 287 | self.check_stat_attributes(self.fname) |
| 288 | |
| 289 | def test_stat_attributes_bytes(self): |
| 290 | try: |
| 291 | fname = self.fname.encode(sys.getfilesystemencoding()) |
| 292 | except UnicodeEncodeError: |
| 293 | self.skipTest("cannot encode %a for the filesystem" % self.fname) |
| 294 | self.check_stat_attributes(fname) |
Tim Peters | e0c446b | 2001-10-18 21:57:37 +0000 | [diff] [blame] | 295 | |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 296 | def test_statvfs_attributes(self): |
| 297 | if not hasattr(os, "statvfs"): |
| 298 | return |
| 299 | |
Martin v. Löwis | f90ae20 | 2002-06-11 06:22:31 +0000 | [diff] [blame] | 300 | try: |
| 301 | result = os.statvfs(self.fname) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 302 | except OSError as e: |
Martin v. Löwis | f90ae20 | 2002-06-11 06:22:31 +0000 | [diff] [blame] | 303 | # On AtheOS, glibc always returns ENOSYS |
Martin v. Löwis | f90ae20 | 2002-06-11 06:22:31 +0000 | [diff] [blame] | 304 | if e.errno == errno.ENOSYS: |
| 305 | return |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 306 | |
| 307 | # Make sure direct access works |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 308 | self.assertEqual(result.f_bfree, result[3]) |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 309 | |
Brett Cannon | cfaf10c | 2008-05-16 00:45:35 +0000 | [diff] [blame] | 310 | # Make sure all the attributes are there. |
| 311 | members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files', |
| 312 | 'ffree', 'favail', 'flag', 'namemax') |
| 313 | for value, member in enumerate(members): |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 314 | self.assertEqual(getattr(result, 'f_' + member), result[value]) |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 315 | |
| 316 | # Make sure that assignment really fails |
| 317 | try: |
| 318 | result.f_bfree = 1 |
| 319 | self.fail("No exception thrown") |
Collin Winter | 42dae6a | 2007-03-28 21:44:53 +0000 | [diff] [blame] | 320 | except AttributeError: |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 321 | pass |
| 322 | |
| 323 | try: |
| 324 | result.parrot = 1 |
| 325 | self.fail("No exception thrown") |
| 326 | except AttributeError: |
| 327 | pass |
| 328 | |
| 329 | # Use the constructor with a too-short tuple. |
| 330 | try: |
| 331 | result2 = os.statvfs_result((10,)) |
| 332 | self.fail("No exception thrown") |
| 333 | except TypeError: |
| 334 | pass |
| 335 | |
| 336 | # Use the constructr with a too-long tuple. |
| 337 | try: |
| 338 | result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) |
| 339 | except TypeError: |
| 340 | pass |
Fred Drake | 38c2ef0 | 2001-07-17 20:52:51 +0000 | [diff] [blame] | 341 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 342 | def test_utime_dir(self): |
| 343 | delta = 1000000 |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 344 | st = os.stat(support.TESTFN) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 345 | # round to int, because some systems may support sub-second |
| 346 | # time stamps in stat, but not in utime. |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 347 | os.utime(support.TESTFN, (st.st_atime, int(st.st_mtime-delta))) |
| 348 | st2 = os.stat(support.TESTFN) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 349 | self.assertEqual(st2.st_mtime, int(st.st_mtime-delta)) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 350 | |
| 351 | # Restrict test to Win32, since there is no guarantee other |
| 352 | # systems support centiseconds |
| 353 | if sys.platform == 'win32': |
Thomas Wouters | 47b49bf | 2007-08-30 22:15:33 +0000 | [diff] [blame] | 354 | def get_file_system(path): |
Hirokazu Yamamoto | 5ef6d18 | 2008-08-20 04:17:24 +0000 | [diff] [blame] | 355 | root = os.path.splitdrive(os.path.abspath(path))[0] + '\\' |
Thomas Wouters | 47b49bf | 2007-08-30 22:15:33 +0000 | [diff] [blame] | 356 | import ctypes |
Hirokazu Yamamoto | ca765d5 | 2008-08-20 16:18:19 +0000 | [diff] [blame] | 357 | kernel32 = ctypes.windll.kernel32 |
Hirokazu Yamamoto | 5ef6d18 | 2008-08-20 04:17:24 +0000 | [diff] [blame] | 358 | buf = ctypes.create_unicode_buffer("", 100) |
Hirokazu Yamamoto | ca765d5 | 2008-08-20 16:18:19 +0000 | [diff] [blame] | 359 | if kernel32.GetVolumeInformationW(root, None, 0, None, None, None, buf, len(buf)): |
Thomas Wouters | 47b49bf | 2007-08-30 22:15:33 +0000 | [diff] [blame] | 360 | return buf.value |
| 361 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 362 | if get_file_system(support.TESTFN) == "NTFS": |
Thomas Wouters | 47b49bf | 2007-08-30 22:15:33 +0000 | [diff] [blame] | 363 | def test_1565150(self): |
| 364 | t1 = 1159195039.25 |
| 365 | os.utime(self.fname, (t1, t1)) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 366 | self.assertEqual(os.stat(self.fname).st_mtime, t1) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 367 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 368 | def test_1686475(self): |
| 369 | # Verify that an open file can be stat'ed |
| 370 | try: |
| 371 | os.stat(r"c:\pagefile.sys") |
| 372 | except WindowsError as e: |
Benjamin Peterson | c4fe6f3 | 2008-08-19 18:57:56 +0000 | [diff] [blame] | 373 | if e.errno == 2: # file does not exist; cannot run test |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 374 | return |
| 375 | self.fail("Could not stat pagefile.sys") |
| 376 | |
Walter Dörwald | 0a6d0ff | 2004-05-31 16:29:04 +0000 | [diff] [blame] | 377 | from test import mapping_tests |
Raymond Hettinger | 2c2d322 | 2003-03-09 07:05:43 +0000 | [diff] [blame] | 378 | |
Walter Dörwald | 0a6d0ff | 2004-05-31 16:29:04 +0000 | [diff] [blame] | 379 | class EnvironTests(mapping_tests.BasicTestMappingProtocol): |
Raymond Hettinger | 2c2d322 | 2003-03-09 07:05:43 +0000 | [diff] [blame] | 380 | """check that os.environ object conform to mapping protocol""" |
Walter Dörwald | 118f931 | 2004-06-02 18:42:25 +0000 | [diff] [blame] | 381 | type2test = None |
Christian Heimes | 9033339 | 2007-11-01 19:08:42 +0000 | [diff] [blame] | 382 | |
Raymond Hettinger | 2c2d322 | 2003-03-09 07:05:43 +0000 | [diff] [blame] | 383 | def setUp(self): |
| 384 | self.__save = dict(os.environ) |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 385 | if os.supports_bytes_environ: |
Victor Stinner | 208d28c | 2010-05-07 00:54:14 +0000 | [diff] [blame] | 386 | self.__saveb = dict(os.environb) |
Christian Heimes | 9033339 | 2007-11-01 19:08:42 +0000 | [diff] [blame] | 387 | for key, value in self._reference().items(): |
| 388 | os.environ[key] = value |
| 389 | |
Raymond Hettinger | 2c2d322 | 2003-03-09 07:05:43 +0000 | [diff] [blame] | 390 | def tearDown(self): |
| 391 | os.environ.clear() |
| 392 | os.environ.update(self.__save) |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 393 | if os.supports_bytes_environ: |
Victor Stinner | 208d28c | 2010-05-07 00:54:14 +0000 | [diff] [blame] | 394 | os.environb.clear() |
| 395 | os.environb.update(self.__saveb) |
Raymond Hettinger | 2c2d322 | 2003-03-09 07:05:43 +0000 | [diff] [blame] | 396 | |
Christian Heimes | 9033339 | 2007-11-01 19:08:42 +0000 | [diff] [blame] | 397 | def _reference(self): |
| 398 | return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"} |
| 399 | |
| 400 | def _empty_mapping(self): |
| 401 | os.environ.clear() |
| 402 | return os.environ |
| 403 | |
Martin v. Löwis | 1d11de6 | 2005-01-29 13:29:23 +0000 | [diff] [blame] | 404 | # Bug 1110478 |
Martin v. Löwis | 5510f65 | 2005-02-17 21:23:20 +0000 | [diff] [blame] | 405 | def test_update2(self): |
Christian Heimes | 9033339 | 2007-11-01 19:08:42 +0000 | [diff] [blame] | 406 | os.environ.clear() |
Martin v. Löwis | 1d11de6 | 2005-01-29 13:29:23 +0000 | [diff] [blame] | 407 | if os.path.exists("/bin/sh"): |
| 408 | os.environ.update(HELLO="World") |
Brian Curtin | 810921b | 2010-10-30 21:24:21 +0000 | [diff] [blame] | 409 | with os.popen("/bin/sh -c 'echo $HELLO'") as popen: |
| 410 | value = popen.read().strip() |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 411 | self.assertEqual(value, "World") |
Martin v. Löwis | 1d11de6 | 2005-01-29 13:29:23 +0000 | [diff] [blame] | 412 | |
Christian Heimes | 1a13d59 | 2007-11-08 14:16:55 +0000 | [diff] [blame] | 413 | def test_os_popen_iter(self): |
| 414 | if os.path.exists("/bin/sh"): |
Brian Curtin | 810921b | 2010-10-30 21:24:21 +0000 | [diff] [blame] | 415 | with os.popen( |
| 416 | "/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen: |
| 417 | it = iter(popen) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 418 | self.assertEqual(next(it), "line1\n") |
| 419 | self.assertEqual(next(it), "line2\n") |
| 420 | self.assertEqual(next(it), "line3\n") |
Brian Curtin | 810921b | 2010-10-30 21:24:21 +0000 | [diff] [blame] | 421 | self.assertRaises(StopIteration, next, it) |
Christian Heimes | 1a13d59 | 2007-11-08 14:16:55 +0000 | [diff] [blame] | 422 | |
Guido van Rossum | 67aca9e | 2007-06-13 21:51:27 +0000 | [diff] [blame] | 423 | # Verify environ keys and values from the OS are of the |
| 424 | # correct str type. |
| 425 | def test_keyvalue_types(self): |
| 426 | for key, val in os.environ.items(): |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 427 | self.assertEqual(type(key), str) |
| 428 | self.assertEqual(type(val), str) |
Guido van Rossum | 67aca9e | 2007-06-13 21:51:27 +0000 | [diff] [blame] | 429 | |
Christian Heimes | 9033339 | 2007-11-01 19:08:42 +0000 | [diff] [blame] | 430 | def test_items(self): |
| 431 | for key, value in self._reference().items(): |
| 432 | self.assertEqual(os.environ.get(key), value) |
| 433 | |
Ezio Melotti | 19e4acf | 2010-02-22 15:59:01 +0000 | [diff] [blame] | 434 | # Issue 7310 |
| 435 | def test___repr__(self): |
| 436 | """Check that the repr() of os.environ looks like environ({...}).""" |
| 437 | env = os.environ |
Victor Stinner | 96f0de9 | 2010-07-29 00:29:00 +0000 | [diff] [blame] | 438 | self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join( |
| 439 | '{!r}: {!r}'.format(key, value) |
| 440 | for key, value in env.items()))) |
Ezio Melotti | 19e4acf | 2010-02-22 15:59:01 +0000 | [diff] [blame] | 441 | |
Gregory P. Smith | b6e8c7e | 2010-02-27 07:22:22 +0000 | [diff] [blame] | 442 | def test_get_exec_path(self): |
| 443 | defpath_list = os.defpath.split(os.pathsep) |
| 444 | test_path = ['/monty', '/python', '', '/flying/circus'] |
| 445 | test_env = {'PATH': os.pathsep.join(test_path)} |
| 446 | |
| 447 | saved_environ = os.environ |
| 448 | try: |
| 449 | os.environ = dict(test_env) |
| 450 | # Test that defaulting to os.environ works. |
| 451 | self.assertSequenceEqual(test_path, os.get_exec_path()) |
| 452 | self.assertSequenceEqual(test_path, os.get_exec_path(env=None)) |
| 453 | finally: |
| 454 | os.environ = saved_environ |
| 455 | |
| 456 | # No PATH environment variable |
| 457 | self.assertSequenceEqual(defpath_list, os.get_exec_path({})) |
| 458 | # Empty PATH environment variable |
| 459 | self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''})) |
| 460 | # Supplied PATH environment variable |
| 461 | self.assertSequenceEqual(test_path, os.get_exec_path(test_env)) |
| 462 | |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 463 | if os.supports_bytes_environ: |
| 464 | # env cannot contain 'PATH' and b'PATH' keys |
Victor Stinner | 38430e2 | 2010-08-19 17:10:18 +0000 | [diff] [blame] | 465 | try: |
Victor Stinner | 6f35eda | 2010-10-29 00:38:58 +0000 | [diff] [blame] | 466 | # ignore BytesWarning warning |
| 467 | with warnings.catch_warnings(record=True): |
| 468 | mixed_env = {'PATH': '1', b'PATH': b'2'} |
Victor Stinner | 38430e2 | 2010-08-19 17:10:18 +0000 | [diff] [blame] | 469 | except BytesWarning: |
Victor Stinner | 6f35eda | 2010-10-29 00:38:58 +0000 | [diff] [blame] | 470 | # mixed_env cannot be created with python -bb |
Victor Stinner | 38430e2 | 2010-08-19 17:10:18 +0000 | [diff] [blame] | 471 | pass |
| 472 | else: |
| 473 | self.assertRaises(ValueError, os.get_exec_path, mixed_env) |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 474 | |
| 475 | # bytes key and/or value |
| 476 | self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}), |
| 477 | ['abc']) |
| 478 | self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}), |
| 479 | ['abc']) |
| 480 | self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}), |
| 481 | ['abc']) |
| 482 | |
| 483 | @unittest.skipUnless(os.supports_bytes_environ, |
| 484 | "os.environb required for this test.") |
Victor Stinner | 84ae118 | 2010-05-06 22:05:07 +0000 | [diff] [blame] | 485 | def test_environb(self): |
| 486 | # os.environ -> os.environb |
| 487 | value = 'euro\u20ac' |
| 488 | try: |
Benjamin Peterson | 180799d | 2010-05-06 22:25:42 +0000 | [diff] [blame] | 489 | value_bytes = value.encode(sys.getfilesystemencoding(), |
| 490 | 'surrogateescape') |
Victor Stinner | 84ae118 | 2010-05-06 22:05:07 +0000 | [diff] [blame] | 491 | except UnicodeEncodeError: |
Benjamin Peterson | 180799d | 2010-05-06 22:25:42 +0000 | [diff] [blame] | 492 | msg = "U+20AC character is not encodable to %s" % ( |
| 493 | sys.getfilesystemencoding(),) |
Benjamin Peterson | 932d3f4 | 2010-05-06 22:26:31 +0000 | [diff] [blame] | 494 | self.skipTest(msg) |
Victor Stinner | 84ae118 | 2010-05-06 22:05:07 +0000 | [diff] [blame] | 495 | os.environ['unicode'] = value |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 496 | self.assertEqual(os.environ['unicode'], value) |
| 497 | self.assertEqual(os.environb[b'unicode'], value_bytes) |
Victor Stinner | 84ae118 | 2010-05-06 22:05:07 +0000 | [diff] [blame] | 498 | |
| 499 | # os.environb -> os.environ |
| 500 | value = b'\xff' |
| 501 | os.environb[b'bytes'] = value |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 502 | self.assertEqual(os.environb[b'bytes'], value) |
Victor Stinner | 84ae118 | 2010-05-06 22:05:07 +0000 | [diff] [blame] | 503 | value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape') |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 504 | self.assertEqual(os.environ['bytes'], value_str) |
Ezio Melotti | 19e4acf | 2010-02-22 15:59:01 +0000 | [diff] [blame] | 505 | |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 506 | class WalkTests(unittest.TestCase): |
| 507 | """Tests for os.walk().""" |
| 508 | |
| 509 | def test_traversal(self): |
| 510 | import os |
| 511 | from os.path import join |
| 512 | |
| 513 | # Build: |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 514 | # TESTFN/ |
| 515 | # TEST1/ a file kid and two directory kids |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 516 | # tmp1 |
| 517 | # SUB1/ a file kid and a directory kid |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 518 | # tmp2 |
| 519 | # SUB11/ no kids |
| 520 | # SUB2/ a file kid and a dirsymlink kid |
| 521 | # tmp3 |
| 522 | # link/ a symlink to TESTFN.2 |
| 523 | # TEST2/ |
| 524 | # tmp4 a lone file |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 525 | walk_path = join(support.TESTFN, "TEST1") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 526 | sub1_path = join(walk_path, "SUB1") |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 527 | sub11_path = join(sub1_path, "SUB11") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 528 | sub2_path = join(walk_path, "SUB2") |
| 529 | tmp1_path = join(walk_path, "tmp1") |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 530 | tmp2_path = join(sub1_path, "tmp2") |
| 531 | tmp3_path = join(sub2_path, "tmp3") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 532 | link_path = join(sub2_path, "link") |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 533 | t2_path = join(support.TESTFN, "TEST2") |
| 534 | tmp4_path = join(support.TESTFN, "TEST2", "tmp4") |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 535 | |
| 536 | # Create stuff. |
| 537 | os.makedirs(sub11_path) |
| 538 | os.makedirs(sub2_path) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 539 | os.makedirs(t2_path) |
| 540 | for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path: |
Alex Martelli | 01c77c6 | 2006-08-24 02:58:11 +0000 | [diff] [blame] | 541 | f = open(path, "w") |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 542 | f.write("I'm " + path + " and proud of it. Blame test_os.\n") |
| 543 | f.close() |
Brian Curtin | d40e6f7 | 2010-07-08 21:39:08 +0000 | [diff] [blame] | 544 | if support.can_symlink(): |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 545 | os.symlink(os.path.abspath(t2_path), link_path) |
| 546 | sub2_tree = (sub2_path, ["link"], ["tmp3"]) |
| 547 | else: |
| 548 | sub2_tree = (sub2_path, [], ["tmp3"]) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 549 | |
| 550 | # Walk top-down. |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 551 | all = list(os.walk(walk_path)) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 552 | self.assertEqual(len(all), 4) |
| 553 | # We can't know which order SUB1 and SUB2 will appear in. |
| 554 | # Not flipped: TESTFN, SUB1, SUB11, SUB2 |
| 555 | # flipped: TESTFN, SUB2, SUB1, SUB11 |
| 556 | flipped = all[0][1][0] != "SUB1" |
| 557 | all[0][1].sort() |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 558 | self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"])) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 559 | self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"])) |
| 560 | self.assertEqual(all[2 + flipped], (sub11_path, [], [])) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 561 | self.assertEqual(all[3 - 2 * flipped], sub2_tree) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 562 | |
| 563 | # Prune the search. |
| 564 | all = [] |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 565 | for root, dirs, files in os.walk(walk_path): |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 566 | all.append((root, dirs, files)) |
| 567 | # Don't descend into SUB1. |
| 568 | if 'SUB1' in dirs: |
| 569 | # Note that this also mutates the dirs we appended to all! |
| 570 | dirs.remove('SUB1') |
| 571 | self.assertEqual(len(all), 2) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 572 | self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"])) |
| 573 | self.assertEqual(all[1], sub2_tree) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 574 | |
| 575 | # Walk bottom-up. |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 576 | all = list(os.walk(walk_path, topdown=False)) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 577 | self.assertEqual(len(all), 4) |
| 578 | # We can't know which order SUB1 and SUB2 will appear in. |
| 579 | # Not flipped: SUB11, SUB1, SUB2, TESTFN |
| 580 | # flipped: SUB2, SUB11, SUB1, TESTFN |
| 581 | flipped = all[3][1][0] != "SUB1" |
| 582 | all[3][1].sort() |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 583 | self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"])) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 584 | self.assertEqual(all[flipped], (sub11_path, [], [])) |
| 585 | self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"])) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 586 | self.assertEqual(all[2 - 2 * flipped], sub2_tree) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 587 | |
Brian Curtin | d40e6f7 | 2010-07-08 21:39:08 +0000 | [diff] [blame] | 588 | if support.can_symlink(): |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 589 | # Walk, following symlinks. |
| 590 | for root, dirs, files in os.walk(walk_path, followlinks=True): |
| 591 | if root == link_path: |
| 592 | self.assertEqual(dirs, []) |
| 593 | self.assertEqual(files, ["tmp4"]) |
| 594 | break |
| 595 | else: |
| 596 | self.fail("Didn't follow symlink with followlinks=True") |
| 597 | |
| 598 | def tearDown(self): |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 599 | # Tear everything down. This is a decent use for bottom-up on |
| 600 | # Windows, which doesn't have a recursive delete command. The |
| 601 | # (not so) subtlety is that rmdir will fail unless the dir's |
| 602 | # kids are removed first, so bottom up is essential. |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 603 | for root, dirs, files in os.walk(support.TESTFN, topdown=False): |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 604 | for name in files: |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 605 | os.remove(os.path.join(root, name)) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 606 | for name in dirs: |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 607 | dirname = os.path.join(root, name) |
| 608 | if not os.path.islink(dirname): |
| 609 | os.rmdir(dirname) |
| 610 | else: |
| 611 | os.remove(dirname) |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 612 | os.rmdir(support.TESTFN) |
Tim Peters | c4e0940 | 2003-04-25 07:11:48 +0000 | [diff] [blame] | 613 | |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 614 | class MakedirTests(unittest.TestCase): |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 615 | def setUp(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 616 | os.mkdir(support.TESTFN) |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 617 | |
| 618 | def test_makedir(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 619 | base = support.TESTFN |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 620 | path = os.path.join(base, 'dir1', 'dir2', 'dir3') |
| 621 | os.makedirs(path) # Should work |
| 622 | path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4') |
| 623 | os.makedirs(path) |
| 624 | |
| 625 | # Try paths with a '.' in them |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 626 | self.assertRaises(OSError, os.makedirs, os.curdir) |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 627 | path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir) |
| 628 | os.makedirs(path) |
| 629 | path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4', |
| 630 | 'dir5', 'dir6') |
| 631 | os.makedirs(path) |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 632 | |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 633 | def tearDown(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 634 | path = os.path.join(support.TESTFN, 'dir1', 'dir2', 'dir3', |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 635 | 'dir4', 'dir5', 'dir6') |
| 636 | # If the tests failed, the bottom-most directory ('../dir6') |
| 637 | # may not have been created, so we look for the outermost directory |
| 638 | # that exists. |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 639 | while not os.path.exists(path) and path != support.TESTFN: |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 640 | path = os.path.dirname(path) |
| 641 | |
| 642 | os.removedirs(path) |
| 643 | |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 644 | class DevNullTests(unittest.TestCase): |
Martin v. Löwis | bdec50f | 2004-06-08 08:29:33 +0000 | [diff] [blame] | 645 | def test_devnull(self): |
Alex Martelli | 01c77c6 | 2006-08-24 02:58:11 +0000 | [diff] [blame] | 646 | f = open(os.devnull, 'w') |
Martin v. Löwis | bdec50f | 2004-06-08 08:29:33 +0000 | [diff] [blame] | 647 | f.write('hello') |
| 648 | f.close() |
Alex Martelli | 01c77c6 | 2006-08-24 02:58:11 +0000 | [diff] [blame] | 649 | f = open(os.devnull, 'r') |
Tim Peters | 4182cfd | 2004-06-08 20:34:34 +0000 | [diff] [blame] | 650 | self.assertEqual(f.read(), '') |
Martin v. Löwis | bdec50f | 2004-06-08 08:29:33 +0000 | [diff] [blame] | 651 | f.close() |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 652 | |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 653 | class URandomTests(unittest.TestCase): |
Martin v. Löwis | dc3883f | 2004-08-29 15:46:35 +0000 | [diff] [blame] | 654 | def test_urandom(self): |
| 655 | try: |
| 656 | self.assertEqual(len(os.urandom(1)), 1) |
| 657 | self.assertEqual(len(os.urandom(10)), 10) |
| 658 | self.assertEqual(len(os.urandom(100)), 100) |
| 659 | self.assertEqual(len(os.urandom(1000)), 1000) |
| 660 | except NotImplementedError: |
| 661 | pass |
| 662 | |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 663 | @contextlib.contextmanager |
| 664 | def _execvpe_mockup(defpath=None): |
| 665 | """ |
| 666 | Stubs out execv and execve functions when used as context manager. |
| 667 | Records exec calls. The mock execv and execve functions always raise an |
| 668 | exception as they would normally never return. |
| 669 | """ |
| 670 | # A list of tuples containing (function name, first arg, args) |
| 671 | # of calls to execv or execve that have been made. |
| 672 | calls = [] |
| 673 | |
| 674 | def mock_execv(name, *args): |
| 675 | calls.append(('execv', name, args)) |
| 676 | raise RuntimeError("execv called") |
| 677 | |
| 678 | def mock_execve(name, *args): |
| 679 | calls.append(('execve', name, args)) |
| 680 | raise OSError(errno.ENOTDIR, "execve called") |
| 681 | |
| 682 | try: |
| 683 | orig_execv = os.execv |
| 684 | orig_execve = os.execve |
| 685 | orig_defpath = os.defpath |
| 686 | os.execv = mock_execv |
| 687 | os.execve = mock_execve |
| 688 | if defpath is not None: |
| 689 | os.defpath = defpath |
| 690 | yield calls |
| 691 | finally: |
| 692 | os.execv = orig_execv |
| 693 | os.execve = orig_execve |
| 694 | os.defpath = orig_defpath |
| 695 | |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 696 | class ExecTests(unittest.TestCase): |
Mark Dickinson | 7cf0389 | 2010-04-16 13:45:35 +0000 | [diff] [blame] | 697 | @unittest.skipIf(USING_LINUXTHREADS, |
| 698 | "avoid triggering a linuxthreads bug: see issue #4970") |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 699 | def test_execvpe_with_bad_program(self): |
Mark Dickinson | 7cf0389 | 2010-04-16 13:45:35 +0000 | [diff] [blame] | 700 | self.assertRaises(OSError, os.execvpe, 'no such app-', |
| 701 | ['no such app-'], None) |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 702 | |
Thomas Heller | 6790d60 | 2007-08-30 17:15:14 +0000 | [diff] [blame] | 703 | def test_execvpe_with_bad_arglist(self): |
| 704 | self.assertRaises(ValueError, os.execvpe, 'notepad', [], None) |
| 705 | |
Gregory P. Smith | 4ae3777 | 2010-05-08 18:05:46 +0000 | [diff] [blame] | 706 | @unittest.skipUnless(hasattr(os, '_execvpe'), |
| 707 | "No internal os._execvpe function to test.") |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 708 | def _test_internal_execvpe(self, test_type): |
| 709 | program_path = os.sep + 'absolutepath' |
| 710 | if test_type is bytes: |
| 711 | program = b'executable' |
| 712 | fullpath = os.path.join(os.fsencode(program_path), program) |
| 713 | native_fullpath = fullpath |
| 714 | arguments = [b'progname', 'arg1', 'arg2'] |
| 715 | else: |
| 716 | program = 'executable' |
| 717 | arguments = ['progname', 'arg1', 'arg2'] |
| 718 | fullpath = os.path.join(program_path, program) |
| 719 | if os.name != "nt": |
| 720 | native_fullpath = os.fsencode(fullpath) |
| 721 | else: |
| 722 | native_fullpath = fullpath |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 723 | env = {'spam': 'beans'} |
| 724 | |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 725 | # test os._execvpe() with an absolute path |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 726 | with _execvpe_mockup() as calls: |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 727 | self.assertRaises(RuntimeError, |
| 728 | os._execvpe, fullpath, arguments) |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 729 | self.assertEqual(len(calls), 1) |
| 730 | self.assertEqual(calls[0], ('execv', fullpath, (arguments,))) |
| 731 | |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 732 | # test os._execvpe() with a relative path: |
| 733 | # os.get_exec_path() returns defpath |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 734 | with _execvpe_mockup(defpath=program_path) as calls: |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 735 | self.assertRaises(OSError, |
| 736 | os._execvpe, program, arguments, env=env) |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 737 | self.assertEqual(len(calls), 1) |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 738 | self.assertSequenceEqual(calls[0], |
| 739 | ('execve', native_fullpath, (arguments, env))) |
| 740 | |
| 741 | # test os._execvpe() with a relative path: |
| 742 | # os.get_exec_path() reads the 'PATH' variable |
| 743 | with _execvpe_mockup() as calls: |
| 744 | env_path = env.copy() |
Victor Stinner | 38430e2 | 2010-08-19 17:10:18 +0000 | [diff] [blame] | 745 | if test_type is bytes: |
| 746 | env_path[b'PATH'] = program_path |
| 747 | else: |
| 748 | env_path['PATH'] = program_path |
Victor Stinner | b745a74 | 2010-05-18 17:17:23 +0000 | [diff] [blame] | 749 | self.assertRaises(OSError, |
| 750 | os._execvpe, program, arguments, env=env_path) |
| 751 | self.assertEqual(len(calls), 1) |
| 752 | self.assertSequenceEqual(calls[0], |
| 753 | ('execve', native_fullpath, (arguments, env_path))) |
| 754 | |
| 755 | def test_internal_execvpe_str(self): |
| 756 | self._test_internal_execvpe(str) |
| 757 | if os.name != "nt": |
| 758 | self._test_internal_execvpe(bytes) |
Victor Stinner | c2d095f | 2010-05-17 00:14:53 +0000 | [diff] [blame] | 759 | |
Gregory P. Smith | 4ae3777 | 2010-05-08 18:05:46 +0000 | [diff] [blame] | 760 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 761 | class Win32ErrorTests(unittest.TestCase): |
| 762 | def test_rename(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 763 | self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 764 | |
| 765 | def test_remove(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 766 | self.assertRaises(WindowsError, os.remove, support.TESTFN) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 767 | |
| 768 | def test_chdir(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 769 | self.assertRaises(WindowsError, os.chdir, support.TESTFN) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 770 | |
| 771 | def test_mkdir(self): |
Amaury Forgeot d'Arc | 2fc224f | 2009-02-19 23:23:47 +0000 | [diff] [blame] | 772 | f = open(support.TESTFN, "w") |
Benjamin Peterson | f91df04 | 2009-02-13 02:50:59 +0000 | [diff] [blame] | 773 | try: |
| 774 | self.assertRaises(WindowsError, os.mkdir, support.TESTFN) |
| 775 | finally: |
| 776 | f.close() |
Amaury Forgeot d'Arc | 2fc224f | 2009-02-19 23:23:47 +0000 | [diff] [blame] | 777 | os.unlink(support.TESTFN) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 778 | |
| 779 | def test_utime(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 780 | self.assertRaises(WindowsError, os.utime, support.TESTFN, None) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 781 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 782 | def test_chmod(self): |
Benjamin Peterson | f91df04 | 2009-02-13 02:50:59 +0000 | [diff] [blame] | 783 | self.assertRaises(WindowsError, os.chmod, support.TESTFN, 0) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 784 | |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 785 | class TestInvalidFD(unittest.TestCase): |
Benjamin Peterson | 05e782f | 2009-01-19 15:15:02 +0000 | [diff] [blame] | 786 | singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat", |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 787 | "fstatvfs", "fsync", "tcgetpgrp", "ttyname"] |
| 788 | #singles.append("close") |
| 789 | #We omit close because it doesn'r raise an exception on some platforms |
| 790 | def get_single(f): |
| 791 | def helper(self): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 792 | if hasattr(os, f): |
| 793 | self.check(getattr(os, f)) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 794 | return helper |
| 795 | for f in singles: |
| 796 | locals()["test_"+f] = get_single(f) |
| 797 | |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 798 | def check(self, f, *args): |
Benjamin Peterson | 5c6d787 | 2009-02-06 02:40:07 +0000 | [diff] [blame] | 799 | try: |
| 800 | f(support.make_bad_fd(), *args) |
| 801 | except OSError as e: |
| 802 | self.assertEqual(e.errno, errno.EBADF) |
| 803 | else: |
| 804 | self.fail("%r didn't raise a OSError with a bad file descriptor" |
| 805 | % f) |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 806 | |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 807 | def test_isatty(self): |
| 808 | if hasattr(os, "isatty"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 809 | self.assertEqual(os.isatty(support.make_bad_fd()), False) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 810 | |
| 811 | def test_closerange(self): |
| 812 | if hasattr(os, "closerange"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 813 | fd = support.make_bad_fd() |
R. David Murray | 630cc48 | 2009-07-22 15:20:27 +0000 | [diff] [blame] | 814 | # Make sure none of the descriptors we are about to close are |
| 815 | # currently valid (issue 6542). |
| 816 | for i in range(10): |
| 817 | try: os.fstat(fd+i) |
| 818 | except OSError: |
| 819 | pass |
| 820 | else: |
| 821 | break |
| 822 | if i < 2: |
| 823 | raise unittest.SkipTest( |
| 824 | "Unable to acquire a range of invalid file descriptors") |
| 825 | self.assertEqual(os.closerange(fd, fd + i-1), None) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 826 | |
| 827 | def test_dup2(self): |
| 828 | if hasattr(os, "dup2"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 829 | self.check(os.dup2, 20) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 830 | |
| 831 | def test_fchmod(self): |
| 832 | if hasattr(os, "fchmod"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 833 | self.check(os.fchmod, 0) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 834 | |
| 835 | def test_fchown(self): |
| 836 | if hasattr(os, "fchown"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 837 | self.check(os.fchown, -1, -1) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 838 | |
| 839 | def test_fpathconf(self): |
| 840 | if hasattr(os, "fpathconf"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 841 | self.check(os.fpathconf, "PC_NAME_MAX") |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 842 | |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 843 | def test_ftruncate(self): |
| 844 | if hasattr(os, "ftruncate"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 845 | self.check(os.ftruncate, 0) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 846 | |
| 847 | def test_lseek(self): |
| 848 | if hasattr(os, "lseek"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 849 | self.check(os.lseek, 0, 0) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 850 | |
| 851 | def test_read(self): |
| 852 | if hasattr(os, "read"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 853 | self.check(os.read, 1) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 854 | |
| 855 | def test_tcsetpgrpt(self): |
| 856 | if hasattr(os, "tcsetpgrp"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 857 | self.check(os.tcsetpgrp, 0) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 858 | |
| 859 | def test_write(self): |
| 860 | if hasattr(os, "write"): |
Benjamin Peterson | 7522c74 | 2009-01-19 21:00:09 +0000 | [diff] [blame] | 861 | self.check(os.write, b" ") |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 862 | |
Brian Curtin | 1b9df39 | 2010-11-24 20:24:31 +0000 | [diff] [blame] | 863 | |
| 864 | class LinkTests(unittest.TestCase): |
| 865 | def setUp(self): |
| 866 | self.file1 = support.TESTFN |
| 867 | self.file2 = os.path.join(support.TESTFN + "2") |
| 868 | |
| 869 | for file in (self.file1, self.file2): |
| 870 | if os.path.exists(file): |
| 871 | os.unlink(file) |
| 872 | |
| 873 | tearDown = setUp |
| 874 | |
| 875 | def _test_link(self, file1, file2): |
| 876 | with open(file1, "w") as f1: |
| 877 | f1.write("test") |
| 878 | |
| 879 | os.link(file1, file2) |
| 880 | with open(file1, "r") as f1, open(file2, "r") as f2: |
| 881 | self.assertTrue(os.path.sameopenfile(f1.fileno(), f2.fileno())) |
| 882 | |
| 883 | def test_link(self): |
| 884 | self._test_link(self.file1, self.file2) |
| 885 | |
| 886 | def test_link_bytes(self): |
| 887 | self._test_link(bytes(self.file1, sys.getfilesystemencoding()), |
| 888 | bytes(self.file2, sys.getfilesystemencoding())) |
| 889 | |
Brian Curtin | f498b75 | 2010-11-30 15:54:04 +0000 | [diff] [blame^] | 890 | def test_unicode_name(self): |
Brian Curtin | 43f0c27 | 2010-11-30 15:40:04 +0000 | [diff] [blame] | 891 | try: |
Brian Curtin | f498b75 | 2010-11-30 15:54:04 +0000 | [diff] [blame^] | 892 | os.fsencode("\xf1") |
Brian Curtin | 43f0c27 | 2010-11-30 15:40:04 +0000 | [diff] [blame] | 893 | except UnicodeError: |
| 894 | raise unittest.SkipTest("Unable to encode for this platform.") |
| 895 | |
Brian Curtin | f498b75 | 2010-11-30 15:54:04 +0000 | [diff] [blame^] | 896 | self.file1 += "\xf1" |
Brian Curtin | fc889c4 | 2010-11-28 23:59:46 +0000 | [diff] [blame] | 897 | self.file2 = self.file1 + "2" |
| 898 | self._test_link(self.file1, self.file2) |
| 899 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 900 | if sys.platform != 'win32': |
| 901 | class Win32ErrorTests(unittest.TestCase): |
| 902 | pass |
| 903 | |
Benjamin Peterson | ef3e4c2 | 2009-04-11 19:48:14 +0000 | [diff] [blame] | 904 | class PosixUidGidTests(unittest.TestCase): |
| 905 | if hasattr(os, 'setuid'): |
| 906 | def test_setuid(self): |
| 907 | if os.getuid() != 0: |
| 908 | self.assertRaises(os.error, os.setuid, 0) |
| 909 | self.assertRaises(OverflowError, os.setuid, 1<<32) |
| 910 | |
| 911 | if hasattr(os, 'setgid'): |
| 912 | def test_setgid(self): |
| 913 | if os.getuid() != 0: |
| 914 | self.assertRaises(os.error, os.setgid, 0) |
| 915 | self.assertRaises(OverflowError, os.setgid, 1<<32) |
| 916 | |
| 917 | if hasattr(os, 'seteuid'): |
| 918 | def test_seteuid(self): |
| 919 | if os.getuid() != 0: |
| 920 | self.assertRaises(os.error, os.seteuid, 0) |
| 921 | self.assertRaises(OverflowError, os.seteuid, 1<<32) |
| 922 | |
| 923 | if hasattr(os, 'setegid'): |
| 924 | def test_setegid(self): |
| 925 | if os.getuid() != 0: |
| 926 | self.assertRaises(os.error, os.setegid, 0) |
| 927 | self.assertRaises(OverflowError, os.setegid, 1<<32) |
| 928 | |
| 929 | if hasattr(os, 'setreuid'): |
| 930 | def test_setreuid(self): |
| 931 | if os.getuid() != 0: |
| 932 | self.assertRaises(os.error, os.setreuid, 0, 0) |
| 933 | self.assertRaises(OverflowError, os.setreuid, 1<<32, 0) |
| 934 | self.assertRaises(OverflowError, os.setreuid, 0, 1<<32) |
Benjamin Peterson | ebe87ba | 2010-03-06 20:34:24 +0000 | [diff] [blame] | 935 | |
| 936 | def test_setreuid_neg1(self): |
| 937 | # Needs to accept -1. We run this in a subprocess to avoid |
| 938 | # altering the test runner's process state (issue8045). |
Benjamin Peterson | ebe87ba | 2010-03-06 20:34:24 +0000 | [diff] [blame] | 939 | subprocess.check_call([ |
| 940 | sys.executable, '-c', |
| 941 | 'import os,sys;os.setreuid(-1,-1);sys.exit(0)']) |
Benjamin Peterson | ef3e4c2 | 2009-04-11 19:48:14 +0000 | [diff] [blame] | 942 | |
| 943 | if hasattr(os, 'setregid'): |
| 944 | def test_setregid(self): |
| 945 | if os.getuid() != 0: |
| 946 | self.assertRaises(os.error, os.setregid, 0, 0) |
| 947 | self.assertRaises(OverflowError, os.setregid, 1<<32, 0) |
| 948 | self.assertRaises(OverflowError, os.setregid, 0, 1<<32) |
Benjamin Peterson | ebe87ba | 2010-03-06 20:34:24 +0000 | [diff] [blame] | 949 | |
| 950 | def test_setregid_neg1(self): |
| 951 | # Needs to accept -1. We run this in a subprocess to avoid |
| 952 | # altering the test runner's process state (issue8045). |
Benjamin Peterson | ebe87ba | 2010-03-06 20:34:24 +0000 | [diff] [blame] | 953 | subprocess.check_call([ |
| 954 | sys.executable, '-c', |
| 955 | 'import os,sys;os.setregid(-1,-1);sys.exit(0)']) |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 956 | |
| 957 | class Pep383Tests(unittest.TestCase): |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 958 | def setUp(self): |
Victor Stinner | d91df1a | 2010-08-18 10:56:19 +0000 | [diff] [blame] | 959 | if support.TESTFN_UNENCODABLE: |
| 960 | self.dir = support.TESTFN_UNENCODABLE |
| 961 | else: |
| 962 | self.dir = support.TESTFN |
| 963 | self.bdir = os.fsencode(self.dir) |
| 964 | |
| 965 | bytesfn = [] |
| 966 | def add_filename(fn): |
| 967 | try: |
| 968 | fn = os.fsencode(fn) |
| 969 | except UnicodeEncodeError: |
| 970 | return |
| 971 | bytesfn.append(fn) |
| 972 | add_filename(support.TESTFN_UNICODE) |
| 973 | if support.TESTFN_UNENCODABLE: |
| 974 | add_filename(support.TESTFN_UNENCODABLE) |
| 975 | if not bytesfn: |
| 976 | self.skipTest("couldn't create any non-ascii filename") |
| 977 | |
| 978 | self.unicodefn = set() |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 979 | os.mkdir(self.dir) |
Victor Stinner | d91df1a | 2010-08-18 10:56:19 +0000 | [diff] [blame] | 980 | try: |
| 981 | for fn in bytesfn: |
| 982 | f = open(os.path.join(self.bdir, fn), "w") |
| 983 | f.close() |
Victor Stinner | e8d5145 | 2010-08-19 01:05:19 +0000 | [diff] [blame] | 984 | fn = os.fsdecode(fn) |
Victor Stinner | d91df1a | 2010-08-18 10:56:19 +0000 | [diff] [blame] | 985 | if fn in self.unicodefn: |
| 986 | raise ValueError("duplicate filename") |
| 987 | self.unicodefn.add(fn) |
| 988 | except: |
| 989 | shutil.rmtree(self.dir) |
| 990 | raise |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 991 | |
| 992 | def tearDown(self): |
| 993 | shutil.rmtree(self.dir) |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 994 | |
| 995 | def test_listdir(self): |
Victor Stinner | d91df1a | 2010-08-18 10:56:19 +0000 | [diff] [blame] | 996 | expected = self.unicodefn |
| 997 | found = set(os.listdir(self.dir)) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 998 | self.assertEqual(found, expected) |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 999 | |
| 1000 | def test_open(self): |
| 1001 | for fn in self.unicodefn: |
| 1002 | f = open(os.path.join(self.dir, fn)) |
| 1003 | f.close() |
| 1004 | |
| 1005 | def test_stat(self): |
| 1006 | for fn in self.unicodefn: |
| 1007 | os.stat(os.path.join(self.dir, fn)) |
Benjamin Peterson | ef3e4c2 | 2009-04-11 19:48:14 +0000 | [diff] [blame] | 1008 | else: |
| 1009 | class PosixUidGidTests(unittest.TestCase): |
| 1010 | pass |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1011 | class Pep383Tests(unittest.TestCase): |
| 1012 | pass |
Benjamin Peterson | ef3e4c2 | 2009-04-11 19:48:14 +0000 | [diff] [blame] | 1013 | |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1014 | @unittest.skipUnless(sys.platform == "win32", "Win32 specific tests") |
| 1015 | class Win32KillTests(unittest.TestCase): |
Brian Curtin | c3acbc3 | 2010-05-28 16:08:40 +0000 | [diff] [blame] | 1016 | def _kill(self, sig): |
| 1017 | # Start sys.executable as a subprocess and communicate from the |
| 1018 | # subprocess to the parent that the interpreter is ready. When it |
| 1019 | # becomes ready, send *sig* via os.kill to the subprocess and check |
| 1020 | # that the return code is equal to *sig*. |
| 1021 | import ctypes |
| 1022 | from ctypes import wintypes |
| 1023 | import msvcrt |
| 1024 | |
| 1025 | # Since we can't access the contents of the process' stdout until the |
| 1026 | # process has exited, use PeekNamedPipe to see what's inside stdout |
| 1027 | # without waiting. This is done so we can tell that the interpreter |
| 1028 | # is started and running at a point where it could handle a signal. |
| 1029 | PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe |
| 1030 | PeekNamedPipe.restype = wintypes.BOOL |
| 1031 | PeekNamedPipe.argtypes = (wintypes.HANDLE, # Pipe handle |
| 1032 | ctypes.POINTER(ctypes.c_char), # stdout buf |
| 1033 | wintypes.DWORD, # Buffer size |
| 1034 | ctypes.POINTER(wintypes.DWORD), # bytes read |
| 1035 | ctypes.POINTER(wintypes.DWORD), # bytes avail |
| 1036 | ctypes.POINTER(wintypes.DWORD)) # bytes left |
| 1037 | msg = "running" |
| 1038 | proc = subprocess.Popen([sys.executable, "-c", |
| 1039 | "import sys;" |
| 1040 | "sys.stdout.write('{}');" |
| 1041 | "sys.stdout.flush();" |
| 1042 | "input()".format(msg)], |
| 1043 | stdout=subprocess.PIPE, |
| 1044 | stderr=subprocess.PIPE, |
| 1045 | stdin=subprocess.PIPE) |
Brian Curtin | 43ec577 | 2010-11-05 15:17:11 +0000 | [diff] [blame] | 1046 | self.addCleanup(proc.stdout.close) |
| 1047 | self.addCleanup(proc.stderr.close) |
| 1048 | self.addCleanup(proc.stdin.close) |
Brian Curtin | c3acbc3 | 2010-05-28 16:08:40 +0000 | [diff] [blame] | 1049 | |
| 1050 | count, max = 0, 100 |
| 1051 | while count < max and proc.poll() is None: |
| 1052 | # Create a string buffer to store the result of stdout from the pipe |
| 1053 | buf = ctypes.create_string_buffer(len(msg)) |
| 1054 | # Obtain the text currently in proc.stdout |
| 1055 | # Bytes read/avail/left are left as NULL and unused |
| 1056 | rslt = PeekNamedPipe(msvcrt.get_osfhandle(proc.stdout.fileno()), |
| 1057 | buf, ctypes.sizeof(buf), None, None, None) |
| 1058 | self.assertNotEqual(rslt, 0, "PeekNamedPipe failed") |
| 1059 | if buf.value: |
| 1060 | self.assertEqual(msg, buf.value.decode()) |
| 1061 | break |
| 1062 | time.sleep(0.1) |
| 1063 | count += 1 |
| 1064 | else: |
| 1065 | self.fail("Did not receive communication from the subprocess") |
| 1066 | |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1067 | os.kill(proc.pid, sig) |
| 1068 | self.assertEqual(proc.wait(), sig) |
| 1069 | |
| 1070 | def test_kill_sigterm(self): |
| 1071 | # SIGTERM doesn't mean anything special, but make sure it works |
Brian Curtin | c3acbc3 | 2010-05-28 16:08:40 +0000 | [diff] [blame] | 1072 | self._kill(signal.SIGTERM) |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1073 | |
| 1074 | def test_kill_int(self): |
| 1075 | # os.kill on Windows can take an int which gets set as the exit code |
Brian Curtin | c3acbc3 | 2010-05-28 16:08:40 +0000 | [diff] [blame] | 1076 | self._kill(100) |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1077 | |
| 1078 | def _kill_with_event(self, event, name): |
Hirokazu Yamamoto | 54c950f | 2010-10-08 08:38:15 +0000 | [diff] [blame] | 1079 | tagname = "test_os_%s" % uuid.uuid1() |
| 1080 | m = mmap.mmap(-1, 1, tagname) |
| 1081 | m[0] = 0 |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1082 | # Run a script which has console control handling enabled. |
| 1083 | proc = subprocess.Popen([sys.executable, |
| 1084 | os.path.join(os.path.dirname(__file__), |
Hirokazu Yamamoto | 54c950f | 2010-10-08 08:38:15 +0000 | [diff] [blame] | 1085 | "win_console_handler.py"), tagname], |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1086 | creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) |
| 1087 | # Let the interpreter startup before we send signals. See #3137. |
Hirokazu Yamamoto | 54c950f | 2010-10-08 08:38:15 +0000 | [diff] [blame] | 1088 | count, max = 0, 20 |
| 1089 | while count < max and proc.poll() is None: |
Brian Curtin | f668df5 | 2010-10-15 14:21:06 +0000 | [diff] [blame] | 1090 | if m[0] == 1: |
Hirokazu Yamamoto | 54c950f | 2010-10-08 08:38:15 +0000 | [diff] [blame] | 1091 | break |
| 1092 | time.sleep(0.5) |
| 1093 | count += 1 |
| 1094 | else: |
| 1095 | self.fail("Subprocess didn't finish initialization") |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1096 | os.kill(proc.pid, event) |
| 1097 | # proc.send_signal(event) could also be done here. |
| 1098 | # Allow time for the signal to be passed and the process to exit. |
| 1099 | time.sleep(0.5) |
| 1100 | if not proc.poll(): |
| 1101 | # Forcefully kill the process if we weren't able to signal it. |
| 1102 | os.kill(proc.pid, signal.SIGINT) |
| 1103 | self.fail("subprocess did not stop on {}".format(name)) |
| 1104 | |
| 1105 | @unittest.skip("subprocesses aren't inheriting CTRL+C property") |
| 1106 | def test_CTRL_C_EVENT(self): |
| 1107 | from ctypes import wintypes |
| 1108 | import ctypes |
| 1109 | |
| 1110 | # Make a NULL value by creating a pointer with no argument. |
| 1111 | NULL = ctypes.POINTER(ctypes.c_int)() |
| 1112 | SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler |
| 1113 | SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int), |
| 1114 | wintypes.BOOL) |
| 1115 | SetConsoleCtrlHandler.restype = wintypes.BOOL |
| 1116 | |
| 1117 | # Calling this with NULL and FALSE causes the calling process to |
| 1118 | # handle CTRL+C, rather than ignore it. This property is inherited |
| 1119 | # by subprocesses. |
| 1120 | SetConsoleCtrlHandler(NULL, 0) |
| 1121 | |
| 1122 | self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT") |
| 1123 | |
| 1124 | def test_CTRL_BREAK_EVENT(self): |
| 1125 | self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT") |
| 1126 | |
| 1127 | |
Brian Curtin | d40e6f7 | 2010-07-08 21:39:08 +0000 | [diff] [blame] | 1128 | def skipUnlessWindows6(test): |
Brian Curtin | 74e4561 | 2010-07-09 15:58:59 +0000 | [diff] [blame] | 1129 | if (hasattr(sys, 'getwindowsversion') |
| 1130 | and sys.getwindowsversion().major >= 6): |
Brian Curtin | d40e6f7 | 2010-07-08 21:39:08 +0000 | [diff] [blame] | 1131 | return test |
| 1132 | return unittest.skip("Requires Windows Vista or later")(test) |
| 1133 | |
| 1134 | @unittest.skipUnless(sys.platform == "win32", "Win32 specific tests") |
| 1135 | @support.skip_unless_symlink |
| 1136 | class Win32SymlinkTests(unittest.TestCase): |
| 1137 | filelink = 'filelinktest' |
| 1138 | filelink_target = os.path.abspath(__file__) |
| 1139 | dirlink = 'dirlinktest' |
| 1140 | dirlink_target = os.path.dirname(filelink_target) |
| 1141 | missing_link = 'missing link' |
| 1142 | |
| 1143 | def setUp(self): |
| 1144 | assert os.path.exists(self.dirlink_target) |
| 1145 | assert os.path.exists(self.filelink_target) |
| 1146 | assert not os.path.exists(self.dirlink) |
| 1147 | assert not os.path.exists(self.filelink) |
| 1148 | assert not os.path.exists(self.missing_link) |
| 1149 | |
| 1150 | def tearDown(self): |
| 1151 | if os.path.exists(self.filelink): |
| 1152 | os.remove(self.filelink) |
| 1153 | if os.path.exists(self.dirlink): |
| 1154 | os.rmdir(self.dirlink) |
| 1155 | if os.path.lexists(self.missing_link): |
| 1156 | os.remove(self.missing_link) |
| 1157 | |
| 1158 | def test_directory_link(self): |
| 1159 | os.symlink(self.dirlink_target, self.dirlink) |
| 1160 | self.assertTrue(os.path.exists(self.dirlink)) |
| 1161 | self.assertTrue(os.path.isdir(self.dirlink)) |
| 1162 | self.assertTrue(os.path.islink(self.dirlink)) |
| 1163 | self.check_stat(self.dirlink, self.dirlink_target) |
| 1164 | |
| 1165 | def test_file_link(self): |
| 1166 | os.symlink(self.filelink_target, self.filelink) |
| 1167 | self.assertTrue(os.path.exists(self.filelink)) |
| 1168 | self.assertTrue(os.path.isfile(self.filelink)) |
| 1169 | self.assertTrue(os.path.islink(self.filelink)) |
| 1170 | self.check_stat(self.filelink, self.filelink_target) |
| 1171 | |
| 1172 | def _create_missing_dir_link(self): |
| 1173 | 'Create a "directory" link to a non-existent target' |
| 1174 | linkname = self.missing_link |
| 1175 | if os.path.lexists(linkname): |
| 1176 | os.remove(linkname) |
| 1177 | target = r'c:\\target does not exist.29r3c740' |
| 1178 | assert not os.path.exists(target) |
| 1179 | target_is_dir = True |
| 1180 | os.symlink(target, linkname, target_is_dir) |
| 1181 | |
| 1182 | def test_remove_directory_link_to_missing_target(self): |
| 1183 | self._create_missing_dir_link() |
| 1184 | # For compatibility with Unix, os.remove will check the |
| 1185 | # directory status and call RemoveDirectory if the symlink |
| 1186 | # was created with target_is_dir==True. |
| 1187 | os.remove(self.missing_link) |
| 1188 | |
| 1189 | @unittest.skip("currently fails; consider for improvement") |
| 1190 | def test_isdir_on_directory_link_to_missing_target(self): |
| 1191 | self._create_missing_dir_link() |
| 1192 | # consider having isdir return true for directory links |
| 1193 | self.assertTrue(os.path.isdir(self.missing_link)) |
| 1194 | |
| 1195 | @unittest.skip("currently fails; consider for improvement") |
| 1196 | def test_rmdir_on_directory_link_to_missing_target(self): |
| 1197 | self._create_missing_dir_link() |
| 1198 | # consider allowing rmdir to remove directory links |
| 1199 | os.rmdir(self.missing_link) |
| 1200 | |
| 1201 | def check_stat(self, link, target): |
| 1202 | self.assertEqual(os.stat(link), os.stat(target)) |
| 1203 | self.assertNotEqual(os.lstat(link), os.stat(link)) |
| 1204 | |
| 1205 | |
Victor Stinner | e8d5145 | 2010-08-19 01:05:19 +0000 | [diff] [blame] | 1206 | class FSEncodingTests(unittest.TestCase): |
| 1207 | def test_nop(self): |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 1208 | self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff') |
| 1209 | self.assertEqual(os.fsdecode('abc\u0141'), 'abc\u0141') |
Benjamin Peterson | 31191a9 | 2010-05-09 03:22:58 +0000 | [diff] [blame] | 1210 | |
Victor Stinner | e8d5145 | 2010-08-19 01:05:19 +0000 | [diff] [blame] | 1211 | def test_identity(self): |
| 1212 | # assert fsdecode(fsencode(x)) == x |
| 1213 | for fn in ('unicode\u0141', 'latin\xe9', 'ascii'): |
| 1214 | try: |
| 1215 | bytesfn = os.fsencode(fn) |
| 1216 | except UnicodeEncodeError: |
| 1217 | continue |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 1218 | self.assertEqual(os.fsdecode(bytesfn), fn) |
Victor Stinner | e8d5145 | 2010-08-19 01:05:19 +0000 | [diff] [blame] | 1219 | |
Victor Stinner | bf9bcab | 2010-05-09 03:15:33 +0000 | [diff] [blame] | 1220 | |
Amaury Forgeot d'Arc | 4b6fdf3 | 2010-09-07 21:31:17 +0000 | [diff] [blame] | 1221 | class PidTests(unittest.TestCase): |
| 1222 | @unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid") |
| 1223 | def test_getppid(self): |
| 1224 | p = subprocess.Popen([sys.executable, '-c', |
| 1225 | 'import os; print(os.getppid())'], |
| 1226 | stdout=subprocess.PIPE) |
| 1227 | stdout, _ = p.communicate() |
| 1228 | # We are the parent of our subprocess |
| 1229 | self.assertEqual(int(stdout), os.getpid()) |
| 1230 | |
| 1231 | |
Brian Curtin | 0151b8e | 2010-09-24 13:43:43 +0000 | [diff] [blame] | 1232 | # The introduction of this TestCase caused at least two different errors on |
| 1233 | # *nix buildbots. Temporarily skip this to let the buildbots move along. |
| 1234 | @unittest.skip("Skip due to platform/environment differences on *NIX buildbots") |
Brian Curtin | e8e4b3b | 2010-09-23 20:04:14 +0000 | [diff] [blame] | 1235 | @unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin") |
| 1236 | class LoginTests(unittest.TestCase): |
| 1237 | def test_getlogin(self): |
| 1238 | user_name = os.getlogin() |
| 1239 | self.assertNotEqual(len(user_name), 0) |
| 1240 | |
| 1241 | |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 1242 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1243 | support.run_unittest( |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1244 | FileTests, |
Walter Dörwald | 21d3a32 | 2003-05-01 17:45:56 +0000 | [diff] [blame] | 1245 | StatAttributeTests, |
| 1246 | EnvironTests, |
Andrew M. Kuchling | b386f6a | 2003-12-23 16:36:11 +0000 | [diff] [blame] | 1247 | WalkTests, |
| 1248 | MakedirTests, |
Martin v. Löwis | bdec50f | 2004-06-08 08:29:33 +0000 | [diff] [blame] | 1249 | DevNullTests, |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1250 | URandomTests, |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 1251 | ExecTests, |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 1252 | Win32ErrorTests, |
Benjamin Peterson | ef3e4c2 | 2009-04-11 19:48:14 +0000 | [diff] [blame] | 1253 | TestInvalidFD, |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1254 | PosixUidGidTests, |
Brian Curtin | eb24d74 | 2010-04-12 17:16:38 +0000 | [diff] [blame] | 1255 | Pep383Tests, |
Victor Stinner | bf9bcab | 2010-05-09 03:15:33 +0000 | [diff] [blame] | 1256 | Win32KillTests, |
Brian Curtin | d40e6f7 | 2010-07-08 21:39:08 +0000 | [diff] [blame] | 1257 | Win32SymlinkTests, |
Victor Stinner | e8d5145 | 2010-08-19 01:05:19 +0000 | [diff] [blame] | 1258 | FSEncodingTests, |
Amaury Forgeot d'Arc | 4b6fdf3 | 2010-09-07 21:31:17 +0000 | [diff] [blame] | 1259 | PidTests, |
Brian Curtin | e8e4b3b | 2010-09-23 20:04:14 +0000 | [diff] [blame] | 1260 | LoginTests, |
Brian Curtin | 1b9df39 | 2010-11-24 20:24:31 +0000 | [diff] [blame] | 1261 | LinkTests, |
Walter Dörwald | 21d3a32 | 2003-05-01 17:45:56 +0000 | [diff] [blame] | 1262 | ) |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 1263 | |
| 1264 | if __name__ == "__main__": |
| 1265 | test_main() |