blob: 4da1f1d7beaf1436f91df80eb21eb07e34a458a0 [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
Victor Stinnere0daff12011-03-20 23:36:35 +010093 def write_windows_console(self, *args):
94 retcode = subprocess.call(args,
95 # use a new console to not flood the test output
96 creationflags=subprocess.CREATE_NEW_CONSOLE,
97 # use a shell to hide the console window (SW_HIDE)
98 shell=True)
99 self.assertEqual(retcode, 0)
100
101 @unittest.skipUnless(sys.platform == 'win32',
102 'test specific to the Windows console')
103 def test_write_windows_console(self):
104 # Issue #11395: the Windows console returns an error (12: not enough
105 # space error) on writing into stdout if stdout mode is binary and the
106 # length is greater than 66,000 bytes (or less, depending on heap
107 # usage).
108 code = "print('x' * 100000)"
109 self.write_windows_console(sys.executable, "-c", code)
110 self.write_windows_console(sys.executable, "-u", "-c", code)
111
Amaury Forgeot d'Arce2e36ba2008-08-01 00:14:22 +0000112 def fdopen_helper(self, *args):
113 fd = os.open(support.TESTFN, os.O_RDONLY)
Victor Stinnerbef7fdf2011-07-01 13:45:30 +0200114 f = os.fdopen(fd, *args)
115 f.close()
Amaury Forgeot d'Arce2e36ba2008-08-01 00:14:22 +0000116
117 def test_fdopen(self):
Victor Stinnerbef7fdf2011-07-01 13:45:30 +0200118 fd = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
119 os.close(fd)
120
Amaury Forgeot d'Arce2e36ba2008-08-01 00:14:22 +0000121 self.fdopen_helper()
122 self.fdopen_helper('r')
123 self.fdopen_helper('r', 100)
124
Victor Stinnerbef7fdf2011-07-01 13:45:30 +0200125
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000126# Test attributes on return values from os.*stat* family.
127class StatAttributeTests(unittest.TestCase):
128 def setUp(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000129 os.mkdir(support.TESTFN)
130 self.fname = os.path.join(support.TESTFN, "f1")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000131 f = open(self.fname, 'wb')
Guido van Rossum26d95c32007-08-27 23:18:54 +0000132 f.write(b"ABC")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000133 f.close()
Tim Peterse0c446b2001-10-18 21:57:37 +0000134
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000135 def tearDown(self):
136 os.unlink(self.fname)
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000137 os.rmdir(support.TESTFN)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000138
Antoine Pitrou38425292010-09-21 18:19:07 +0000139 def check_stat_attributes(self, fname):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000140 if not hasattr(os, "stat"):
141 return
142
143 import stat
Antoine Pitrou38425292010-09-21 18:19:07 +0000144 result = os.stat(fname)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000145
146 # Make sure direct access works
Ezio Melottib3aedd42010-11-20 19:04:17 +0000147 self.assertEqual(result[stat.ST_SIZE], 3)
148 self.assertEqual(result.st_size, 3)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000149
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000150 # Make sure all the attributes are there
151 members = dir(result)
152 for name in dir(stat):
153 if name[:3] == 'ST_':
154 attr = name.lower()
Martin v. Löwis4d394df2005-01-23 09:19:22 +0000155 if name.endswith("TIME"):
156 def trunc(x): return int(x)
157 else:
158 def trunc(x): return x
Ezio Melottib3aedd42010-11-20 19:04:17 +0000159 self.assertEqual(trunc(getattr(result, attr)),
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000160 result[getattr(stat, name)])
Benjamin Peterson577473f2010-01-19 00:09:57 +0000161 self.assertIn(attr, members)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000162
163 try:
164 result[200]
165 self.fail("No exception thrown")
166 except IndexError:
167 pass
168
169 # Make sure that assignment fails
170 try:
171 result.st_mode = 1
172 self.fail("No exception thrown")
Collin Winter42dae6a2007-03-28 21:44:53 +0000173 except AttributeError:
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000174 pass
175
176 try:
177 result.st_rdev = 1
178 self.fail("No exception thrown")
Guido van Rossum1fff8782001-10-18 21:19:31 +0000179 except (AttributeError, TypeError):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000180 pass
181
182 try:
183 result.parrot = 1
184 self.fail("No exception thrown")
185 except AttributeError:
186 pass
187
188 # Use the stat_result constructor with a too-short tuple.
189 try:
190 result2 = os.stat_result((10,))
191 self.fail("No exception thrown")
192 except TypeError:
193 pass
194
Ezio Melotti42da6632011-03-15 05:18:48 +0200195 # Use the constructor with a too-long tuple.
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000196 try:
197 result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
198 except TypeError:
199 pass
200
Antoine Pitrou38425292010-09-21 18:19:07 +0000201 def test_stat_attributes(self):
202 self.check_stat_attributes(self.fname)
203
204 def test_stat_attributes_bytes(self):
205 try:
206 fname = self.fname.encode(sys.getfilesystemencoding())
207 except UnicodeEncodeError:
208 self.skipTest("cannot encode %a for the filesystem" % self.fname)
209 self.check_stat_attributes(fname)
Tim Peterse0c446b2001-10-18 21:57:37 +0000210
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000211 def test_statvfs_attributes(self):
212 if not hasattr(os, "statvfs"):
213 return
214
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000215 try:
216 result = os.statvfs(self.fname)
Guido van Rossumb940e112007-01-10 16:19:56 +0000217 except OSError as e:
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000218 # On AtheOS, glibc always returns ENOSYS
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000219 if e.errno == errno.ENOSYS:
220 return
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000221
222 # Make sure direct access works
Ezio Melottib3aedd42010-11-20 19:04:17 +0000223 self.assertEqual(result.f_bfree, result[3])
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000224
Brett Cannoncfaf10c2008-05-16 00:45:35 +0000225 # Make sure all the attributes are there.
226 members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files',
227 'ffree', 'favail', 'flag', 'namemax')
228 for value, member in enumerate(members):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000229 self.assertEqual(getattr(result, 'f_' + member), result[value])
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000230
231 # Make sure that assignment really fails
232 try:
233 result.f_bfree = 1
234 self.fail("No exception thrown")
Collin Winter42dae6a2007-03-28 21:44:53 +0000235 except AttributeError:
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000236 pass
237
238 try:
239 result.parrot = 1
240 self.fail("No exception thrown")
241 except AttributeError:
242 pass
243
244 # Use the constructor with a too-short tuple.
245 try:
246 result2 = os.statvfs_result((10,))
247 self.fail("No exception thrown")
248 except TypeError:
249 pass
250
Ezio Melotti42da6632011-03-15 05:18:48 +0200251 # Use the constructor with a too-long tuple.
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000252 try:
253 result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
254 except TypeError:
255 pass
Fred Drake38c2ef02001-07-17 20:52:51 +0000256
Thomas Wouters89f507f2006-12-13 04:49:30 +0000257 def test_utime_dir(self):
258 delta = 1000000
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000259 st = os.stat(support.TESTFN)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000260 # round to int, because some systems may support sub-second
261 # time stamps in stat, but not in utime.
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000262 os.utime(support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
263 st2 = os.stat(support.TESTFN)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000264 self.assertEqual(st2.st_mtime, int(st.st_mtime-delta))
Thomas Wouters89f507f2006-12-13 04:49:30 +0000265
266 # Restrict test to Win32, since there is no guarantee other
267 # systems support centiseconds
268 if sys.platform == 'win32':
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000269 def get_file_system(path):
Hirokazu Yamamoto5ef6d182008-08-20 04:17:24 +0000270 root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000271 import ctypes
Hirokazu Yamamotoca765d52008-08-20 16:18:19 +0000272 kernel32 = ctypes.windll.kernel32
Hirokazu Yamamoto5ef6d182008-08-20 04:17:24 +0000273 buf = ctypes.create_unicode_buffer("", 100)
Hirokazu Yamamotoca765d52008-08-20 16:18:19 +0000274 if kernel32.GetVolumeInformationW(root, None, 0, None, None, None, buf, len(buf)):
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000275 return buf.value
276
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000277 if get_file_system(support.TESTFN) == "NTFS":
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000278 def test_1565150(self):
279 t1 = 1159195039.25
280 os.utime(self.fname, (t1, t1))
Ezio Melottib3aedd42010-11-20 19:04:17 +0000281 self.assertEqual(os.stat(self.fname).st_mtime, t1)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000282
Amaury Forgeot d'Arca251a852011-01-03 00:19:11 +0000283 def test_large_time(self):
284 t1 = 5000000000 # some day in 2128
285 os.utime(self.fname, (t1, t1))
286 self.assertEqual(os.stat(self.fname).st_mtime, t1)
287
Guido van Rossumd8faa362007-04-27 19:54:29 +0000288 def test_1686475(self):
289 # Verify that an open file can be stat'ed
290 try:
291 os.stat(r"c:\pagefile.sys")
292 except WindowsError as e:
Benjamin Petersonc4fe6f32008-08-19 18:57:56 +0000293 if e.errno == 2: # file does not exist; cannot run test
Guido van Rossumd8faa362007-04-27 19:54:29 +0000294 return
295 self.fail("Could not stat pagefile.sys")
296
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000297from test import mapping_tests
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000298
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000299class EnvironTests(mapping_tests.BasicTestMappingProtocol):
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000300 """check that os.environ object conform to mapping protocol"""
Walter Dörwald118f9312004-06-02 18:42:25 +0000301 type2test = None
Christian Heimes90333392007-11-01 19:08:42 +0000302
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000303 def setUp(self):
304 self.__save = dict(os.environ)
Victor Stinnerb745a742010-05-18 17:17:23 +0000305 if os.supports_bytes_environ:
Victor Stinner208d28c2010-05-07 00:54:14 +0000306 self.__saveb = dict(os.environb)
Christian Heimes90333392007-11-01 19:08:42 +0000307 for key, value in self._reference().items():
308 os.environ[key] = value
309
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000310 def tearDown(self):
311 os.environ.clear()
312 os.environ.update(self.__save)
Victor Stinnerb745a742010-05-18 17:17:23 +0000313 if os.supports_bytes_environ:
Victor Stinner208d28c2010-05-07 00:54:14 +0000314 os.environb.clear()
315 os.environb.update(self.__saveb)
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000316
Christian Heimes90333392007-11-01 19:08:42 +0000317 def _reference(self):
318 return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
319
320 def _empty_mapping(self):
321 os.environ.clear()
322 return os.environ
323
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000324 # Bug 1110478
Martin v. Löwis5510f652005-02-17 21:23:20 +0000325 def test_update2(self):
Christian Heimes90333392007-11-01 19:08:42 +0000326 os.environ.clear()
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000327 if os.path.exists("/bin/sh"):
328 os.environ.update(HELLO="World")
Brian Curtin810921b2010-10-30 21:24:21 +0000329 with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
330 value = popen.read().strip()
Ezio Melottib3aedd42010-11-20 19:04:17 +0000331 self.assertEqual(value, "World")
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000332
Christian Heimes1a13d592007-11-08 14:16:55 +0000333 def test_os_popen_iter(self):
334 if os.path.exists("/bin/sh"):
Brian Curtin810921b2010-10-30 21:24:21 +0000335 with os.popen(
336 "/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen:
337 it = iter(popen)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000338 self.assertEqual(next(it), "line1\n")
339 self.assertEqual(next(it), "line2\n")
340 self.assertEqual(next(it), "line3\n")
Brian Curtin810921b2010-10-30 21:24:21 +0000341 self.assertRaises(StopIteration, next, it)
Christian Heimes1a13d592007-11-08 14:16:55 +0000342
Guido van Rossum67aca9e2007-06-13 21:51:27 +0000343 # Verify environ keys and values from the OS are of the
344 # correct str type.
345 def test_keyvalue_types(self):
346 for key, val in os.environ.items():
Ezio Melottib3aedd42010-11-20 19:04:17 +0000347 self.assertEqual(type(key), str)
348 self.assertEqual(type(val), str)
Guido van Rossum67aca9e2007-06-13 21:51:27 +0000349
Christian Heimes90333392007-11-01 19:08:42 +0000350 def test_items(self):
351 for key, value in self._reference().items():
352 self.assertEqual(os.environ.get(key), value)
353
Ezio Melotti19e4acf2010-02-22 15:59:01 +0000354 # Issue 7310
355 def test___repr__(self):
356 """Check that the repr() of os.environ looks like environ({...})."""
357 env = os.environ
Victor Stinner96f0de92010-07-29 00:29:00 +0000358 self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join(
359 '{!r}: {!r}'.format(key, value)
360 for key, value in env.items())))
Ezio Melotti19e4acf2010-02-22 15:59:01 +0000361
Gregory P. Smithb6e8c7e2010-02-27 07:22:22 +0000362 def test_get_exec_path(self):
363 defpath_list = os.defpath.split(os.pathsep)
364 test_path = ['/monty', '/python', '', '/flying/circus']
365 test_env = {'PATH': os.pathsep.join(test_path)}
366
367 saved_environ = os.environ
368 try:
369 os.environ = dict(test_env)
370 # Test that defaulting to os.environ works.
371 self.assertSequenceEqual(test_path, os.get_exec_path())
372 self.assertSequenceEqual(test_path, os.get_exec_path(env=None))
373 finally:
374 os.environ = saved_environ
375
376 # No PATH environment variable
377 self.assertSequenceEqual(defpath_list, os.get_exec_path({}))
378 # Empty PATH environment variable
379 self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''}))
380 # Supplied PATH environment variable
381 self.assertSequenceEqual(test_path, os.get_exec_path(test_env))
382
Victor Stinnerb745a742010-05-18 17:17:23 +0000383 if os.supports_bytes_environ:
384 # env cannot contain 'PATH' and b'PATH' keys
Victor Stinner38430e22010-08-19 17:10:18 +0000385 try:
Victor Stinner6f35eda2010-10-29 00:38:58 +0000386 # ignore BytesWarning warning
387 with warnings.catch_warnings(record=True):
388 mixed_env = {'PATH': '1', b'PATH': b'2'}
Victor Stinner38430e22010-08-19 17:10:18 +0000389 except BytesWarning:
Victor Stinner6f35eda2010-10-29 00:38:58 +0000390 # mixed_env cannot be created with python -bb
Victor Stinner38430e22010-08-19 17:10:18 +0000391 pass
392 else:
393 self.assertRaises(ValueError, os.get_exec_path, mixed_env)
Victor Stinnerb745a742010-05-18 17:17:23 +0000394
395 # bytes key and/or value
396 self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}),
397 ['abc'])
398 self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}),
399 ['abc'])
400 self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}),
401 ['abc'])
402
403 @unittest.skipUnless(os.supports_bytes_environ,
404 "os.environb required for this test.")
Victor Stinner84ae1182010-05-06 22:05:07 +0000405 def test_environb(self):
406 # os.environ -> os.environb
407 value = 'euro\u20ac'
408 try:
Benjamin Peterson180799d2010-05-06 22:25:42 +0000409 value_bytes = value.encode(sys.getfilesystemencoding(),
410 'surrogateescape')
Victor Stinner84ae1182010-05-06 22:05:07 +0000411 except UnicodeEncodeError:
Benjamin Peterson180799d2010-05-06 22:25:42 +0000412 msg = "U+20AC character is not encodable to %s" % (
413 sys.getfilesystemencoding(),)
Benjamin Peterson932d3f42010-05-06 22:26:31 +0000414 self.skipTest(msg)
Victor Stinner84ae1182010-05-06 22:05:07 +0000415 os.environ['unicode'] = value
Ezio Melottib3aedd42010-11-20 19:04:17 +0000416 self.assertEqual(os.environ['unicode'], value)
417 self.assertEqual(os.environb[b'unicode'], value_bytes)
Victor Stinner84ae1182010-05-06 22:05:07 +0000418
419 # os.environb -> os.environ
420 value = b'\xff'
421 os.environb[b'bytes'] = value
Ezio Melottib3aedd42010-11-20 19:04:17 +0000422 self.assertEqual(os.environb[b'bytes'], value)
Victor Stinner84ae1182010-05-06 22:05:07 +0000423 value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000424 self.assertEqual(os.environ['bytes'], value_str)
Ezio Melotti19e4acf2010-02-22 15:59:01 +0000425
Charles-François Natali7be8f682011-11-27 12:49:27 +0100426 # On FreeBSD < 7 and OS X < 10.6, unsetenv() doesn't return a value (issue
427 # #13415).
428 @unittest.skipIf(sys.platform.startswith(('freebsd', 'darwin')),
429 "due to known OS bug: see issue #13415")
Victor Stinner60b385e2011-11-22 22:01:28 +0100430 def test_unset_error(self):
431 if sys.platform == "win32":
432 # an environment variable is limited to 32,767 characters
433 key = 'x' * 50000
Victor Stinnerb3f82682011-11-22 22:30:19 +0100434 self.assertRaises(ValueError, os.environ.__delitem__, key)
Victor Stinner60b385e2011-11-22 22:01:28 +0100435 else:
436 # "=" is not allowed in a variable name
437 key = 'key='
Victor Stinnerb3f82682011-11-22 22:30:19 +0100438 self.assertRaises(OSError, os.environ.__delitem__, key)
Victor Stinner60b385e2011-11-22 22:01:28 +0100439
Tim Petersc4e09402003-04-25 07:11:48 +0000440class WalkTests(unittest.TestCase):
441 """Tests for os.walk()."""
442
443 def test_traversal(self):
444 import os
445 from os.path import join
446
447 # Build:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000448 # TESTFN/
449 # TEST1/ a file kid and two directory kids
Tim Petersc4e09402003-04-25 07:11:48 +0000450 # tmp1
451 # SUB1/ a file kid and a directory kid
Guido van Rossumd8faa362007-04-27 19:54:29 +0000452 # tmp2
453 # SUB11/ no kids
454 # SUB2/ a file kid and a dirsymlink kid
455 # tmp3
456 # link/ a symlink to TESTFN.2
457 # TEST2/
458 # tmp4 a lone file
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000459 walk_path = join(support.TESTFN, "TEST1")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000460 sub1_path = join(walk_path, "SUB1")
Tim Petersc4e09402003-04-25 07:11:48 +0000461 sub11_path = join(sub1_path, "SUB11")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000462 sub2_path = join(walk_path, "SUB2")
463 tmp1_path = join(walk_path, "tmp1")
Tim Petersc4e09402003-04-25 07:11:48 +0000464 tmp2_path = join(sub1_path, "tmp2")
465 tmp3_path = join(sub2_path, "tmp3")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000466 link_path = join(sub2_path, "link")
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000467 t2_path = join(support.TESTFN, "TEST2")
468 tmp4_path = join(support.TESTFN, "TEST2", "tmp4")
Tim Petersc4e09402003-04-25 07:11:48 +0000469
470 # Create stuff.
471 os.makedirs(sub11_path)
472 os.makedirs(sub2_path)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000473 os.makedirs(t2_path)
474 for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
Alex Martelli01c77c62006-08-24 02:58:11 +0000475 f = open(path, "w")
Tim Petersc4e09402003-04-25 07:11:48 +0000476 f.write("I'm " + path + " and proud of it. Blame test_os.\n")
477 f.close()
Brian Curtin3b4499c2010-12-28 14:31:47 +0000478 if support.can_symlink():
Guido van Rossumd8faa362007-04-27 19:54:29 +0000479 os.symlink(os.path.abspath(t2_path), link_path)
480 sub2_tree = (sub2_path, ["link"], ["tmp3"])
481 else:
482 sub2_tree = (sub2_path, [], ["tmp3"])
Tim Petersc4e09402003-04-25 07:11:48 +0000483
484 # Walk top-down.
Guido van Rossumd8faa362007-04-27 19:54:29 +0000485 all = list(os.walk(walk_path))
Tim Petersc4e09402003-04-25 07:11:48 +0000486 self.assertEqual(len(all), 4)
487 # We can't know which order SUB1 and SUB2 will appear in.
488 # Not flipped: TESTFN, SUB1, SUB11, SUB2
489 # flipped: TESTFN, SUB2, SUB1, SUB11
490 flipped = all[0][1][0] != "SUB1"
491 all[0][1].sort()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000492 self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000493 self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
494 self.assertEqual(all[2 + flipped], (sub11_path, [], []))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000495 self.assertEqual(all[3 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000496
497 # Prune the search.
498 all = []
Guido van Rossumd8faa362007-04-27 19:54:29 +0000499 for root, dirs, files in os.walk(walk_path):
Tim Petersc4e09402003-04-25 07:11:48 +0000500 all.append((root, dirs, files))
501 # Don't descend into SUB1.
502 if 'SUB1' in dirs:
503 # Note that this also mutates the dirs we appended to all!
504 dirs.remove('SUB1')
505 self.assertEqual(len(all), 2)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000506 self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"]))
507 self.assertEqual(all[1], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000508
509 # Walk bottom-up.
Guido van Rossumd8faa362007-04-27 19:54:29 +0000510 all = list(os.walk(walk_path, topdown=False))
Tim Petersc4e09402003-04-25 07:11:48 +0000511 self.assertEqual(len(all), 4)
512 # We can't know which order SUB1 and SUB2 will appear in.
513 # Not flipped: SUB11, SUB1, SUB2, TESTFN
514 # flipped: SUB2, SUB11, SUB1, TESTFN
515 flipped = all[3][1][0] != "SUB1"
516 all[3][1].sort()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000517 self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000518 self.assertEqual(all[flipped], (sub11_path, [], []))
519 self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000520 self.assertEqual(all[2 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000521
Brian Curtin3b4499c2010-12-28 14:31:47 +0000522 if support.can_symlink():
Guido van Rossumd8faa362007-04-27 19:54:29 +0000523 # Walk, following symlinks.
524 for root, dirs, files in os.walk(walk_path, followlinks=True):
525 if root == link_path:
526 self.assertEqual(dirs, [])
527 self.assertEqual(files, ["tmp4"])
528 break
529 else:
530 self.fail("Didn't follow symlink with followlinks=True")
531
532 def tearDown(self):
Tim Petersc4e09402003-04-25 07:11:48 +0000533 # Tear everything down. This is a decent use for bottom-up on
534 # Windows, which doesn't have a recursive delete command. The
535 # (not so) subtlety is that rmdir will fail unless the dir's
536 # kids are removed first, so bottom up is essential.
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000537 for root, dirs, files in os.walk(support.TESTFN, topdown=False):
Tim Petersc4e09402003-04-25 07:11:48 +0000538 for name in files:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000539 os.remove(os.path.join(root, name))
Tim Petersc4e09402003-04-25 07:11:48 +0000540 for name in dirs:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000541 dirname = os.path.join(root, name)
542 if not os.path.islink(dirname):
543 os.rmdir(dirname)
544 else:
545 os.remove(dirname)
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000546 os.rmdir(support.TESTFN)
Tim Petersc4e09402003-04-25 07:11:48 +0000547
Guido van Rossume7ba4952007-06-06 23:52:48 +0000548class MakedirTests(unittest.TestCase):
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000549 def setUp(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000550 os.mkdir(support.TESTFN)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000551
552 def test_makedir(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000553 base = support.TESTFN
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000554 path = os.path.join(base, 'dir1', 'dir2', 'dir3')
555 os.makedirs(path) # Should work
556 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
557 os.makedirs(path)
558
559 # Try paths with a '.' in them
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000560 self.assertRaises(OSError, os.makedirs, os.curdir)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000561 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
562 os.makedirs(path)
563 path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
564 'dir5', 'dir6')
565 os.makedirs(path)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000566
Terry Reedy5a22b652010-12-02 07:05:56 +0000567 def test_exist_ok_existing_directory(self):
568 path = os.path.join(support.TESTFN, 'dir1')
569 mode = 0o777
570 old_mask = os.umask(0o022)
571 os.makedirs(path, mode)
572 self.assertRaises(OSError, os.makedirs, path, mode)
573 self.assertRaises(OSError, os.makedirs, path, mode, exist_ok=False)
574 self.assertRaises(OSError, os.makedirs, path, 0o776, exist_ok=True)
575 os.makedirs(path, mode=mode, exist_ok=True)
576 os.umask(old_mask)
577
578 def test_exist_ok_existing_regular_file(self):
579 base = support.TESTFN
580 path = os.path.join(support.TESTFN, 'dir1')
581 f = open(path, 'w')
582 f.write('abc')
583 f.close()
584 self.assertRaises(OSError, os.makedirs, path)
585 self.assertRaises(OSError, os.makedirs, path, exist_ok=False)
586 self.assertRaises(OSError, os.makedirs, path, exist_ok=True)
587 os.remove(path)
588
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000589 def tearDown(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000590 path = os.path.join(support.TESTFN, 'dir1', 'dir2', 'dir3',
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000591 'dir4', 'dir5', 'dir6')
592 # If the tests failed, the bottom-most directory ('../dir6')
593 # may not have been created, so we look for the outermost directory
594 # that exists.
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000595 while not os.path.exists(path) and path != support.TESTFN:
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000596 path = os.path.dirname(path)
597
598 os.removedirs(path)
599
Guido van Rossume7ba4952007-06-06 23:52:48 +0000600class DevNullTests(unittest.TestCase):
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000601 def test_devnull(self):
Victor Stinnera6d2c762011-06-30 18:20:11 +0200602 with open(os.devnull, 'wb') as f:
603 f.write(b'hello')
604 f.close()
605 with open(os.devnull, 'rb') as f:
606 self.assertEqual(f.read(), b'')
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000607
Guido van Rossume7ba4952007-06-06 23:52:48 +0000608class URandomTests(unittest.TestCase):
Martin v. Löwisdc3883f2004-08-29 15:46:35 +0000609 def test_urandom(self):
610 try:
611 self.assertEqual(len(os.urandom(1)), 1)
612 self.assertEqual(len(os.urandom(10)), 10)
613 self.assertEqual(len(os.urandom(100)), 100)
614 self.assertEqual(len(os.urandom(1000)), 1000)
615 except NotImplementedError:
616 pass
617
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000618@contextlib.contextmanager
619def _execvpe_mockup(defpath=None):
620 """
621 Stubs out execv and execve functions when used as context manager.
622 Records exec calls. The mock execv and execve functions always raise an
623 exception as they would normally never return.
624 """
625 # A list of tuples containing (function name, first arg, args)
626 # of calls to execv or execve that have been made.
627 calls = []
628
629 def mock_execv(name, *args):
630 calls.append(('execv', name, args))
631 raise RuntimeError("execv called")
632
633 def mock_execve(name, *args):
634 calls.append(('execve', name, args))
635 raise OSError(errno.ENOTDIR, "execve called")
636
637 try:
638 orig_execv = os.execv
639 orig_execve = os.execve
640 orig_defpath = os.defpath
641 os.execv = mock_execv
642 os.execve = mock_execve
643 if defpath is not None:
644 os.defpath = defpath
645 yield calls
646 finally:
647 os.execv = orig_execv
648 os.execve = orig_execve
649 os.defpath = orig_defpath
650
Guido van Rossume7ba4952007-06-06 23:52:48 +0000651class ExecTests(unittest.TestCase):
Mark Dickinson7cf03892010-04-16 13:45:35 +0000652 @unittest.skipIf(USING_LINUXTHREADS,
653 "avoid triggering a linuxthreads bug: see issue #4970")
Guido van Rossume7ba4952007-06-06 23:52:48 +0000654 def test_execvpe_with_bad_program(self):
Mark Dickinson7cf03892010-04-16 13:45:35 +0000655 self.assertRaises(OSError, os.execvpe, 'no such app-',
656 ['no such app-'], None)
Guido van Rossume7ba4952007-06-06 23:52:48 +0000657
Thomas Heller6790d602007-08-30 17:15:14 +0000658 def test_execvpe_with_bad_arglist(self):
659 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
660
Gregory P. Smith4ae37772010-05-08 18:05:46 +0000661 @unittest.skipUnless(hasattr(os, '_execvpe'),
662 "No internal os._execvpe function to test.")
Victor Stinnerb745a742010-05-18 17:17:23 +0000663 def _test_internal_execvpe(self, test_type):
664 program_path = os.sep + 'absolutepath'
665 if test_type is bytes:
666 program = b'executable'
667 fullpath = os.path.join(os.fsencode(program_path), program)
668 native_fullpath = fullpath
669 arguments = [b'progname', 'arg1', 'arg2']
670 else:
671 program = 'executable'
672 arguments = ['progname', 'arg1', 'arg2']
673 fullpath = os.path.join(program_path, program)
674 if os.name != "nt":
675 native_fullpath = os.fsencode(fullpath)
676 else:
677 native_fullpath = fullpath
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000678 env = {'spam': 'beans'}
679
Victor Stinnerb745a742010-05-18 17:17:23 +0000680 # test os._execvpe() with an absolute path
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000681 with _execvpe_mockup() as calls:
Victor Stinnerb745a742010-05-18 17:17:23 +0000682 self.assertRaises(RuntimeError,
683 os._execvpe, fullpath, arguments)
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000684 self.assertEqual(len(calls), 1)
685 self.assertEqual(calls[0], ('execv', fullpath, (arguments,)))
686
Victor Stinnerb745a742010-05-18 17:17:23 +0000687 # test os._execvpe() with a relative path:
688 # os.get_exec_path() returns defpath
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000689 with _execvpe_mockup(defpath=program_path) as calls:
Victor Stinnerb745a742010-05-18 17:17:23 +0000690 self.assertRaises(OSError,
691 os._execvpe, program, arguments, env=env)
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000692 self.assertEqual(len(calls), 1)
Victor Stinnerb745a742010-05-18 17:17:23 +0000693 self.assertSequenceEqual(calls[0],
694 ('execve', native_fullpath, (arguments, env)))
695
696 # test os._execvpe() with a relative path:
697 # os.get_exec_path() reads the 'PATH' variable
698 with _execvpe_mockup() as calls:
699 env_path = env.copy()
Victor Stinner38430e22010-08-19 17:10:18 +0000700 if test_type is bytes:
701 env_path[b'PATH'] = program_path
702 else:
703 env_path['PATH'] = program_path
Victor Stinnerb745a742010-05-18 17:17:23 +0000704 self.assertRaises(OSError,
705 os._execvpe, program, arguments, env=env_path)
706 self.assertEqual(len(calls), 1)
707 self.assertSequenceEqual(calls[0],
708 ('execve', native_fullpath, (arguments, env_path)))
709
710 def test_internal_execvpe_str(self):
711 self._test_internal_execvpe(str)
712 if os.name != "nt":
713 self._test_internal_execvpe(bytes)
Victor Stinnerc2d095f2010-05-17 00:14:53 +0000714
Gregory P. Smith4ae37772010-05-08 18:05:46 +0000715
Thomas Wouters477c8d52006-05-27 19:21:47 +0000716class Win32ErrorTests(unittest.TestCase):
717 def test_rename(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000718 self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak")
Thomas Wouters477c8d52006-05-27 19:21:47 +0000719
720 def test_remove(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000721 self.assertRaises(WindowsError, os.remove, support.TESTFN)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000722
723 def test_chdir(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000724 self.assertRaises(WindowsError, os.chdir, support.TESTFN)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000725
726 def test_mkdir(self):
Amaury Forgeot d'Arc2fc224f2009-02-19 23:23:47 +0000727 f = open(support.TESTFN, "w")
Benjamin Petersonf91df042009-02-13 02:50:59 +0000728 try:
729 self.assertRaises(WindowsError, os.mkdir, support.TESTFN)
730 finally:
731 f.close()
Amaury Forgeot d'Arc2fc224f2009-02-19 23:23:47 +0000732 os.unlink(support.TESTFN)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000733
734 def test_utime(self):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000735 self.assertRaises(WindowsError, os.utime, support.TESTFN, None)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000736
Thomas Wouters477c8d52006-05-27 19:21:47 +0000737 def test_chmod(self):
Benjamin Petersonf91df042009-02-13 02:50:59 +0000738 self.assertRaises(WindowsError, os.chmod, support.TESTFN, 0)
Thomas Wouters477c8d52006-05-27 19:21:47 +0000739
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000740class TestInvalidFD(unittest.TestCase):
Benjamin Peterson05e782f2009-01-19 15:15:02 +0000741 singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000742 "fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
743 #singles.append("close")
744 #We omit close because it doesn'r raise an exception on some platforms
745 def get_single(f):
746 def helper(self):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000747 if hasattr(os, f):
748 self.check(getattr(os, f))
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000749 return helper
750 for f in singles:
751 locals()["test_"+f] = get_single(f)
752
Benjamin Peterson7522c742009-01-19 21:00:09 +0000753 def check(self, f, *args):
Benjamin Peterson5c6d7872009-02-06 02:40:07 +0000754 try:
755 f(support.make_bad_fd(), *args)
756 except OSError as e:
757 self.assertEqual(e.errno, errno.EBADF)
758 else:
759 self.fail("%r didn't raise a OSError with a bad file descriptor"
760 % f)
Benjamin Peterson7522c742009-01-19 21:00:09 +0000761
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000762 def test_isatty(self):
763 if hasattr(os, "isatty"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000764 self.assertEqual(os.isatty(support.make_bad_fd()), False)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000765
766 def test_closerange(self):
767 if hasattr(os, "closerange"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000768 fd = support.make_bad_fd()
R. David Murray630cc482009-07-22 15:20:27 +0000769 # Make sure none of the descriptors we are about to close are
770 # currently valid (issue 6542).
771 for i in range(10):
772 try: os.fstat(fd+i)
773 except OSError:
774 pass
775 else:
776 break
777 if i < 2:
778 raise unittest.SkipTest(
779 "Unable to acquire a range of invalid file descriptors")
780 self.assertEqual(os.closerange(fd, fd + i-1), None)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000781
782 def test_dup2(self):
783 if hasattr(os, "dup2"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000784 self.check(os.dup2, 20)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000785
786 def test_fchmod(self):
787 if hasattr(os, "fchmod"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000788 self.check(os.fchmod, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000789
790 def test_fchown(self):
791 if hasattr(os, "fchown"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000792 self.check(os.fchown, -1, -1)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000793
794 def test_fpathconf(self):
795 if hasattr(os, "fpathconf"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000796 self.check(os.fpathconf, "PC_NAME_MAX")
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000797
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000798 def test_ftruncate(self):
799 if hasattr(os, "ftruncate"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000800 self.check(os.ftruncate, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000801
802 def test_lseek(self):
803 if hasattr(os, "lseek"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000804 self.check(os.lseek, 0, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000805
806 def test_read(self):
807 if hasattr(os, "read"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000808 self.check(os.read, 1)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000809
810 def test_tcsetpgrpt(self):
811 if hasattr(os, "tcsetpgrp"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000812 self.check(os.tcsetpgrp, 0)
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000813
814 def test_write(self):
815 if hasattr(os, "write"):
Benjamin Peterson7522c742009-01-19 21:00:09 +0000816 self.check(os.write, b" ")
Benjamin Petersone1cdfd72009-01-18 21:02:37 +0000817
Brian Curtin1b9df392010-11-24 20:24:31 +0000818
819class LinkTests(unittest.TestCase):
820 def setUp(self):
821 self.file1 = support.TESTFN
822 self.file2 = os.path.join(support.TESTFN + "2")
823
Brian Curtinc0abc4e2010-11-30 23:46:54 +0000824 def tearDown(self):
Brian Curtin1b9df392010-11-24 20:24:31 +0000825 for file in (self.file1, self.file2):
826 if os.path.exists(file):
827 os.unlink(file)
828
Brian Curtin1b9df392010-11-24 20:24:31 +0000829 def _test_link(self, file1, file2):
830 with open(file1, "w") as f1:
831 f1.write("test")
832
833 os.link(file1, file2)
834 with open(file1, "r") as f1, open(file2, "r") as f2:
835 self.assertTrue(os.path.sameopenfile(f1.fileno(), f2.fileno()))
836
837 def test_link(self):
838 self._test_link(self.file1, self.file2)
839
840 def test_link_bytes(self):
841 self._test_link(bytes(self.file1, sys.getfilesystemencoding()),
842 bytes(self.file2, sys.getfilesystemencoding()))
843
Brian Curtinf498b752010-11-30 15:54:04 +0000844 def test_unicode_name(self):
Brian Curtin43f0c272010-11-30 15:40:04 +0000845 try:
Brian Curtinf498b752010-11-30 15:54:04 +0000846 os.fsencode("\xf1")
Brian Curtin43f0c272010-11-30 15:40:04 +0000847 except UnicodeError:
848 raise unittest.SkipTest("Unable to encode for this platform.")
849
Brian Curtinf498b752010-11-30 15:54:04 +0000850 self.file1 += "\xf1"
Brian Curtinfc889c42010-11-28 23:59:46 +0000851 self.file2 = self.file1 + "2"
852 self._test_link(self.file1, self.file2)
853
Thomas Wouters477c8d52006-05-27 19:21:47 +0000854if sys.platform != 'win32':
855 class Win32ErrorTests(unittest.TestCase):
856 pass
857
Benjamin Petersonef3e4c22009-04-11 19:48:14 +0000858 class PosixUidGidTests(unittest.TestCase):
859 if hasattr(os, 'setuid'):
860 def test_setuid(self):
861 if os.getuid() != 0:
862 self.assertRaises(os.error, os.setuid, 0)
863 self.assertRaises(OverflowError, os.setuid, 1<<32)
864
865 if hasattr(os, 'setgid'):
866 def test_setgid(self):
867 if os.getuid() != 0:
868 self.assertRaises(os.error, os.setgid, 0)
869 self.assertRaises(OverflowError, os.setgid, 1<<32)
870
871 if hasattr(os, 'seteuid'):
872 def test_seteuid(self):
873 if os.getuid() != 0:
874 self.assertRaises(os.error, os.seteuid, 0)
875 self.assertRaises(OverflowError, os.seteuid, 1<<32)
876
877 if hasattr(os, 'setegid'):
878 def test_setegid(self):
879 if os.getuid() != 0:
880 self.assertRaises(os.error, os.setegid, 0)
881 self.assertRaises(OverflowError, os.setegid, 1<<32)
882
883 if hasattr(os, 'setreuid'):
884 def test_setreuid(self):
885 if os.getuid() != 0:
886 self.assertRaises(os.error, os.setreuid, 0, 0)
887 self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
888 self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000889
890 def test_setreuid_neg1(self):
891 # Needs to accept -1. We run this in a subprocess to avoid
892 # altering the test runner's process state (issue8045).
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000893 subprocess.check_call([
894 sys.executable, '-c',
895 'import os,sys;os.setreuid(-1,-1);sys.exit(0)'])
Benjamin Petersonef3e4c22009-04-11 19:48:14 +0000896
897 if hasattr(os, 'setregid'):
898 def test_setregid(self):
899 if os.getuid() != 0:
900 self.assertRaises(os.error, os.setregid, 0, 0)
901 self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
902 self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000903
904 def test_setregid_neg1(self):
905 # Needs to accept -1. We run this in a subprocess to avoid
906 # altering the test runner's process state (issue8045).
Benjamin Petersonebe87ba2010-03-06 20:34:24 +0000907 subprocess.check_call([
908 sys.executable, '-c',
909 'import os,sys;os.setregid(-1,-1);sys.exit(0)'])
Martin v. Löwis011e8422009-05-05 04:43:17 +0000910
911 class Pep383Tests(unittest.TestCase):
Martin v. Löwis011e8422009-05-05 04:43:17 +0000912 def setUp(self):
Victor Stinnerd91df1a2010-08-18 10:56:19 +0000913 if support.TESTFN_UNENCODABLE:
914 self.dir = support.TESTFN_UNENCODABLE
915 else:
916 self.dir = support.TESTFN
917 self.bdir = os.fsencode(self.dir)
918
919 bytesfn = []
920 def add_filename(fn):
921 try:
922 fn = os.fsencode(fn)
923 except UnicodeEncodeError:
924 return
925 bytesfn.append(fn)
926 add_filename(support.TESTFN_UNICODE)
927 if support.TESTFN_UNENCODABLE:
928 add_filename(support.TESTFN_UNENCODABLE)
929 if not bytesfn:
930 self.skipTest("couldn't create any non-ascii filename")
931
932 self.unicodefn = set()
Martin v. Löwis011e8422009-05-05 04:43:17 +0000933 os.mkdir(self.dir)
Victor Stinnerd91df1a2010-08-18 10:56:19 +0000934 try:
935 for fn in bytesfn:
936 f = open(os.path.join(self.bdir, fn), "w")
937 f.close()
Victor Stinnere8d51452010-08-19 01:05:19 +0000938 fn = os.fsdecode(fn)
Victor Stinnerd91df1a2010-08-18 10:56:19 +0000939 if fn in self.unicodefn:
940 raise ValueError("duplicate filename")
941 self.unicodefn.add(fn)
942 except:
943 shutil.rmtree(self.dir)
944 raise
Martin v. Löwis011e8422009-05-05 04:43:17 +0000945
946 def tearDown(self):
947 shutil.rmtree(self.dir)
Martin v. Löwis011e8422009-05-05 04:43:17 +0000948
949 def test_listdir(self):
Victor Stinnerd91df1a2010-08-18 10:56:19 +0000950 expected = self.unicodefn
951 found = set(os.listdir(self.dir))
Ezio Melottib3aedd42010-11-20 19:04:17 +0000952 self.assertEqual(found, expected)
Martin v. Löwis011e8422009-05-05 04:43:17 +0000953
954 def test_open(self):
955 for fn in self.unicodefn:
Victor Stinnera6d2c762011-06-30 18:20:11 +0200956 f = open(os.path.join(self.dir, fn), 'rb')
Martin v. Löwis011e8422009-05-05 04:43:17 +0000957 f.close()
958
959 def test_stat(self):
960 for fn in self.unicodefn:
961 os.stat(os.path.join(self.dir, fn))
Benjamin Petersonef3e4c22009-04-11 19:48:14 +0000962else:
963 class PosixUidGidTests(unittest.TestCase):
964 pass
Martin v. Löwis011e8422009-05-05 04:43:17 +0000965 class Pep383Tests(unittest.TestCase):
966 pass
Benjamin Petersonef3e4c22009-04-11 19:48:14 +0000967
Brian Curtineb24d742010-04-12 17:16:38 +0000968@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
969class Win32KillTests(unittest.TestCase):
Brian Curtinc3acbc32010-05-28 16:08:40 +0000970 def _kill(self, sig):
971 # Start sys.executable as a subprocess and communicate from the
972 # subprocess to the parent that the interpreter is ready. When it
973 # becomes ready, send *sig* via os.kill to the subprocess and check
974 # that the return code is equal to *sig*.
975 import ctypes
976 from ctypes import wintypes
977 import msvcrt
978
979 # Since we can't access the contents of the process' stdout until the
980 # process has exited, use PeekNamedPipe to see what's inside stdout
981 # without waiting. This is done so we can tell that the interpreter
982 # is started and running at a point where it could handle a signal.
983 PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
984 PeekNamedPipe.restype = wintypes.BOOL
985 PeekNamedPipe.argtypes = (wintypes.HANDLE, # Pipe handle
986 ctypes.POINTER(ctypes.c_char), # stdout buf
987 wintypes.DWORD, # Buffer size
988 ctypes.POINTER(wintypes.DWORD), # bytes read
989 ctypes.POINTER(wintypes.DWORD), # bytes avail
990 ctypes.POINTER(wintypes.DWORD)) # bytes left
991 msg = "running"
992 proc = subprocess.Popen([sys.executable, "-c",
993 "import sys;"
994 "sys.stdout.write('{}');"
995 "sys.stdout.flush();"
996 "input()".format(msg)],
997 stdout=subprocess.PIPE,
998 stderr=subprocess.PIPE,
999 stdin=subprocess.PIPE)
Brian Curtin43ec5772010-11-05 15:17:11 +00001000 self.addCleanup(proc.stdout.close)
1001 self.addCleanup(proc.stderr.close)
1002 self.addCleanup(proc.stdin.close)
Brian Curtinc3acbc32010-05-28 16:08:40 +00001003
1004 count, max = 0, 100
1005 while count < max and proc.poll() is None:
1006 # Create a string buffer to store the result of stdout from the pipe
1007 buf = ctypes.create_string_buffer(len(msg))
1008 # Obtain the text currently in proc.stdout
1009 # Bytes read/avail/left are left as NULL and unused
1010 rslt = PeekNamedPipe(msvcrt.get_osfhandle(proc.stdout.fileno()),
1011 buf, ctypes.sizeof(buf), None, None, None)
1012 self.assertNotEqual(rslt, 0, "PeekNamedPipe failed")
1013 if buf.value:
1014 self.assertEqual(msg, buf.value.decode())
1015 break
1016 time.sleep(0.1)
1017 count += 1
1018 else:
1019 self.fail("Did not receive communication from the subprocess")
1020
Brian Curtineb24d742010-04-12 17:16:38 +00001021 os.kill(proc.pid, sig)
1022 self.assertEqual(proc.wait(), sig)
1023
1024 def test_kill_sigterm(self):
1025 # SIGTERM doesn't mean anything special, but make sure it works
Brian Curtinc3acbc32010-05-28 16:08:40 +00001026 self._kill(signal.SIGTERM)
Brian Curtineb24d742010-04-12 17:16:38 +00001027
1028 def test_kill_int(self):
1029 # os.kill on Windows can take an int which gets set as the exit code
Brian Curtinc3acbc32010-05-28 16:08:40 +00001030 self._kill(100)
Brian Curtineb24d742010-04-12 17:16:38 +00001031
1032 def _kill_with_event(self, event, name):
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001033 tagname = "test_os_%s" % uuid.uuid1()
1034 m = mmap.mmap(-1, 1, tagname)
1035 m[0] = 0
Brian Curtineb24d742010-04-12 17:16:38 +00001036 # Run a script which has console control handling enabled.
1037 proc = subprocess.Popen([sys.executable,
1038 os.path.join(os.path.dirname(__file__),
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001039 "win_console_handler.py"), tagname],
Brian Curtineb24d742010-04-12 17:16:38 +00001040 creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
1041 # Let the interpreter startup before we send signals. See #3137.
Hirokazu Yamamoto8e9fe9f2010-12-05 02:41:46 +00001042 count, max = 0, 100
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001043 while count < max and proc.poll() is None:
Brian Curtinf668df52010-10-15 14:21:06 +00001044 if m[0] == 1:
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001045 break
Hirokazu Yamamoto8e9fe9f2010-12-05 02:41:46 +00001046 time.sleep(0.1)
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001047 count += 1
1048 else:
Hirokazu Yamamoto8e9fe9f2010-12-05 02:41:46 +00001049 # Forcefully kill the process if we weren't able to signal it.
1050 os.kill(proc.pid, signal.SIGINT)
Hirokazu Yamamoto54c950f2010-10-08 08:38:15 +00001051 self.fail("Subprocess didn't finish initialization")
Brian Curtineb24d742010-04-12 17:16:38 +00001052 os.kill(proc.pid, event)
1053 # proc.send_signal(event) could also be done here.
1054 # Allow time for the signal to be passed and the process to exit.
1055 time.sleep(0.5)
1056 if not proc.poll():
1057 # Forcefully kill the process if we weren't able to signal it.
1058 os.kill(proc.pid, signal.SIGINT)
1059 self.fail("subprocess did not stop on {}".format(name))
1060
1061 @unittest.skip("subprocesses aren't inheriting CTRL+C property")
1062 def test_CTRL_C_EVENT(self):
1063 from ctypes import wintypes
1064 import ctypes
1065
1066 # Make a NULL value by creating a pointer with no argument.
1067 NULL = ctypes.POINTER(ctypes.c_int)()
1068 SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
1069 SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
1070 wintypes.BOOL)
1071 SetConsoleCtrlHandler.restype = wintypes.BOOL
1072
1073 # Calling this with NULL and FALSE causes the calling process to
1074 # handle CTRL+C, rather than ignore it. This property is inherited
1075 # by subprocesses.
1076 SetConsoleCtrlHandler(NULL, 0)
1077
1078 self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
1079
1080 def test_CTRL_BREAK_EVENT(self):
1081 self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT")
1082
1083
Brian Curtind40e6f72010-07-08 21:39:08 +00001084@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
Brian Curtin3b4499c2010-12-28 14:31:47 +00001085@support.skip_unless_symlink
Brian Curtind40e6f72010-07-08 21:39:08 +00001086class Win32SymlinkTests(unittest.TestCase):
1087 filelink = 'filelinktest'
1088 filelink_target = os.path.abspath(__file__)
1089 dirlink = 'dirlinktest'
1090 dirlink_target = os.path.dirname(filelink_target)
1091 missing_link = 'missing link'
1092
1093 def setUp(self):
1094 assert os.path.exists(self.dirlink_target)
1095 assert os.path.exists(self.filelink_target)
1096 assert not os.path.exists(self.dirlink)
1097 assert not os.path.exists(self.filelink)
1098 assert not os.path.exists(self.missing_link)
1099
1100 def tearDown(self):
1101 if os.path.exists(self.filelink):
1102 os.remove(self.filelink)
1103 if os.path.exists(self.dirlink):
1104 os.rmdir(self.dirlink)
1105 if os.path.lexists(self.missing_link):
1106 os.remove(self.missing_link)
1107
1108 def test_directory_link(self):
1109 os.symlink(self.dirlink_target, self.dirlink)
1110 self.assertTrue(os.path.exists(self.dirlink))
1111 self.assertTrue(os.path.isdir(self.dirlink))
1112 self.assertTrue(os.path.islink(self.dirlink))
1113 self.check_stat(self.dirlink, self.dirlink_target)
1114
1115 def test_file_link(self):
1116 os.symlink(self.filelink_target, self.filelink)
1117 self.assertTrue(os.path.exists(self.filelink))
1118 self.assertTrue(os.path.isfile(self.filelink))
1119 self.assertTrue(os.path.islink(self.filelink))
1120 self.check_stat(self.filelink, self.filelink_target)
1121
1122 def _create_missing_dir_link(self):
1123 'Create a "directory" link to a non-existent target'
1124 linkname = self.missing_link
1125 if os.path.lexists(linkname):
1126 os.remove(linkname)
1127 target = r'c:\\target does not exist.29r3c740'
1128 assert not os.path.exists(target)
1129 target_is_dir = True
1130 os.symlink(target, linkname, target_is_dir)
1131
1132 def test_remove_directory_link_to_missing_target(self):
1133 self._create_missing_dir_link()
1134 # For compatibility with Unix, os.remove will check the
1135 # directory status and call RemoveDirectory if the symlink
1136 # was created with target_is_dir==True.
1137 os.remove(self.missing_link)
1138
1139 @unittest.skip("currently fails; consider for improvement")
1140 def test_isdir_on_directory_link_to_missing_target(self):
1141 self._create_missing_dir_link()
1142 # consider having isdir return true for directory links
1143 self.assertTrue(os.path.isdir(self.missing_link))
1144
1145 @unittest.skip("currently fails; consider for improvement")
1146 def test_rmdir_on_directory_link_to_missing_target(self):
1147 self._create_missing_dir_link()
1148 # consider allowing rmdir to remove directory links
1149 os.rmdir(self.missing_link)
1150
1151 def check_stat(self, link, target):
1152 self.assertEqual(os.stat(link), os.stat(target))
1153 self.assertNotEqual(os.lstat(link), os.stat(link))
1154
Brian Curtind25aef52011-06-13 15:16:04 -05001155 bytes_link = os.fsencode(link)
1156 self.assertEqual(os.stat(bytes_link), os.stat(target))
1157 self.assertNotEqual(os.lstat(bytes_link), os.stat(bytes_link))
1158
1159 def test_12084(self):
1160 level1 = os.path.abspath(support.TESTFN)
1161 level2 = os.path.join(level1, "level2")
1162 level3 = os.path.join(level2, "level3")
1163 try:
1164 os.mkdir(level1)
1165 os.mkdir(level2)
1166 os.mkdir(level3)
1167
1168 file1 = os.path.abspath(os.path.join(level1, "file1"))
1169
1170 with open(file1, "w") as f:
1171 f.write("file1")
1172
1173 orig_dir = os.getcwd()
1174 try:
1175 os.chdir(level2)
1176 link = os.path.join(level2, "link")
1177 os.symlink(os.path.relpath(file1), "link")
1178 self.assertIn("link", os.listdir(os.getcwd()))
1179
1180 # Check os.stat calls from the same dir as the link
1181 self.assertEqual(os.stat(file1), os.stat("link"))
1182
1183 # Check os.stat calls from a dir below the link
1184 os.chdir(level1)
1185 self.assertEqual(os.stat(file1),
1186 os.stat(os.path.relpath(link)))
1187
1188 # Check os.stat calls from a dir above the link
1189 os.chdir(level3)
1190 self.assertEqual(os.stat(file1),
1191 os.stat(os.path.relpath(link)))
1192 finally:
1193 os.chdir(orig_dir)
1194 except OSError as err:
1195 self.fail(err)
1196 finally:
1197 os.remove(file1)
1198 shutil.rmtree(level1)
1199
Brian Curtind40e6f72010-07-08 21:39:08 +00001200
Victor Stinnere8d51452010-08-19 01:05:19 +00001201class FSEncodingTests(unittest.TestCase):
1202 def test_nop(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +00001203 self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff')
1204 self.assertEqual(os.fsdecode('abc\u0141'), 'abc\u0141')
Benjamin Peterson31191a92010-05-09 03:22:58 +00001205
Victor Stinnere8d51452010-08-19 01:05:19 +00001206 def test_identity(self):
1207 # assert fsdecode(fsencode(x)) == x
1208 for fn in ('unicode\u0141', 'latin\xe9', 'ascii'):
1209 try:
1210 bytesfn = os.fsencode(fn)
1211 except UnicodeEncodeError:
1212 continue
Ezio Melottib3aedd42010-11-20 19:04:17 +00001213 self.assertEqual(os.fsdecode(bytesfn), fn)
Victor Stinnere8d51452010-08-19 01:05:19 +00001214
Victor Stinnerbf9bcab2010-05-09 03:15:33 +00001215
Amaury Forgeot d'Arc4b6fdf32010-09-07 21:31:17 +00001216class PidTests(unittest.TestCase):
1217 @unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
1218 def test_getppid(self):
1219 p = subprocess.Popen([sys.executable, '-c',
1220 'import os; print(os.getppid())'],
1221 stdout=subprocess.PIPE)
1222 stdout, _ = p.communicate()
1223 # We are the parent of our subprocess
1224 self.assertEqual(int(stdout), os.getpid())
1225
1226
Brian Curtin0151b8e2010-09-24 13:43:43 +00001227# The introduction of this TestCase caused at least two different errors on
1228# *nix buildbots. Temporarily skip this to let the buildbots move along.
1229@unittest.skip("Skip due to platform/environment differences on *NIX buildbots")
Brian Curtine8e4b3b2010-09-23 20:04:14 +00001230@unittest.skipUnless(hasattr(os, 'getlogin'), "test needs os.getlogin")
1231class LoginTests(unittest.TestCase):
1232 def test_getlogin(self):
1233 user_name = os.getlogin()
1234 self.assertNotEqual(len(user_name), 0)
1235
1236
Fred Drake2e2be372001-09-20 21:33:42 +00001237def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +00001238 support.run_unittest(
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001239 FileTests,
Walter Dörwald21d3a322003-05-01 17:45:56 +00001240 StatAttributeTests,
1241 EnvironTests,
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +00001242 WalkTests,
1243 MakedirTests,
Martin v. Löwisbdec50f2004-06-08 08:29:33 +00001244 DevNullTests,
Thomas Wouters477c8d52006-05-27 19:21:47 +00001245 URandomTests,
Guido van Rossume7ba4952007-06-06 23:52:48 +00001246 ExecTests,
Benjamin Petersone1cdfd72009-01-18 21:02:37 +00001247 Win32ErrorTests,
Benjamin Petersonef3e4c22009-04-11 19:48:14 +00001248 TestInvalidFD,
Martin v. Löwis011e8422009-05-05 04:43:17 +00001249 PosixUidGidTests,
Brian Curtineb24d742010-04-12 17:16:38 +00001250 Pep383Tests,
Victor Stinnerbf9bcab2010-05-09 03:15:33 +00001251 Win32KillTests,
Brian Curtind40e6f72010-07-08 21:39:08 +00001252 Win32SymlinkTests,
Victor Stinnere8d51452010-08-19 01:05:19 +00001253 FSEncodingTests,
Amaury Forgeot d'Arc4b6fdf32010-09-07 21:31:17 +00001254 PidTests,
Brian Curtine8e4b3b2010-09-23 20:04:14 +00001255 LoginTests,
Brian Curtin1b9df392010-11-24 20:24:31 +00001256 LinkTests,
Walter Dörwald21d3a322003-05-01 17:45:56 +00001257 )
Fred Drake2e2be372001-09-20 21:33:42 +00001258
1259if __name__ == "__main__":
1260 test_main()