blob: 544eee16b59ca92d27928e45616f1c755cbe49ba [file] [log] [blame]
Fred Drake38c2ef02001-07-17 20:52:51 +00001# 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örwaldf0dfc7a2003-10-20 14:01:56 +00003# portable than they had been thought to be.
Fred Drake38c2ef02001-07-17 20:52:51 +00004
5import os
Benjamin Peterson5c6d7872009-02-06 02:40:07 +00006import errno
Fred Drake38c2ef02001-07-17 20:52:51 +00007import unittest
Jeremy Hyltona7fc21b2001-08-20 20:10:01 +00008import warnings
Thomas Wouters477c8d52006-05-27 19:21:47 +00009import sys
Brian Curtineb24d742010-04-12 17:16:38 +000010import signal
11import subprocess
12import time
Martin v. Löwis011e8422009-05-05 04:43:17 +000013import shutil
Benjamin Petersonee8712c2008-05-20 21:35:26 +000014from test import support
Victor Stinnerc2d095f2010-05-17 00:14:53 +000015import contextlib
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +000016import mmap
17import uuid
Fred Drake38c2ef02001-07-17 20:52:51 +000018
Mark Dickinson7cf03892010-04-16 13:45:35 +000019# 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 Dickinson89589c92010-04-16 13:51:27 +000023if (hasattr(os, "confstr_names") and
24 "CS_GNU_LIBPTHREAD_VERSION" in os.confstr_names):
Mark Dickinson7cf03892010-04-16 13:45:35 +000025 libpthread = os.confstr("CS_GNU_LIBPTHREAD_VERSION")
26 USING_LINUXTHREADS= libpthread.startswith("linuxthreads")
27else:
28 USING_LINUXTHREADS= False
Brian Curtineb24d742010-04-12 17:16:38 +000029
Thomas Wouters0e3f5912006-08-11 14:57:12 +000030# Tests creating TESTFN
31class FileTests(unittest.TestCase):
32 def setUp(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +000033 if os.path.exists(support.TESTFN):
34 os.unlink(support.TESTFN)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000035 tearDown = setUp
36
37 def test_access(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +000038 f = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000039 os.close(f)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000040 self.assertTrue(os.access(support.TESTFN, os.W_OK))
Thomas Wouters0e3f5912006-08-11 14:57:12 +000041
Christian Heimesfdab48e2008-01-20 09:06:41 +000042 def test_closerange(self):
Antoine Pitroub9ee06c2008-08-16 22:03:17 +000043 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 Petersonfa0d7032009-06-01 22:42:33 +000055 self.skipTest("couldn't allocate two consecutive fds")
Antoine Pitroub9ee06c2008-08-16 22:03:17 +000056 first, second = second, os.dup(second)
57 finally:
58 os.close(second)
Christian Heimesfdab48e2008-01-20 09:06:41 +000059 # close a fd that is open, and one that isn't
Antoine Pitroub9ee06c2008-08-16 22:03:17 +000060 os.closerange(first, first + 2)
Antoine Pitrou9cadb1b2008-09-15 23:02:56 +000061 self.assertRaises(OSError, os.write, first, b"a")
Thomas Wouters0e3f5912006-08-11 14:57:12 +000062
Benjamin Peterson1cc6df92010-06-30 17:39:45 +000063 @support.cpython_only
Hirokazu Yamamoto4c19e6e2008-09-08 23:41:21 +000064 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 Pitrou9cadb1b2008-09-15 23:02:56 +000071 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 Pitroud62269f2008-09-15 23:54:52 +000090 self.assertEqual(fobj.read().splitlines(),
91 [b"bacon", b"eggs", b"spam"])
Antoine Pitrou9cadb1b2008-09-15 23:02:56 +000092
93
Christian Heimesdd15f6c2008-03-16 00:07:10 +000094class TemporaryFileTests(unittest.TestCase):
95 def setUp(self):
96 self.files = []
Benjamin Petersonee8712c2008-05-20 21:35:26 +000097 os.mkdir(support.TESTFN)
Christian Heimesdd15f6c2008-03-16 00:07:10 +000098
99 def tearDown(self):
100 for name in self.files:
101 os.unlink(name)
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000102 os.rmdir(support.TESTFN)
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000103
104 def check_tempfile(self, name):
105 # make sure it doesn't already exist:
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000106 self.assertFalse(os.path.exists(name),
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000107 "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 Petersonee8712c2008-05-20 21:35:26 +0000119 name = os.tempnam(support.TESTFN)
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000120 self.check_tempfile(name)
121
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000122 name = os.tempnam(support.TESTFN, "pfx")
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000123 self.assertTrue(os.path.basename(name)[:3] == "pfx")
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000124 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 Petersonc9c0f202009-06-30 23:06:06 +0000172 self.assertTrue(s == "foobar")
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000173
174 def test_tmpnam(self):
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000175 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 Petersonc9c0f202009-06-30 23:06:06 +0000196 self.assertFalse(os.path.exists(name),
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000197 "file already exists for temporary file")
198 else:
199 self.check_tempfile(name)
200
Amaury Forgeot d'Arce2e36ba2008-08-01 00:14:22 +0000201 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 Rossum98bf58f2001-10-18 20:34:25 +0000211# Test attributes on return values from os.*stat* family.
212class StatAttributeTests(unittest.TestCase):
213 def setUp(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000214 os.mkdir(support.TESTFN)
215 self.fname = os.path.join(support.TESTFN, "f1")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000216 f = open(self.fname, 'wb')
Guido van Rossum26d95c32007-08-27 23:18:54 +0000217 f.write(b"ABC")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000218 f.close()
Tim Peterse0c446b2001-10-18 21:57:37 +0000219
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000220 def tearDown(self):
221 os.unlink(self.fname)
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000222 os.rmdir(support.TESTFN)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000223
Antoine Pitrou38425292010-09-21 18:19:07 +0000224 def check_stat_attributes(self, fname):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000225 if not hasattr(os, "stat"):
226 return
227
228 import stat
Antoine Pitrou38425292010-09-21 18:19:07 +0000229 result = os.stat(fname)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000230
231 # Make sure direct access works
Ezio Melottib3aedd42010-11-20 19:04:17 +0000232 self.assertEqual(result[stat.ST_SIZE], 3)
233 self.assertEqual(result.st_size, 3)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000234
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000235 # 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öwis4d394df2005-01-23 09:19:22 +0000240 if name.endswith("TIME"):
241 def trunc(x): return int(x)
242 else:
243 def trunc(x): return x
Ezio Melottib3aedd42010-11-20 19:04:17 +0000244 self.assertEqual(trunc(getattr(result, attr)),
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000245 result[getattr(stat, name)])
Benjamin Peterson577473f2010-01-19 00:09:57 +0000246 self.assertIn(attr, members)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000247
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 Winter42dae6a2007-03-28 21:44:53 +0000258 except AttributeError:
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000259 pass
260
261 try:
262 result.st_rdev = 1
263 self.fail("No exception thrown")
Guido van Rossum1fff8782001-10-18 21:19:31 +0000264 except (AttributeError, TypeError):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000265 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 Pitrou38425292010-09-21 18:19:07 +0000286 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 Peterse0c446b2001-10-18 21:57:37 +0000295
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000296 def test_statvfs_attributes(self):
297 if not hasattr(os, "statvfs"):
298 return
299
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000300 try:
301 result = os.statvfs(self.fname)
Guido van Rossumb940e112007-01-10 16:19:56 +0000302 except OSError as e:
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000303 # On AtheOS, glibc always returns ENOSYS
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000304 if e.errno == errno.ENOSYS:
305 return
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000306
307 # Make sure direct access works
Ezio Melottib3aedd42010-11-20 19:04:17 +0000308 self.assertEqual(result.f_bfree, result[3])
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000309
Brett Cannoncfaf10c2008-05-16 00:45:35 +0000310 # 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 Melottib3aedd42010-11-20 19:04:17 +0000314 self.assertEqual(getattr(result, 'f_' + member), result[value])
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000315
316 # Make sure that assignment really fails
317 try:
318 result.f_bfree = 1
319 self.fail("No exception thrown")
Collin Winter42dae6a2007-03-28 21:44:53 +0000320 except AttributeError:
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000321 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 Drake38c2ef02001-07-17 20:52:51 +0000341
Thomas Wouters89f507f2006-12-13 04:49:30 +0000342 def test_utime_dir(self):
343 delta = 1000000
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000344 st = os.stat(support.TESTFN)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000345 # round to int, because some systems may support sub-second
346 # time stamps in stat, but not in utime.
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000347 os.utime(support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
348 st2 = os.stat(support.TESTFN)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000349 self.assertEqual(st2.st_mtime, int(st.st_mtime-delta))
Thomas Wouters89f507f2006-12-13 04:49:30 +0000350
351 # Restrict test to Win32, since there is no guarantee other
352 # systems support centiseconds
353 if sys.platform == 'win32':
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000354 def get_file_system(path):
Hirokazu Yamamoto5ef6d182008-08-20 04:17:24 +0000355 root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000356 import ctypes
Hirokazu Yamamotoca765d52008-08-20 16:18:19 +0000357 kernel32 = ctypes.windll.kernel32
Hirokazu Yamamoto5ef6d182008-08-20 04:17:24 +0000358 buf = ctypes.create_unicode_buffer("", 100)
Hirokazu Yamamotoca765d52008-08-20 16:18:19 +0000359 if kernel32.GetVolumeInformationW(root, None, 0, None, None, None, buf, len(buf)):
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000360 return buf.value
361
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000362 if get_file_system(support.TESTFN) == "NTFS":
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000363 def test_1565150(self):
364 t1 = 1159195039.25
365 os.utime(self.fname, (t1, t1))
Ezio Melottib3aedd42010-11-20 19:04:17 +0000366 self.assertEqual(os.stat(self.fname).st_mtime, t1)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000367
Amaury Forgeot d'Arca251a852011-01-03 00:19:11 +0000368 def test_large_time(self):
369 t1 = 5000000000 # some day in 2128
370 os.utime(self.fname, (t1, t1))
371 self.assertEqual(os.stat(self.fname).st_mtime, t1)
372
Guido van Rossumd8faa362007-04-27 19:54:29 +0000373 def test_1686475(self):
374 # Verify that an open file can be stat'ed
375 try:
376 os.stat(r"c:\pagefile.sys")
377 except WindowsError as e:
Benjamin Petersonc4fe6f32008-08-19 18:57:56 +0000378 if e.errno == 2: # file does not exist; cannot run test
Guido van Rossumd8faa362007-04-27 19:54:29 +0000379 return
380 self.fail("Could not stat pagefile.sys")
381
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000382from test import mapping_tests
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000383
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000384class EnvironTests(mapping_tests.BasicTestMappingProtocol):
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000385 """check that os.environ object conform to mapping protocol"""
Walter Dörwald118f9312004-06-02 18:42:25 +0000386 type2test = None
Christian Heimes90333392007-11-01 19:08:42 +0000387
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000388 def setUp(self):
389 self.__save = dict(os.environ)
Victor Stinnerb745a742010-05-18 17:17:23 +0000390 if os.supports_bytes_environ:
Victor Stinner208d28c2010-05-07 00:54:14 +0000391 self.__saveb = dict(os.environb)
Christian Heimes90333392007-11-01 19:08:42 +0000392 for key, value in self._reference().items():
393 os.environ[key] = value
394
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000395 def tearDown(self):
396 os.environ.clear()
397 os.environ.update(self.__save)
Victor Stinnerb745a742010-05-18 17:17:23 +0000398 if os.supports_bytes_environ:
Victor Stinner208d28c2010-05-07 00:54:14 +0000399 os.environb.clear()
400 os.environb.update(self.__saveb)
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000401
Christian Heimes90333392007-11-01 19:08:42 +0000402 def _reference(self):
403 return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
404
405 def _empty_mapping(self):
406 os.environ.clear()
407 return os.environ
408
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000409 # Bug 1110478
Martin v. Löwis5510f652005-02-17 21:23:20 +0000410 def test_update2(self):
Christian Heimes90333392007-11-01 19:08:42 +0000411 os.environ.clear()
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000412 if os.path.exists("/bin/sh"):
413 os.environ.update(HELLO="World")
Brian Curtin810921b2010-10-30 21:24:21 +0000414 with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
415 value = popen.read().strip()
Ezio Melottib3aedd42010-11-20 19:04:17 +0000416 self.assertEqual(value, "World")
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000417
Christian Heimes1a13d592007-11-08 14:16:55 +0000418 def test_os_popen_iter(self):
419 if os.path.exists("/bin/sh"):
Brian Curtin810921b2010-10-30 21:24:21 +0000420 with os.popen(
421 "/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen:
422 it = iter(popen)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000423 self.assertEqual(next(it), "line1\n")
424 self.assertEqual(next(it), "line2\n")
425 self.assertEqual(next(it), "line3\n")
Brian Curtin810921b2010-10-30 21:24:21 +0000426 self.assertRaises(StopIteration, next, it)
Christian Heimes1a13d592007-11-08 14:16:55 +0000427
Guido van Rossum67aca9e2007-06-13 21:51:27 +0000428 # Verify environ keys and values from the OS are of the
429 # correct str type.
430 def test_keyvalue_types(self):
431 for key, val in os.environ.items():
Ezio Melottib3aedd42010-11-20 19:04:17 +0000432 self.assertEqual(type(key), str)
433 self.assertEqual(type(val), str)
Guido van Rossum67aca9e2007-06-13 21:51:27 +0000434
Christian Heimes90333392007-11-01 19:08:42 +0000435 def test_items(self):
436 for key, value in self._reference().items():
437 self.assertEqual(os.environ.get(key), value)
438
Ezio Melotti19e4acf2010-02-22 15:59:01 +0000439 # Issue 7310
440 def test___repr__(self):
441 """Check that the repr() of os.environ looks like environ({...})."""
442 env = os.environ
Victor Stinner96f0de92010-07-29 00:29:00 +0000443 self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join(
444 '{!r}: {!r}'.format(key, value)
445 for key, value in env.items())))
Ezio Melotti19e4acf2010-02-22 15:59:01 +0000446
Gregory P. Smithb6e8c7e2010-02-27 07:22:22 +0000447 def test_get_exec_path(self):
448 defpath_list = os.defpath.split(os.pathsep)
449 test_path = ['/monty', '/python', '', '/flying/circus']
450 test_env = {'PATH': os.pathsep.join(test_path)}
451
452 saved_environ = os.environ
453 try:
454 os.environ = dict(test_env)
455 # Test that defaulting to os.environ works.
456 self.assertSequenceEqual(test_path, os.get_exec_path())
457 self.assertSequenceEqual(test_path, os.get_exec_path(env=None))
458 finally:
459 os.environ = saved_environ
460
461 # No PATH environment variable
462 self.assertSequenceEqual(defpath_list, os.get_exec_path({}))
463 # Empty PATH environment variable
464 self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''}))
465 # Supplied PATH environment variable
466 self.assertSequenceEqual(test_path, os.get_exec_path(test_env))
467
Victor Stinnerb745a742010-05-18 17:17:23 +0000468 if os.supports_bytes_environ:
469 # env cannot contain 'PATH' and b'PATH' keys
Victor Stinner38430e22010-08-19 17:10:18 +0000470 try:
Victor Stinner6f35eda2010-10-29 00:38:58 +0000471 # ignore BytesWarning warning
472 with warnings.catch_warnings(record=True):
473 mixed_env = {'PATH': '1', b'PATH': b'2'}
Victor Stinner38430e22010-08-19 17:10:18 +0000474 except BytesWarning:
Victor Stinner6f35eda2010-10-29 00:38:58 +0000475 # mixed_env cannot be created with python -bb
Victor Stinner38430e22010-08-19 17:10:18 +0000476 pass
477 else:
478 self.assertRaises(ValueError, os.get_exec_path, mixed_env)
Victor Stinnerb745a742010-05-18 17:17:23 +0000479
480 # bytes key and/or value
481 self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}),
482 ['abc'])
483 self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}),
484 ['abc'])
485 self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}),
486 ['abc'])
487
488 @unittest.skipUnless(os.supports_bytes_environ,
489 "os.environb required for this test.")
Victor Stinner84ae1182010-05-06 22:05:07 +0000490 def test_environb(self):
491 # os.environ -> os.environb
492 value = 'euro\u20ac'
493 try:
Benjamin Peterson180799d2010-05-06 22:25:42 +0000494 value_bytes = value.encode(sys.getfilesystemencoding(),
495 'surrogateescape')
Victor Stinner84ae1182010-05-06 22:05:07 +0000496 except UnicodeEncodeError:
Benjamin Peterson180799d2010-05-06 22:25:42 +0000497 msg = "U+20AC character is not encodable to %s" % (
498 sys.getfilesystemencoding(),)
Benjamin Peterson932d3f42010-05-06 22:26:31 +0000499 self.skipTest(msg)
Victor Stinner84ae1182010-05-06 22:05:07 +0000500 os.environ['unicode'] = value
Ezio Melottib3aedd42010-11-20 19:04:17 +0000501 self.assertEqual(os.environ['unicode'], value)
502 self.assertEqual(os.environb[b'unicode'], value_bytes)
Victor Stinner84ae1182010-05-06 22:05:07 +0000503
504 # os.environb -> os.environ
505 value = b'\xff'
506 os.environb[b'bytes'] = value
Ezio Melottib3aedd42010-11-20 19:04:17 +0000507 self.assertEqual(os.environb[b'bytes'], value)
Victor Stinner84ae1182010-05-06 22:05:07 +0000508 value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000509 self.assertEqual(os.environ['bytes'], value_str)
Ezio Melotti19e4acf2010-02-22 15:59:01 +0000510
Tim Petersc4e09402003-04-25 07:11:48 +0000511class WalkTests(unittest.TestCase):
512 """Tests for os.walk()."""
513
514 def test_traversal(self):
515 import os
516 from os.path import join
517
518 # Build:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000519 # TESTFN/
520 # TEST1/ a file kid and two directory kids
Tim Petersc4e09402003-04-25 07:11:48 +0000521 # tmp1
522 # SUB1/ a file kid and a directory kid
Guido van Rossumd8faa362007-04-27 19:54:29 +0000523 # tmp2
524 # SUB11/ no kids
525 # SUB2/ a file kid and a dirsymlink kid
526 # tmp3
527 # link/ a symlink to TESTFN.2
528 # TEST2/
529 # tmp4 a lone file
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000530 walk_path = join(support.TESTFN, "TEST1")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000531 sub1_path = join(walk_path, "SUB1")
Tim Petersc4e09402003-04-25 07:11:48 +0000532 sub11_path = join(sub1_path, "SUB11")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000533 sub2_path = join(walk_path, "SUB2")
534 tmp1_path = join(walk_path, "tmp1")
Tim Petersc4e09402003-04-25 07:11:48 +0000535 tmp2_path = join(sub1_path, "tmp2")
536 tmp3_path = join(sub2_path, "tmp3")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000537 link_path = join(sub2_path, "link")
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000538 t2_path = join(support.TESTFN, "TEST2")
539 tmp4_path = join(support.TESTFN, "TEST2", "tmp4")
Tim Petersc4e09402003-04-25 07:11:48 +0000540
541 # Create stuff.
542 os.makedirs(sub11_path)
543 os.makedirs(sub2_path)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000544 os.makedirs(t2_path)
545 for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
Alex Martelli01c77c62006-08-24 02:58:11 +0000546 f = open(path, "w")
Tim Petersc4e09402003-04-25 07:11:48 +0000547 f.write("I'm " + path + " and proud of it. Blame test_os.\n")
548 f.close()
Brian Curtin3b4499c2010-12-28 14:31:47 +0000549 if support.can_symlink():
Guido van Rossumd8faa362007-04-27 19:54:29 +0000550 os.symlink(os.path.abspath(t2_path), link_path)
551 sub2_tree = (sub2_path, ["link"], ["tmp3"])
552 else:
553 sub2_tree = (sub2_path, [], ["tmp3"])
Tim Petersc4e09402003-04-25 07:11:48 +0000554
555 # Walk top-down.
Guido van Rossumd8faa362007-04-27 19:54:29 +0000556 all = list(os.walk(walk_path))
Tim Petersc4e09402003-04-25 07:11:48 +0000557 self.assertEqual(len(all), 4)
558 # We can't know which order SUB1 and SUB2 will appear in.
559 # Not flipped: TESTFN, SUB1, SUB11, SUB2
560 # flipped: TESTFN, SUB2, SUB1, SUB11
561 flipped = all[0][1][0] != "SUB1"
562 all[0][1].sort()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000563 self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000564 self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
565 self.assertEqual(all[2 + flipped], (sub11_path, [], []))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000566 self.assertEqual(all[3 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000567
568 # Prune the search.
569 all = []
Guido van Rossumd8faa362007-04-27 19:54:29 +0000570 for root, dirs, files in os.walk(walk_path):
Tim Petersc4e09402003-04-25 07:11:48 +0000571 all.append((root, dirs, files))
572 # Don't descend into SUB1.
573 if 'SUB1' in dirs:
574 # Note that this also mutates the dirs we appended to all!
575 dirs.remove('SUB1')
576 self.assertEqual(len(all), 2)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000577 self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"]))
578 self.assertEqual(all[1], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000579
580 # Walk bottom-up.
Guido van Rossumd8faa362007-04-27 19:54:29 +0000581 all = list(os.walk(walk_path, topdown=False))
Tim Petersc4e09402003-04-25 07:11:48 +0000582 self.assertEqual(len(all), 4)
583 # We can't know which order SUB1 and SUB2 will appear in.
584 # Not flipped: SUB11, SUB1, SUB2, TESTFN
585 # flipped: SUB2, SUB11, SUB1, TESTFN
586 flipped = all[3][1][0] != "SUB1"
587 all[3][1].sort()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000588 self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000589 self.assertEqual(all[flipped], (sub11_path, [], []))
590 self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000591 self.assertEqual(all[2 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000592
Brian Curtin3b4499c2010-12-28 14:31:47 +0000593 if support.can_symlink():
Guido van Rossumd8faa362007-04-27 19:54:29 +0000594 # Walk, following symlinks.
595 for root, dirs, files in os.walk(walk_path, followlinks=True):
596 if root == link_path:
597 self.assertEqual(dirs, [])
598 self.assertEqual(files, ["tmp4"])
599 break
600 else:
601 self.fail("Didn't follow symlink with followlinks=True")
602
603 def tearDown(self):
Tim Petersc4e09402003-04-25 07:11:48 +0000604 # Tear everything down. This is a decent use for bottom-up on
605 # Windows, which doesn't have a recursive delete command. The
606 # (not so) subtlety is that rmdir will fail unless the dir's
607 # kids are removed first, so bottom up is essential.
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000608 for root, dirs, files in os.walk(support.TESTFN, topdown=False):
Tim Petersc4e09402003-04-25 07:11:48 +0000609 for name in files:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000610 os.remove(os.path.join(root, name))
Tim Petersc4e09402003-04-25 07:11:48 +0000611 for name in dirs:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000612 dirname = os.path.join(root, name)
613 if not os.path.islink(dirname):
614 os.rmdir(dirname)
615 else:
616 os.remove(dirname)
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000617 os.rmdir(support.TESTFN)
Tim Petersc4e09402003-04-25 07:11:48 +0000618
Guido van Rossume7ba4952007-06-06 23:52:48 +0000619class MakedirTests(unittest.TestCase):
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000620 def setUp(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000621 os.mkdir(support.TESTFN)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000622
623 def test_makedir(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000624 base = support.TESTFN
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000625 path = os.path.join(base, 'dir1', 'dir2', 'dir3')
626 os.makedirs(path) # Should work
627 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
628 os.makedirs(path)
629
630 # Try paths with a '.' in them
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000631 self.assertRaises(OSError, os.makedirs, os.curdir)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000632 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
633 os.makedirs(path)
634 path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
635 'dir5', 'dir6')
636 os.makedirs(path)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000637
Terry Reedy5a22b652010-12-02 07:05:56 +0000638 def test_exist_ok_existing_directory(self):
639 path = os.path.join(support.TESTFN, 'dir1')
640 mode = 0o777
641 old_mask = os.umask(0o022)
642 os.makedirs(path, mode)
643 self.assertRaises(OSError, os.makedirs, path, mode)
644 self.assertRaises(OSError, os.makedirs, path, mode, exist_ok=False)
645 self.assertRaises(OSError, os.makedirs, path, 0o776, exist_ok=True)
646 os.makedirs(path, mode=mode, exist_ok=True)
647 os.umask(old_mask)
648
649 def test_exist_ok_existing_regular_file(self):
650 base = support.TESTFN
651 path = os.path.join(support.TESTFN, 'dir1')
652 f = open(path, 'w')
653 f.write('abc')
654 f.close()
655 self.assertRaises(OSError, os.makedirs, path)
656 self.assertRaises(OSError, os.makedirs, path, exist_ok=False)
657 self.assertRaises(OSError, os.makedirs, path, exist_ok=True)
658 os.remove(path)
659
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000660 def tearDown(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000661 path = os.path.join(support.TESTFN, 'dir1', 'dir2', 'dir3',
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000662 'dir4', 'dir5', 'dir6')
663 # If the tests failed, the bottom-most directory ('../dir6')
664 # may not have been created, so we look for the outermost directory
665 # that exists.
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000666 while not os.path.exists(path) and path != support.TESTFN:
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000667 path = os.path.dirname(path)
668
669 os.removedirs(path)
670
Guido van Rossume7ba4952007-06-06 23:52:48 +0000671class DevNullTests(unittest.TestCase):
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000672 def test_devnull(self):
Alex Martelli01c77c62006-08-24 02:58:11 +0000673 f = open(os.devnull, 'w')
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000674 f.write('hello')
675 f.close()
Alex Martelli01c77c62006-08-24 02:58:11 +0000676 f = open(os.devnull, 'r')
Tim Peters4182cfd2004-06-08 20:34:34 +0000677 self.assertEqual(f.read(), '')
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000678 f.close()
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000679
Guido van Rossume7ba4952007-06-06 23:52:48 +0000680class URandomTests(unittest.TestCase):
Martin v. Löwisdc3883f2004-08-29 15:46:35 +0000681 def test_urandom(self):
682 try:
683 self.assertEqual(len(os.urandom(1)), 1)
684 self.assertEqual(len(os.urandom(10)), 10)
685 self.assertEqual(len(os.urandom(100)), 100)
686 self.assertEqual(len(os.urandom(1000)), 1000)
687 except NotImplementedError:
688 pass
689
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000690@contextlib.contextmanager
691def _execvpe_mockup(defpath=None):
692 """
693 Stubs out execv and execve functions when used as context manager.
694 Records exec calls. The mock execv and execve functions always raise an
695 exception as they would normally never return.
696 """
697 # A list of tuples containing (function name, first arg, args)
698 # of calls to execv or execve that have been made.
699 calls = []
700
701 def mock_execv(name, *args):
702 calls.append(('execv', name, args))
703 raise RuntimeError("execv called")
704
705 def mock_execve(name, *args):
706 calls.append(('execve', name, args))
707 raise OSError(errno.ENOTDIR, "execve called")
708
709 try:
710 orig_execv = os.execv
711 orig_execve = os.execve
712 orig_defpath = os.defpath
713 os.execv = mock_execv
714 os.execve = mock_execve
715 if defpath is not None:
716 os.defpath = defpath
717 yield calls
718 finally:
719 os.execv = orig_execv
720 os.execve = orig_execve
721 os.defpath = orig_defpath
722
Guido van Rossume7ba4952007-06-06 23:52:48 +0000723class ExecTests(unittest.TestCase):
Mark Dickinson7cf03892010-04-16 13:45:35 +0000724 @unittest.skipIf(USING_LINUXTHREADS,
725 "avoid triggering a linuxthreads bug: see issue #4970")
Guido van Rossume7ba4952007-06-06 23:52:48 +0000726 def test_execvpe_with_bad_program(self):
Mark Dickinson7cf03892010-04-16 13:45:35 +0000727 self.assertRaises(OSError, os.execvpe, 'no such app-',
728 ['no such app-'], None)
Guido van Rossume7ba4952007-06-06 23:52:48 +0000729
Thomas Heller6790d602007-08-30 17:15:14 +0000730 def test_execvpe_with_bad_arglist(self):
731 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
732
Gregory P. Smith4ae37772010-05-08 18:05:46 +0000733 @unittest.skipUnless(hasattr(os, '_execvpe'),
734 "No internal os._execvpe function to test.")
Victor Stinnerb745a742010-05-18 17:17:23 +0000735 def _test_internal_execvpe(self, test_type):
736 program_path = os.sep + 'absolutepath'
737 if test_type is bytes:
738 program = b'executable'
739 fullpath = os.path.join(os.fsencode(program_path), program)
740 native_fullpath = fullpath
741 arguments = [b'progname', 'arg1', 'arg2']
742 else:
743 program = 'executable'
744 arguments = ['progname', 'arg1', 'arg2']
745 fullpath = os.path.join(program_path, program)
746 if os.name != "nt":
747 native_fullpath = os.fsencode(fullpath)
748 else:
749 native_fullpath = fullpath
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000750 env = {'spam': 'beans'}
751
Victor Stinnerb745a742010-05-18 17:17:23 +0000752 # test os._execvpe() with an absolute path
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000753 with _execvpe_mockup() as calls:
Victor Stinnerb745a742010-05-18 17:17:23 +0000754 self.assertRaises(RuntimeError,
755 os._execvpe, fullpath, arguments)
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000756 self.assertEqual(len(calls), 1)
757 self.assertEqual(calls[0], ('execv', fullpath, (arguments,)))
758
Victor Stinnerb745a742010-05-18 17:17:23 +0000759 # test os._execvpe() with a relative path:
760 # os.get_exec_path() returns defpath
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000761 with _execvpe_mockup(defpath=program_path) as calls:
Victor Stinnerb745a742010-05-18 17:17:23 +0000762 self.assertRaises(OSError,
763 os._execvpe, program, arguments, env=env)
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000764 self.assertEqual(len(calls), 1)
Victor Stinnerb745a742010-05-18 17:17:23 +0000765 self.assertSequenceEqual(calls[0],
766 ('execve', native_fullpath, (arguments, env)))
767
768 # test os._execvpe() with a relative path:
769 # os.get_exec_path() reads the 'PATH' variable
770 with _execvpe_mockup() as calls:
771 env_path = env.copy()
Victor Stinner38430e22010-08-19 17:10:18 +0000772 if test_type is bytes:
773 env_path[b'PATH'] = program_path
774 else:
775 env_path['PATH'] = program_path
Victor Stinnerb745a742010-05-18 17:17:23 +0000776 self.assertRaises(OSError,
777 os._execvpe, program, arguments, env=env_path)
778 self.assertEqual(len(calls), 1)
779 self.assertSequenceEqual(calls[0],
780 ('execve', native_fullpath, (arguments, env_path)))
781
782 def test_internal_execvpe_str(self):
783 self._test_internal_execvpe(str)
784 if os.name != "nt":
785 self._test_internal_execvpe(bytes)
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000786
Gregory P. Smith4ae37772010-05-08 18:05:46 +0000787
Thomas Wouters477c8d52006-05-27 19:21:47 +0000788class Win32ErrorTests(unittest.TestCase):
789 def test_rename(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000790 self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak")
Thomas Wouters477c8d52006-05-27 19:21:47 +0000791
792 def test_remove(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000793 self.assertRaises(WindowsError, os.remove, support.TESTFN)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000794
795 def test_chdir(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000796 self.assertRaises(WindowsError, os.chdir, support.TESTFN)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000797
798 def test_mkdir(self):
Amaury Forgeot d'Arc2fc224f2009-02-19 23:23:47 +0000799 f = open(support.TESTFN, "w")
Benjamin Petersonf91df042009-02-13 02:50:59 +0000800 try:
801 self.assertRaises(WindowsError, os.mkdir, support.TESTFN)
802 finally:
803 f.close()
Amaury Forgeot d'Arc2fc224f2009-02-19 23:23:47 +0000804 os.unlink(support.TESTFN)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000805
806 def test_utime(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000807 self.assertRaises(WindowsError, os.utime, support.TESTFN, None)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000808
Thomas Wouters477c8d52006-05-27 19:21:47 +0000809 def test_chmod(self):
Benjamin Petersonf91df042009-02-13 02:50:59 +0000810 self.assertRaises(WindowsError, os.chmod, support.TESTFN, 0)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000811
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000812class TestInvalidFD(unittest.TestCase):
Benjamin Peterson05e782f2009-01-19 15:15:02 +0000813 singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000814 "fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
815 #singles.append("close")
816 #We omit close because it doesn'r raise an exception on some platforms
817 def get_single(f):
818 def helper(self):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000819 if hasattr(os, f):
820 self.check(getattr(os, f))
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000821 return helper
822 for f in singles:
823 locals()["test_"+f] = get_single(f)
824
Benjamin Peterson7522c742009-01-19 21:00:09 +0000825 def check(self, f, *args):
Benjamin Peterson5c6d7872009-02-06 02:40:07 +0000826 try:
827 f(support.make_bad_fd(), *args)
828 except OSError as e:
829 self.assertEqual(e.errno, errno.EBADF)
830 else:
831 self.fail("%r didn't raise a OSError with a bad file descriptor"
832 % f)
Benjamin Peterson7522c742009-01-19 21:00:09 +0000833
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000834 def test_isatty(self):
835 if hasattr(os, "isatty"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000836 self.assertEqual(os.isatty(support.make_bad_fd()), False)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000837
838 def test_closerange(self):
839 if hasattr(os, "closerange"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000840 fd = support.make_bad_fd()
R. David Murray630cc482009-07-22 15:20:27 +0000841 # Make sure none of the descriptors we are about to close are
842 # currently valid (issue 6542).
843 for i in range(10):
844 try: os.fstat(fd+i)
845 except OSError:
846 pass
847 else:
848 break
849 if i < 2:
850 raise unittest.SkipTest(
851 "Unable to acquire a range of invalid file descriptors")
852 self.assertEqual(os.closerange(fd, fd + i-1), None)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000853
854 def test_dup2(self):
855 if hasattr(os, "dup2"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000856 self.check(os.dup2, 20)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000857
858 def test_fchmod(self):
859 if hasattr(os, "fchmod"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000860 self.check(os.fchmod, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000861
862 def test_fchown(self):
863 if hasattr(os, "fchown"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000864 self.check(os.fchown, -1, -1)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000865
866 def test_fpathconf(self):
867 if hasattr(os, "fpathconf"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000868 self.check(os.fpathconf, "PC_NAME_MAX")
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000869
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000870 def test_ftruncate(self):
871 if hasattr(os, "ftruncate"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000872 self.check(os.ftruncate, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000873
874 def test_lseek(self):
875 if hasattr(os, "lseek"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000876 self.check(os.lseek, 0, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000877
878 def test_read(self):
879 if hasattr(os, "read"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000880 self.check(os.read, 1)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000881
882 def test_tcsetpgrpt(self):
883 if hasattr(os, "tcsetpgrp"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000884 self.check(os.tcsetpgrp, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000885
886 def test_write(self):
887 if hasattr(os, "write"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000888 self.check(os.write, b" ")
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000889
Brian Curtin1b9df392010-11-24 20:24:31 +0000890
891class LinkTests(unittest.TestCase):
892 def setUp(self):
893 self.file1 = support.TESTFN
894 self.file2 = os.path.join(support.TESTFN + "2")
895
Brian Curtinc0abc4e2010-11-30 23:46:54 +0000896 def tearDown(self):
Brian Curtin1b9df392010-11-24 20:24:31 +0000897 for file in (self.file1, self.file2):
898 if os.path.exists(file):
899 os.unlink(file)
900
Brian Curtin1b9df392010-11-24 20:24:31 +0000901 def _test_link(self, file1, file2):
902 with open(file1, "w") as f1:
903 f1.write("test")
904
905 os.link(file1, file2)
906 with open(file1, "r") as f1, open(file2, "r") as f2:
907 self.assertTrue(os.path.sameopenfile(f1.fileno(), f2.fileno()))
908
909 def test_link(self):
910 self._test_link(self.file1, self.file2)
911
912 def test_link_bytes(self):
913 self._test_link(bytes(self.file1, sys.getfilesystemencoding()),
914 bytes(self.file2, sys.getfilesystemencoding()))
915
Brian Curtinf498b752010-11-30 15:54:04 +0000916 def test_unicode_name(self):
Brian Curtin43f0c272010-11-30 15:40:04 +0000917 try:
Brian Curtinf498b752010-11-30 15:54:04 +0000918 os.fsencode("\xf1")
Brian Curtin43f0c272010-11-30 15:40:04 +0000919 except UnicodeError:
920 raise unittest.SkipTest("Unable to encode for this platform.")
921
Brian Curtinf498b752010-11-30 15:54:04 +0000922 self.file1 += "\xf1"
Brian Curtinfc889c42010-11-28 23:59:46 +0000923 self.file2 = self.file1 + "2"
924 self._test_link(self.file1, self.file2)
925
Thomas Wouters477c8d52006-05-27 19:21:47 +0000926if sys.platform != 'win32':
927 class Win32ErrorTests(unittest.TestCase):
928 pass
929
Benjamin Petersonef3e4c22009-04-11 19:48:14 +0000930 class PosixUidGidTests(unittest.TestCase):
931 if hasattr(os, 'setuid'):
932 def test_setuid(self):
933 if os.getuid() != 0:
934 self.assertRaises(os.error, os.setuid, 0)
935 self.assertRaises(OverflowError, os.setuid, 1<<32)
936
937 if hasattr(os, 'setgid'):
938 def test_setgid(self):
939 if os.getuid() != 0:
940 self.assertRaises(os.error, os.setgid, 0)
941 self.assertRaises(OverflowError, os.setgid, 1<<32)
942
943 if hasattr(os, 'seteuid'):
944 def test_seteuid(self):
945 if os.getuid() != 0:
946 self.assertRaises(os.error, os.seteuid, 0)
947 self.assertRaises(OverflowError, os.seteuid, 1<<32)
948
949 if hasattr(os, 'setegid'):
950 def test_setegid(self):
951 if os.getuid() != 0:
952 self.assertRaises(os.error, os.setegid, 0)
953 self.assertRaises(OverflowError, os.setegid, 1<<32)
954
955 if hasattr(os, 'setreuid'):
956 def test_setreuid(self):
957 if os.getuid() != 0:
958 self.assertRaises(os.error, os.setreuid, 0, 0)
959 self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
960 self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000961
962 def test_setreuid_neg1(self):
963 # Needs to accept -1. We run this in a subprocess to avoid
964 # altering the test runner's process state (issue8045).
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000965 subprocess.check_call([
966 sys.executable, '-c',
967 'import os,sys;os.setreuid(-1,-1);sys.exit(0)'])
Benjamin Petersonef3e4c22009-04-11 19:48:14 +0000968
969 if hasattr(os, 'setregid'):
970 def test_setregid(self):
971 if os.getuid() != 0:
972 self.assertRaises(os.error, os.setregid, 0, 0)
973 self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
974 self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000975
976 def test_setregid_neg1(self):
977 # Needs to accept -1. We run this in a subprocess to avoid
978 # altering the test runner's process state (issue8045).
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000979 subprocess.check_call([
980 sys.executable, '-c',
981 'import os,sys;os.setregid(-1,-1);sys.exit(0)'])
Martin v. Löwis011e8422009-05-05 04:43:17 +0000982
983 class Pep383Tests(unittest.TestCase):
Martin v. Löwis011e8422009-05-05 04:43:17 +0000984 def setUp(self):
Victor Stinnerd91df1a2010-08-18 10:56:19 +0000985 if support.TESTFN_UNENCODABLE:
986 self.dir = support.TESTFN_UNENCODABLE
987 else:
988 self.dir = support.TESTFN
989 self.bdir = os.fsencode(self.dir)
990
991 bytesfn = []
992 def add_filename(fn):
993 try:
994 fn = os.fsencode(fn)
995 except UnicodeEncodeError:
996 return
997 bytesfn.append(fn)
998 add_filename(support.TESTFN_UNICODE)
999 if support.TESTFN_UNENCODABLE:
1000 add_filename(support.TESTFN_UNENCODABLE)
1001 if not bytesfn:
1002 self.skipTest("couldn't create any non-ascii filename")
1003
1004 self.unicodefn = set()
Martin v. Löwis011e8422009-05-05 04:43:17 +00001005 os.mkdir(self.dir)
Victor Stinnerd91df1a2010-08-18 10:56:19 +00001006 try:
1007 for fn in bytesfn:
1008 f = open(os.path.join(self.bdir, fn), "w")
1009 f.close()
Victor Stinnere8d51452010-08-19 01:05:19 +00001010 fn = os.fsdecode(fn)
Victor Stinnerd91df1a2010-08-18 10:56:19 +00001011 if fn in self.unicodefn:
1012 raise ValueError("duplicate filename")
1013 self.unicodefn.add(fn)
1014 except:
1015 shutil.rmtree(self.dir)
1016 raise
Martin v. Löwis011e8422009-05-05 04:43:17 +00001017
1018 def tearDown(self):
1019 shutil.rmtree(self.dir)
Martin v. Löwis011e8422009-05-05 04:43:17 +00001020
1021 def test_listdir(self):
Victor Stinnerd91df1a2010-08-18 10:56:19 +00001022 expected = self.unicodefn
1023 found = set(os.listdir(self.dir))
Ezio Melottib3aedd42010-11-20 19:04:17 +00001024 self.assertEqual(found, expected)
Martin v. Löwis011e8422009-05-05 04:43:17 +00001025
1026 def test_open(self):
1027 for fn in self.unicodefn:
1028 f = open(os.path.join(self.dir, fn))
1029 f.close()
1030
1031 def test_stat(self):
1032 for fn in self.unicodefn:
1033 os.stat(os.path.join(self.dir, fn))
Benjamin Petersonef3e4c22009-04-11 19:48:14 +00001034else:
1035 class PosixUidGidTests(unittest.TestCase):
1036 pass
Martin v. Löwis011e8422009-05-05 04:43:17 +00001037 class Pep383Tests(unittest.TestCase):
1038 pass
Benjamin Petersonef3e4c22009-04-11 19:48:14 +00001039
Brian Curtineb24d742010-04-12 17:16:38 +00001040@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
1041class Win32KillTests(unittest.TestCase):
Brian Curtinc3acbc32010-05-28 16:08:40 +00001042 def _kill(self, sig):
1043 # Start sys.executable as a subprocess and communicate from the
1044 # subprocess to the parent that the interpreter is ready. When it
1045 # becomes ready, send *sig* via os.kill to the subprocess and check
1046 # that the return code is equal to *sig*.
1047 import ctypes
1048 from ctypes import wintypes
1049 import msvcrt
1050
1051 # Since we can't access the contents of the process' stdout until the
1052 # process has exited, use PeekNamedPipe to see what's inside stdout
1053 # without waiting. This is done so we can tell that the interpreter
1054 # is started and running at a point where it could handle a signal.
1055 PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
1056 PeekNamedPipe.restype = wintypes.BOOL
1057 PeekNamedPipe.argtypes = (wintypes.HANDLE, # Pipe handle
1058 ctypes.POINTER(ctypes.c_char), # stdout buf
1059 wintypes.DWORD, # Buffer size
1060 ctypes.POINTER(wintypes.DWORD), # bytes read
1061 ctypes.POINTER(wintypes.DWORD), # bytes avail
1062 ctypes.POINTER(wintypes.DWORD)) # bytes left
1063 msg = "running"
1064 proc = subprocess.Popen([sys.executable, "-c",
1065 "import sys;"
1066 "sys.stdout.write('{}');"
1067 "sys.stdout.flush();"
1068 "input()".format(msg)],
1069 stdout=subprocess.PIPE,
1070 stderr=subprocess.PIPE,
1071 stdin=subprocess.PIPE)
Brian Curtin43ec5772010-11-05 15:17:11 +00001072 self.addCleanup(proc.stdout.close)
1073 self.addCleanup(proc.stderr.close)
1074 self.addCleanup(proc.stdin.close)
Brian Curtinc3acbc32010-05-28 16:08:40 +00001075
1076 count, max = 0, 100
1077 while count < max and proc.poll() is None:
1078 # Create a string buffer to store the result of stdout from the pipe
1079 buf = ctypes.create_string_buffer(len(msg))
1080 # Obtain the text currently in proc.stdout
1081 # Bytes read/avail/left are left as NULL and unused
1082 rslt = PeekNamedPipe(msvcrt.get_osfhandle(proc.stdout.fileno()),
1083 buf, ctypes.sizeof(buf), None, None, None)
1084 self.assertNotEqual(rslt, 0, "PeekNamedPipe failed")
1085 if buf.value:
1086 self.assertEqual(msg, buf.value.decode())
1087 break
1088 time.sleep(0.1)
1089 count += 1
1090 else:
1091 self.fail("Did not receive communication from the subprocess")
1092
Brian Curtineb24d742010-04-12 17:16:38 +00001093 os.kill(proc.pid, sig)
1094 self.assertEqual(proc.wait(), sig)
1095
1096 def test_kill_sigterm(self):
1097 # SIGTERM doesn't mean anything special, but make sure it works
Brian Curtinc3acbc32010-05-28 16:08:40 +00001098 self._kill(signal.SIGTERM)
Brian Curtineb24d742010-04-12 17:16:38 +00001099
1100 def test_kill_int(self):
1101 # os.kill on Windows can take an int which gets set as the exit code
Brian Curtinc3acbc32010-05-28 16:08:40 +00001102 self._kill(100)
Brian Curtineb24d742010-04-12 17:16:38 +00001103
1104 def _kill_with_event(self, event, name):
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001105 tagname = "test_os_%s" % uuid.uuid1()
1106 m = mmap.mmap(-1, 1, tagname)
1107 m[0] = 0
Brian Curtineb24d742010-04-12 17:16:38 +00001108 # Run a script which has console control handling enabled.
1109 proc = subprocess.Popen([sys.executable,
1110 os.path.join(os.path.dirname(__file__),
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001111 "win_console_handler.py"), tagname],
Brian Curtineb24d742010-04-12 17:16:38 +00001112 creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
1113 # Let the interpreter startup before we send signals. See #3137.
Hirokazu Yamamoto8e9fe9f2010-12-05 02:41:46 +00001114 count, max = 0, 100
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001115 while count < max and proc.poll() is None:
Brian Curtinf668df52010-10-15 14:21:06 +00001116 if m[0] == 1:
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001117 break
Hirokazu Yamamoto8e9fe9f2010-12-05 02:41:46 +00001118 time.sleep(0.1)
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001119 count += 1
1120 else:
Hirokazu Yamamoto8e9fe9f2010-12-05 02:41:46 +00001121 # Forcefully kill the process if we weren't able to signal it.
1122 os.kill(proc.pid, signal.SIGINT)
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001123 self.fail("Subprocess didn't finish initialization")
Brian Curtineb24d742010-04-12 17:16:38 +00001124 os.kill(proc.pid, event)
1125 # proc.send_signal(event) could also be done here.
1126 # Allow time for the signal to be passed and the process to exit.
1127 time.sleep(0.5)
1128 if not proc.poll():
1129 # Forcefully kill the process if we weren't able to signal it.
1130 os.kill(proc.pid, signal.SIGINT)
1131 self.fail("subprocess did not stop on {}".format(name))
1132
1133 @unittest.skip("subprocesses aren't inheriting CTRL+C property")
1134 def test_CTRL_C_EVENT(self):
1135 from ctypes import wintypes
1136 import ctypes
1137
1138 # Make a NULL value by creating a pointer with no argument.
1139 NULL = ctypes.POINTER(ctypes.c_int)()
1140 SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
1141 SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
1142 wintypes.BOOL)
1143 SetConsoleCtrlHandler.restype = wintypes.BOOL
1144
1145 # Calling this with NULL and FALSE causes the calling process to
1146 # handle CTRL+C, rather than ignore it. This property is inherited
1147 # by subprocesses.
1148 SetConsoleCtrlHandler(NULL, 0)
1149
1150 self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
1151
1152 def test_CTRL_BREAK_EVENT(self):
1153 self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT")
1154
1155
Brian Curtind40e6f72010-07-08 21:39:08 +00001156@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
Brian Curtin3b4499c2010-12-28 14:31:47 +00001157@support.skip_unless_symlink
Brian Curtind40e6f72010-07-08 21:39:08 +00001158class Win32SymlinkTests(unittest.TestCase):
1159 filelink = 'filelinktest'
1160 filelink_target = os.path.abspath(__file__)
1161 dirlink = 'dirlinktest'
1162 dirlink_target = os.path.dirname(filelink_target)
1163 missing_link = 'missing link'
1164
1165 def setUp(self):
1166 assert os.path.exists(self.dirlink_target)
1167 assert os.path.exists(self.filelink_target)
1168 assert not os.path.exists(self.dirlink)
1169 assert not os.path.exists(self.filelink)
1170 assert not os.path.exists(self.missing_link)
1171
1172 def tearDown(self):
1173 if os.path.exists(self.filelink):
1174 os.remove(self.filelink)
1175 if os.path.exists(self.dirlink):
1176 os.rmdir(self.dirlink)
1177 if os.path.lexists(self.missing_link):
1178 os.remove(self.missing_link)
1179
1180 def test_directory_link(self):
1181 os.symlink(self.dirlink_target, self.dirlink)
1182 self.assertTrue(os.path.exists(self.dirlink))
1183 self.assertTrue(os.path.isdir(self.dirlink))
1184 self.assertTrue(os.path.islink(self.dirlink))
1185 self.check_stat(self.dirlink, self.dirlink_target)
1186
1187 def test_file_link(self):
1188 os.symlink(self.filelink_target, self.filelink)
1189 self.assertTrue(os.path.exists(self.filelink))
1190 self.assertTrue(os.path.isfile(self.filelink))
1191 self.assertTrue(os.path.islink(self.filelink))
1192 self.check_stat(self.filelink, self.filelink_target)
1193
1194 def _create_missing_dir_link(self):
1195 'Create a "directory" link to a non-existent target'
1196 linkname = self.missing_link
1197 if os.path.lexists(linkname):
1198 os.remove(linkname)
1199 target = r'c:\\target does not exist.29r3c740'
1200 assert not os.path.exists(target)
1201 target_is_dir = True
1202 os.symlink(target, linkname, target_is_dir)
1203
1204 def test_remove_directory_link_to_missing_target(self):
1205 self._create_missing_dir_link()
1206 # For compatibility with Unix, os.remove will check the
1207 # directory status and call RemoveDirectory if the symlink
1208 # was created with target_is_dir==True.
1209 os.remove(self.missing_link)
1210
1211 @unittest.skip("currently fails; consider for improvement")
1212 def test_isdir_on_directory_link_to_missing_target(self):
1213 self._create_missing_dir_link()
1214 # consider having isdir return true for directory links
1215 self.assertTrue(os.path.isdir(self.missing_link))
1216
1217 @unittest.skip("currently fails; consider for improvement")
1218 def test_rmdir_on_directory_link_to_missing_target(self):
1219 self._create_missing_dir_link()
1220 # consider allowing rmdir to remove directory links
1221 os.rmdir(self.missing_link)
1222
1223 def check_stat(self, link, target):
1224 self.assertEqual(os.stat(link), os.stat(target))
1225 self.assertNotEqual(os.lstat(link), os.stat(link))
1226
1227
Victor Stinnere8d51452010-08-19 01:05:19 +00001228class FSEncodingTests(unittest.TestCase):
1229 def test_nop(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +00001230 self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff')
1231 self.assertEqual(os.fsdecode('abc\u0141'), 'abc\u0141')
Benjamin Peterson31191a92010-05-09 03:22:58 +00001232
Victor Stinnere8d51452010-08-19 01:05:19 +00001233 def test_identity(self):
1234 # assert fsdecode(fsencode(x)) == x
1235 for fn in ('unicode\u0141', 'latin\xe9', 'ascii'):
1236 try:
1237 bytesfn = os.fsencode(fn)
1238 except UnicodeEncodeError:
1239 continue
Ezio Melottib3aedd42010-11-20 19:04:17 +00001240 self.assertEqual(os.fsdecode(bytesfn), fn)
Victor Stinnere8d51452010-08-19 01:05:19 +00001241
Victor Stinnerbf9bcab2010-05-09 03:15:33 +00001242
Amaury Forgeot d'Arc4b6fdf32010-09-07 21:31:17 +00001243class PidTests(unittest.TestCase):
1244 @unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
1245 def test_getppid(self):
1246 p = subprocess.Popen([sys.executable, '-c',
1247 'import os; print(os.getppid())'],
1248 stdout=subprocess.PIPE)
1249 stdout, _ = p.communicate()
1250 # We are the parent of our subprocess
1251 self.assertEqual(int(stdout), os.getpid())
1252
1253
Brian Curtin0151b8e2010-09-24 13:43:43 +00001254# The introduction of this TestCase caused at least two different errors on
1255# *nix buildbots. Temporarily skip this to let the buildbots move along.
1256@unittest.skip("Skip due to platform/environment differences on *NIX buildbots")
Brian Curtine8e4b3b2010-09-23 20:04:14 +00001257@unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin")
1258class LoginTests(unittest.TestCase):
1259 def test_getlogin(self):
1260 user_name = os.getlogin()
1261 self.assertNotEqual(len(user_name), 0)
1262
1263
Fred Drake2e2be372001-09-20 21:33:42 +00001264def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +00001265 support.run_unittest(
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001266 FileTests,
Walter Dörwald21d3a322003-05-01 17:45:56 +00001267 StatAttributeTests,
1268 EnvironTests,
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +00001269 WalkTests,
1270 MakedirTests,
Martin v. Löwisbdec50f2004-06-08 08:29:33 +00001271 DevNullTests,
Thomas Wouters477c8d52006-05-27 19:21:47 +00001272 URandomTests,
Guido van Rossume7ba4952007-06-06 23:52:48 +00001273 ExecTests,
Benjamin Petersone1cdfd72009-01-18 21:02:37 +00001274 Win32ErrorTests,
Benjamin Petersonef3e4c22009-04-11 19:48:14 +00001275 TestInvalidFD,
Martin v. Löwis011e8422009-05-05 04:43:17 +00001276 PosixUidGidTests,
Brian Curtineb24d742010-04-12 17:16:38 +00001277 Pep383Tests,
Victor Stinnerbf9bcab2010-05-09 03:15:33 +00001278 Win32KillTests,
Brian Curtind40e6f72010-07-08 21:39:08 +00001279 Win32SymlinkTests,
Victor Stinnere8d51452010-08-19 01:05:19 +00001280 FSEncodingTests,
Amaury Forgeot d'Arc4b6fdf32010-09-07 21:31:17 +00001281 PidTests,
Brian Curtine8e4b3b2010-09-23 20:04:14 +00001282 LoginTests,
Brian Curtin1b9df392010-11-24 20:24:31 +00001283 LinkTests,
Walter Dörwald21d3a322003-05-01 17:45:56 +00001284 )
Fred Drake2e2be372001-09-20 21:33:42 +00001285
1286if __name__ == "__main__":
1287 test_main()