blob: eec1621301773a5df08da7b2f60a52d00d4eaf35 [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 Peterson1de05e92009-01-31 01:42:55 +00006import errno
Fred Drake38c2ef02001-07-17 20:52:51 +00007import unittest
Jeremy Hyltona7fc21b2001-08-20 20:10:01 +00008import warnings
Martin v. Löwis8e0d4942006-05-04 10:08:42 +00009import sys
Brian Curtine5aa8862010-04-02 23:26:06 +000010import signal
11import subprocess
12import time
Walter Dörwald21d3a322003-05-01 17:45:56 +000013from test import test_support
Hirokazu Yamamoto1f504f12010-10-08 09:41:13 +000014import mmap
15import uuid
Fred Drake38c2ef02001-07-17 20:52:51 +000016
Barry Warsaw60f01882001-08-22 19:24:42 +000017warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
18warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__)
19
Martin v. Löwisee1e06d2006-07-02 18:44:00 +000020# Tests creating TESTFN
21class FileTests(unittest.TestCase):
22 def setUp(self):
23 if os.path.exists(test_support.TESTFN):
24 os.unlink(test_support.TESTFN)
25 tearDown = setUp
26
27 def test_access(self):
28 f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
29 os.close(f)
Benjamin Peterson5c8da862009-06-30 22:57:08 +000030 self.assertTrue(os.access(test_support.TESTFN, os.W_OK))
Tim Peters16a39322006-07-03 08:23:19 +000031
Georg Brandl309501a2008-01-19 20:22:13 +000032 def test_closerange(self):
Antoine Pitroubebb18b2008-08-17 14:43:41 +000033 first = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
34 # We must allocate two consecutive file descriptors, otherwise
35 # it will mess up other file descriptors (perhaps even the three
36 # standard ones).
37 second = os.dup(first)
38 try:
39 retries = 0
40 while second != first + 1:
41 os.close(first)
42 retries += 1
43 if retries > 10:
44 # XXX test skipped
Benjamin Peterson757b3c92009-05-16 18:44:34 +000045 self.skipTest("couldn't allocate two consecutive fds")
Antoine Pitroubebb18b2008-08-17 14:43:41 +000046 first, second = second, os.dup(second)
47 finally:
48 os.close(second)
Georg Brandl309501a2008-01-19 20:22:13 +000049 # close a fd that is open, and one that isn't
Antoine Pitroubebb18b2008-08-17 14:43:41 +000050 os.closerange(first, first + 2)
51 self.assertRaises(OSError, os.write, first, "a")
Georg Brandl309501a2008-01-19 20:22:13 +000052
Benjamin Peterson10947a62010-06-30 17:11:08 +000053 @test_support.cpython_only
Hirokazu Yamamoto74ce88f2008-09-08 23:03:47 +000054 def test_rename(self):
55 path = unicode(test_support.TESTFN)
56 old = sys.getrefcount(path)
57 self.assertRaises(TypeError, os.rename, path, 0)
58 new = sys.getrefcount(path)
59 self.assertEqual(old, new)
60
Martin v. Löwisee1e06d2006-07-02 18:44:00 +000061
Fred Drake38c2ef02001-07-17 20:52:51 +000062class TemporaryFileTests(unittest.TestCase):
63 def setUp(self):
64 self.files = []
Walter Dörwald21d3a322003-05-01 17:45:56 +000065 os.mkdir(test_support.TESTFN)
Fred Drake38c2ef02001-07-17 20:52:51 +000066
67 def tearDown(self):
68 for name in self.files:
69 os.unlink(name)
Walter Dörwald21d3a322003-05-01 17:45:56 +000070 os.rmdir(test_support.TESTFN)
Fred Drake38c2ef02001-07-17 20:52:51 +000071
72 def check_tempfile(self, name):
73 # make sure it doesn't already exist:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000074 self.assertFalse(os.path.exists(name),
Fred Drake38c2ef02001-07-17 20:52:51 +000075 "file already exists for temporary file")
76 # make sure we can create the file
77 open(name, "w")
78 self.files.append(name)
79
80 def test_tempnam(self):
81 if not hasattr(os, "tempnam"):
82 return
Antoine Pitroub0614612011-01-02 20:04:52 +000083 with warnings.catch_warnings():
84 warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
85 r"test_os$")
86 warnings.filterwarnings("ignore", "tempnam", DeprecationWarning)
87 self.check_tempfile(os.tempnam())
Fred Drake38c2ef02001-07-17 20:52:51 +000088
Antoine Pitroub0614612011-01-02 20:04:52 +000089 name = os.tempnam(test_support.TESTFN)
90 self.check_tempfile(name)
Fred Drake38c2ef02001-07-17 20:52:51 +000091
Antoine Pitroub0614612011-01-02 20:04:52 +000092 name = os.tempnam(test_support.TESTFN, "pfx")
93 self.assertTrue(os.path.basename(name)[:3] == "pfx")
94 self.check_tempfile(name)
Fred Drake38c2ef02001-07-17 20:52:51 +000095
96 def test_tmpfile(self):
97 if not hasattr(os, "tmpfile"):
98 return
Martin v. Löwisd2bbe522008-03-06 06:55:22 +000099 # As with test_tmpnam() below, the Windows implementation of tmpfile()
100 # attempts to create a file in the root directory of the current drive.
101 # On Vista and Server 2008, this test will always fail for normal users
102 # as writing to the root directory requires elevated privileges. With
103 # XP and below, the semantics of tmpfile() are the same, but the user
104 # running the test is more likely to have administrative privileges on
105 # their account already. If that's the case, then os.tmpfile() should
106 # work. In order to make this test as useful as possible, rather than
107 # trying to detect Windows versions or whether or not the user has the
108 # right permissions, just try and create a file in the root directory
109 # and see if it raises a 'Permission denied' OSError. If it does, then
110 # test that a subsequent call to os.tmpfile() raises the same error. If
111 # it doesn't, assume we're on XP or below and the user running the test
112 # has administrative privileges, and proceed with the test as normal.
Antoine Pitroub0614612011-01-02 20:04:52 +0000113 with warnings.catch_warnings():
114 warnings.filterwarnings("ignore", "tmpfile", DeprecationWarning)
Martin v. Löwisd2bbe522008-03-06 06:55:22 +0000115
Antoine Pitroub0614612011-01-02 20:04:52 +0000116 if sys.platform == 'win32':
117 name = '\\python_test_os_test_tmpfile.txt'
118 if os.path.exists(name):
119 os.remove(name)
120 try:
121 fp = open(name, 'w')
122 except IOError, first:
123 # open() failed, assert tmpfile() fails in the same way.
124 # Although open() raises an IOError and os.tmpfile() raises an
125 # OSError(), 'args' will be (13, 'Permission denied') in both
126 # cases.
127 try:
128 fp = os.tmpfile()
129 except OSError, second:
130 self.assertEqual(first.args, second.args)
131 else:
132 self.fail("expected os.tmpfile() to raise OSError")
133 return
134 else:
135 # open() worked, therefore, tmpfile() should work. Close our
136 # dummy file and proceed with the test as normal.
137 fp.close()
138 os.remove(name)
139
140 fp = os.tmpfile()
141 fp.write("foobar")
142 fp.seek(0,0)
143 s = fp.read()
144 fp.close()
145 self.assertTrue(s == "foobar")
Fred Drake38c2ef02001-07-17 20:52:51 +0000146
147 def test_tmpnam(self):
148 if not hasattr(os, "tmpnam"):
149 return
Antoine Pitroub0614612011-01-02 20:04:52 +0000150 with warnings.catch_warnings():
151 warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
152 r"test_os$")
153 warnings.filterwarnings("ignore", "tmpnam", DeprecationWarning)
154
155 name = os.tmpnam()
156 if sys.platform in ("win32",):
157 # The Windows tmpnam() seems useless. From the MS docs:
158 #
159 # The character string that tmpnam creates consists of
160 # the path prefix, defined by the entry P_tmpdir in the
161 # file STDIO.H, followed by a sequence consisting of the
162 # digit characters '0' through '9'; the numerical value
163 # of this string is in the range 1 - 65,535. Changing the
164 # definitions of L_tmpnam or P_tmpdir in STDIO.H does not
165 # change the operation of tmpnam.
166 #
167 # The really bizarre part is that, at least under MSVC6,
168 # P_tmpdir is "\\". That is, the path returned refers to
169 # the root of the current drive. That's a terrible place to
170 # put temp files, and, depending on privileges, the user
171 # may not even be able to open a file in the root directory.
172 self.assertFalse(os.path.exists(name),
173 "file already exists for temporary file")
174 else:
175 self.check_tempfile(name)
Tim Peters87cc0c32001-07-21 01:41:30 +0000176
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000177# Test attributes on return values from os.*stat* family.
178class StatAttributeTests(unittest.TestCase):
179 def setUp(self):
Walter Dörwald21d3a322003-05-01 17:45:56 +0000180 os.mkdir(test_support.TESTFN)
181 self.fname = os.path.join(test_support.TESTFN, "f1")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000182 f = open(self.fname, 'wb')
183 f.write("ABC")
184 f.close()
Tim Peterse0c446b2001-10-18 21:57:37 +0000185
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000186 def tearDown(self):
187 os.unlink(self.fname)
Walter Dörwald21d3a322003-05-01 17:45:56 +0000188 os.rmdir(test_support.TESTFN)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000189
190 def test_stat_attributes(self):
191 if not hasattr(os, "stat"):
192 return
193
194 import stat
195 result = os.stat(self.fname)
196
197 # Make sure direct access works
Ezio Melotti2623a372010-11-21 13:34:58 +0000198 self.assertEqual(result[stat.ST_SIZE], 3)
199 self.assertEqual(result.st_size, 3)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000200
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000201 # Make sure all the attributes are there
202 members = dir(result)
203 for name in dir(stat):
204 if name[:3] == 'ST_':
205 attr = name.lower()
Martin v. Löwis4d394df2005-01-23 09:19:22 +0000206 if name.endswith("TIME"):
207 def trunc(x): return int(x)
208 else:
209 def trunc(x): return x
Ezio Melotti2623a372010-11-21 13:34:58 +0000210 self.assertEqual(trunc(getattr(result, attr)),
211 result[getattr(stat, name)])
Ezio Melottiaa980582010-01-23 23:04:36 +0000212 self.assertIn(attr, members)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000213
214 try:
215 result[200]
216 self.fail("No exception thrown")
217 except IndexError:
218 pass
219
220 # Make sure that assignment fails
221 try:
222 result.st_mode = 1
223 self.fail("No exception thrown")
Benjamin Petersonc262a692010-06-30 18:41:08 +0000224 except (AttributeError, TypeError):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000225 pass
226
227 try:
228 result.st_rdev = 1
229 self.fail("No exception thrown")
Guido van Rossum1fff8782001-10-18 21:19:31 +0000230 except (AttributeError, TypeError):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000231 pass
232
233 try:
234 result.parrot = 1
235 self.fail("No exception thrown")
236 except AttributeError:
237 pass
238
239 # Use the stat_result constructor with a too-short tuple.
240 try:
241 result2 = os.stat_result((10,))
242 self.fail("No exception thrown")
243 except TypeError:
244 pass
245
Ezio Melotti24b07bc2011-03-15 18:55:01 +0200246 # Use the constructor with a too-long tuple.
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000247 try:
248 result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
249 except TypeError:
250 pass
251
Tim Peterse0c446b2001-10-18 21:57:37 +0000252
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000253 def test_statvfs_attributes(self):
254 if not hasattr(os, "statvfs"):
255 return
256
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000257 try:
258 result = os.statvfs(self.fname)
259 except OSError, e:
260 # On AtheOS, glibc always returns ENOSYS
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000261 if e.errno == errno.ENOSYS:
262 return
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000263
264 # Make sure direct access works
Ezio Melotti2623a372010-11-21 13:34:58 +0000265 self.assertEqual(result.f_bfree, result[3])
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000266
Brett Cannon90f2cb42008-05-16 00:37:42 +0000267 # Make sure all the attributes are there.
268 members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files',
269 'ffree', 'favail', 'flag', 'namemax')
270 for value, member in enumerate(members):
Ezio Melotti2623a372010-11-21 13:34:58 +0000271 self.assertEqual(getattr(result, 'f_' + member), result[value])
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000272
273 # Make sure that assignment really fails
274 try:
275 result.f_bfree = 1
276 self.fail("No exception thrown")
277 except TypeError:
278 pass
279
280 try:
281 result.parrot = 1
282 self.fail("No exception thrown")
283 except AttributeError:
284 pass
285
286 # Use the constructor with a too-short tuple.
287 try:
288 result2 = os.statvfs_result((10,))
289 self.fail("No exception thrown")
290 except TypeError:
291 pass
292
Ezio Melotti24b07bc2011-03-15 18:55:01 +0200293 # Use the constructor with a too-long tuple.
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000294 try:
295 result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
296 except TypeError:
297 pass
Fred Drake38c2ef02001-07-17 20:52:51 +0000298
Martin v. Löwis18aaa562006-10-15 08:43:33 +0000299 def test_utime_dir(self):
300 delta = 1000000
301 st = os.stat(test_support.TESTFN)
Martin v. Löwisa97e06d2006-10-15 11:02:07 +0000302 # round to int, because some systems may support sub-second
303 # time stamps in stat, but not in utime.
304 os.utime(test_support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
Martin v. Löwis18aaa562006-10-15 08:43:33 +0000305 st2 = os.stat(test_support.TESTFN)
Ezio Melotti2623a372010-11-21 13:34:58 +0000306 self.assertEqual(st2.st_mtime, int(st.st_mtime-delta))
Martin v. Löwis18aaa562006-10-15 08:43:33 +0000307
Martin v. Löwisf43893a2006-10-09 20:44:25 +0000308 # Restrict test to Win32, since there is no guarantee other
309 # systems support centiseconds
310 if sys.platform == 'win32':
Martin v. Löwis7dcb83c2007-08-30 19:04:09 +0000311 def get_file_system(path):
Hirokazu Yamamotoccfdcd02008-08-20 04:13:28 +0000312 root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
Martin v. Löwis7dcb83c2007-08-30 19:04:09 +0000313 import ctypes
Hirokazu Yamamotocd3b74d2008-08-20 16:15:28 +0000314 kernel32 = ctypes.windll.kernel32
315 buf = ctypes.create_string_buffer("", 100)
316 if kernel32.GetVolumeInformationA(root, None, 0, None, None, None, buf, len(buf)):
Martin v. Löwis7dcb83c2007-08-30 19:04:09 +0000317 return buf.value
318
319 if get_file_system(test_support.TESTFN) == "NTFS":
320 def test_1565150(self):
321 t1 = 1159195039.25
322 os.utime(self.fname, (t1, t1))
Ezio Melotti2623a372010-11-21 13:34:58 +0000323 self.assertEqual(os.stat(self.fname).st_mtime, t1)
Martin v. Löwisf43893a2006-10-09 20:44:25 +0000324
Amaury Forgeot d'Arcac514c82011-01-03 00:50:57 +0000325 def test_large_time(self):
326 t1 = 5000000000 # some day in 2128
327 os.utime(self.fname, (t1, t1))
328 self.assertEqual(os.stat(self.fname).st_mtime, t1)
329
Martin v. Löwis3bf573f2007-04-04 18:30:36 +0000330 def test_1686475(self):
331 # Verify that an open file can be stat'ed
332 try:
333 os.stat(r"c:\pagefile.sys")
334 except WindowsError, e:
Antoine Pitrou954ea642008-08-17 20:15:07 +0000335 if e.errno == 2: # file does not exist; cannot run test
Martin v. Löwis3bf573f2007-04-04 18:30:36 +0000336 return
337 self.fail("Could not stat pagefile.sys")
338
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000339from test import mapping_tests
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000340
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000341class EnvironTests(mapping_tests.BasicTestMappingProtocol):
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000342 """check that os.environ object conform to mapping protocol"""
Walter Dörwald118f9312004-06-02 18:42:25 +0000343 type2test = None
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000344 def _reference(self):
345 return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
346 def _empty_mapping(self):
347 os.environ.clear()
348 return os.environ
349 def setUp(self):
350 self.__save = dict(os.environ)
351 os.environ.clear()
352 def tearDown(self):
353 os.environ.clear()
354 os.environ.update(self.__save)
355
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000356 # Bug 1110478
Martin v. Löwis5510f652005-02-17 21:23:20 +0000357 def test_update2(self):
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000358 if os.path.exists("/bin/sh"):
359 os.environ.update(HELLO="World")
Brian Curtinfcbf5d02010-10-30 21:29:52 +0000360 with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
361 value = popen.read().strip()
Ezio Melotti2623a372010-11-21 13:34:58 +0000362 self.assertEqual(value, "World")
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000363
Charles-François Natali27bc4d02011-11-27 13:05:14 +0100364 # On FreeBSD < 7 and OS X < 10.6, unsetenv() doesn't return a value (issue
365 # #13415).
366 @unittest.skipIf(sys.platform.startswith(('freebsd', 'darwin')),
367 "due to known OS bug: see issue #13415")
Victor Stinner53853c32011-11-22 22:20:13 +0100368 def test_unset_error(self):
369 if sys.platform == "win32":
370 # an environment variable is limited to 32,767 characters
371 key = 'x' * 50000
Victor Stinner091b6ef2011-11-22 22:30:19 +0100372 self.assertRaises(ValueError, os.environ.__delitem__, key)
Victor Stinner53853c32011-11-22 22:20:13 +0100373 else:
374 # "=" is not allowed in a variable name
375 key = 'key='
Victor Stinner091b6ef2011-11-22 22:30:19 +0100376 self.assertRaises(OSError, os.environ.__delitem__, key)
Victor Stinner53853c32011-11-22 22:20:13 +0100377
Tim Petersc4e09402003-04-25 07:11:48 +0000378class WalkTests(unittest.TestCase):
379 """Tests for os.walk()."""
380
381 def test_traversal(self):
382 import os
383 from os.path import join
384
385 # Build:
Neal Norwitz0d4c06e2007-04-25 06:30:05 +0000386 # TESTFN/
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000387 # TEST1/ a file kid and two directory kids
Tim Petersc4e09402003-04-25 07:11:48 +0000388 # tmp1
389 # SUB1/ a file kid and a directory kid
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000390 # tmp2
391 # SUB11/ no kids
392 # SUB2/ a file kid and a dirsymlink kid
393 # tmp3
394 # link/ a symlink to TESTFN.2
395 # TEST2/
396 # tmp4 a lone file
397 walk_path = join(test_support.TESTFN, "TEST1")
398 sub1_path = join(walk_path, "SUB1")
Tim Petersc4e09402003-04-25 07:11:48 +0000399 sub11_path = join(sub1_path, "SUB11")
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000400 sub2_path = join(walk_path, "SUB2")
401 tmp1_path = join(walk_path, "tmp1")
Tim Petersc4e09402003-04-25 07:11:48 +0000402 tmp2_path = join(sub1_path, "tmp2")
403 tmp3_path = join(sub2_path, "tmp3")
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000404 link_path = join(sub2_path, "link")
405 t2_path = join(test_support.TESTFN, "TEST2")
406 tmp4_path = join(test_support.TESTFN, "TEST2", "tmp4")
Tim Petersc4e09402003-04-25 07:11:48 +0000407
408 # Create stuff.
409 os.makedirs(sub11_path)
410 os.makedirs(sub2_path)
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000411 os.makedirs(t2_path)
412 for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
Tim Petersc4e09402003-04-25 07:11:48 +0000413 f = file(path, "w")
414 f.write("I'm " + path + " and proud of it. Blame test_os.\n")
415 f.close()
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000416 if hasattr(os, "symlink"):
417 os.symlink(os.path.abspath(t2_path), link_path)
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000418 sub2_tree = (sub2_path, ["link"], ["tmp3"])
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000419 else:
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000420 sub2_tree = (sub2_path, [], ["tmp3"])
Tim Petersc4e09402003-04-25 07:11:48 +0000421
422 # Walk top-down.
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000423 all = list(os.walk(walk_path))
Tim Petersc4e09402003-04-25 07:11:48 +0000424 self.assertEqual(len(all), 4)
425 # We can't know which order SUB1 and SUB2 will appear in.
426 # Not flipped: TESTFN, SUB1, SUB11, SUB2
427 # flipped: TESTFN, SUB2, SUB1, SUB11
428 flipped = all[0][1][0] != "SUB1"
429 all[0][1].sort()
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000430 self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000431 self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
432 self.assertEqual(all[2 + flipped], (sub11_path, [], []))
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000433 self.assertEqual(all[3 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000434
435 # Prune the search.
436 all = []
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000437 for root, dirs, files in os.walk(walk_path):
Tim Petersc4e09402003-04-25 07:11:48 +0000438 all.append((root, dirs, files))
439 # Don't descend into SUB1.
440 if 'SUB1' in dirs:
441 # Note that this also mutates the dirs we appended to all!
442 dirs.remove('SUB1')
443 self.assertEqual(len(all), 2)
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000444 self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"]))
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000445 self.assertEqual(all[1], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000446
447 # Walk bottom-up.
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000448 all = list(os.walk(walk_path, topdown=False))
Tim Petersc4e09402003-04-25 07:11:48 +0000449 self.assertEqual(len(all), 4)
450 # We can't know which order SUB1 and SUB2 will appear in.
451 # Not flipped: SUB11, SUB1, SUB2, TESTFN
452 # flipped: SUB2, SUB11, SUB1, TESTFN
453 flipped = all[3][1][0] != "SUB1"
454 all[3][1].sort()
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000455 self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000456 self.assertEqual(all[flipped], (sub11_path, [], []))
457 self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000458 self.assertEqual(all[2 - 2 * flipped], sub2_tree)
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000459
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000460 if hasattr(os, "symlink"):
461 # Walk, following symlinks.
462 for root, dirs, files in os.walk(walk_path, followlinks=True):
463 if root == link_path:
464 self.assertEqual(dirs, [])
465 self.assertEqual(files, ["tmp4"])
466 break
467 else:
468 self.fail("Didn't follow symlink with followlinks=True")
Tim Petersc4e09402003-04-25 07:11:48 +0000469
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000470 def tearDown(self):
Tim Petersc4e09402003-04-25 07:11:48 +0000471 # Tear everything down. This is a decent use for bottom-up on
472 # Windows, which doesn't have a recursive delete command. The
473 # (not so) subtlety is that rmdir will fail unless the dir's
474 # kids are removed first, so bottom up is essential.
Walter Dörwald21d3a322003-05-01 17:45:56 +0000475 for root, dirs, files in os.walk(test_support.TESTFN, topdown=False):
Tim Petersc4e09402003-04-25 07:11:48 +0000476 for name in files:
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000477 os.remove(os.path.join(root, name))
Tim Petersc4e09402003-04-25 07:11:48 +0000478 for name in dirs:
Žiga Seilnacht18ffe422007-04-04 18:38:47 +0000479 dirname = os.path.join(root, name)
Georg Brandlcae9f3d2007-03-21 09:10:29 +0000480 if not os.path.islink(dirname):
481 os.rmdir(dirname)
482 else:
483 os.remove(dirname)
Walter Dörwald21d3a322003-05-01 17:45:56 +0000484 os.rmdir(test_support.TESTFN)
Tim Petersc4e09402003-04-25 07:11:48 +0000485
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000486class MakedirTests (unittest.TestCase):
487 def setUp(self):
488 os.mkdir(test_support.TESTFN)
489
490 def test_makedir(self):
491 base = test_support.TESTFN
492 path = os.path.join(base, 'dir1', 'dir2', 'dir3')
493 os.makedirs(path) # Should work
494 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
495 os.makedirs(path)
496
497 # Try paths with a '.' in them
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000498 self.assertRaises(OSError, os.makedirs, os.curdir)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000499 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
500 os.makedirs(path)
501 path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
502 'dir5', 'dir6')
503 os.makedirs(path)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000504
Tim Peters58eb11c2004-01-18 20:29:55 +0000505
506
507
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000508 def tearDown(self):
509 path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
510 'dir4', 'dir5', 'dir6')
511 # If the tests failed, the bottom-most directory ('../dir6')
512 # may not have been created, so we look for the outermost directory
513 # that exists.
514 while not os.path.exists(path) and path != test_support.TESTFN:
515 path = os.path.dirname(path)
516
517 os.removedirs(path)
518
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000519class DevNullTests (unittest.TestCase):
520 def test_devnull(self):
521 f = file(os.devnull, 'w')
522 f.write('hello')
523 f.close()
524 f = file(os.devnull, 'r')
Tim Peters4182cfd2004-06-08 20:34:34 +0000525 self.assertEqual(f.read(), '')
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000526 f.close()
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000527
Martin v. Löwisdc3883f2004-08-29 15:46:35 +0000528class URandomTests (unittest.TestCase):
529 def test_urandom(self):
530 try:
531 self.assertEqual(len(os.urandom(1)), 1)
532 self.assertEqual(len(os.urandom(10)), 10)
533 self.assertEqual(len(os.urandom(100)), 100)
534 self.assertEqual(len(os.urandom(1000)), 1000)
Gregory P. Smithd7122032008-09-02 05:36:11 +0000535 # see http://bugs.python.org/issue3708
Mark Dickinson1b34d252010-01-01 17:27:30 +0000536 self.assertRaises(TypeError, os.urandom, 0.9)
537 self.assertRaises(TypeError, os.urandom, 1.1)
538 self.assertRaises(TypeError, os.urandom, 2.0)
Martin v. Löwisdc3883f2004-08-29 15:46:35 +0000539 except NotImplementedError:
540 pass
541
Matthias Klosee9fbf2b2010-03-19 14:45:06 +0000542 def test_execvpe_with_bad_arglist(self):
543 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
544
Martin v. Löwis8e0d4942006-05-04 10:08:42 +0000545class Win32ErrorTests(unittest.TestCase):
546 def test_rename(self):
547 self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak")
548
549 def test_remove(self):
550 self.assertRaises(WindowsError, os.remove, test_support.TESTFN)
551
552 def test_chdir(self):
553 self.assertRaises(WindowsError, os.chdir, test_support.TESTFN)
554
Martin v. Löwisd4e3bb32006-05-06 16:32:54 +0000555 def test_mkdir(self):
Kristján Valur Jónssone20f54f2009-02-06 10:17:34 +0000556 f = open(test_support.TESTFN, "w")
557 try:
558 self.assertRaises(WindowsError, os.mkdir, test_support.TESTFN)
559 finally:
560 f.close()
561 os.unlink(test_support.TESTFN)
Martin v. Löwisd4e3bb32006-05-06 16:32:54 +0000562
563 def test_utime(self):
564 self.assertRaises(WindowsError, os.utime, test_support.TESTFN, None)
565
Martin v. Löwisd4e3bb32006-05-06 16:32:54 +0000566 def test_chmod(self):
Kristján Valur Jónssone20f54f2009-02-06 10:17:34 +0000567 self.assertRaises(WindowsError, os.chmod, test_support.TESTFN, 0)
Martin v. Löwisd4e3bb32006-05-06 16:32:54 +0000568
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000569class TestInvalidFD(unittest.TestCase):
Kristján Valur Jónsson71ba2152009-01-15 22:40:03 +0000570 singles = ["fchdir", "fdopen", "dup", "fdatasync", "fstat",
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000571 "fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
Kristján Valur Jónsson71ba2152009-01-15 22:40:03 +0000572 #singles.append("close")
573 #We omit close because it doesn'r raise an exception on some platforms
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000574 def get_single(f):
575 def helper(self):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000576 if hasattr(os, f):
577 self.check(getattr(os, f))
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000578 return helper
579 for f in singles:
580 locals()["test_"+f] = get_single(f)
581
Benjamin Peterson5539c782009-01-19 17:37:42 +0000582 def check(self, f, *args):
Benjamin Peterson1de05e92009-01-31 01:42:55 +0000583 try:
584 f(test_support.make_bad_fd(), *args)
585 except OSError as e:
586 self.assertEqual(e.errno, errno.EBADF)
587 else:
588 self.fail("%r didn't raise a OSError with a bad file descriptor"
589 % f)
Benjamin Peterson5539c782009-01-19 17:37:42 +0000590
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000591 def test_isatty(self):
Kristján Valur Jónsson4f69b7e2009-01-15 22:46:26 +0000592 if hasattr(os, "isatty"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000593 self.assertEqual(os.isatty(test_support.make_bad_fd()), False)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000594
595 def test_closerange(self):
Kristján Valur Jónsson4f69b7e2009-01-15 22:46:26 +0000596 if hasattr(os, "closerange"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000597 fd = test_support.make_bad_fd()
R. David Murray46ca2f22009-07-22 17:22:58 +0000598 # Make sure none of the descriptors we are about to close are
599 # currently valid (issue 6542).
600 for i in range(10):
601 try: os.fstat(fd+i)
602 except OSError:
603 pass
604 else:
605 break
606 if i < 2:
607 raise unittest.SkipTest(
608 "Unable to acquire a range of invalid file descriptors")
609 self.assertEqual(os.closerange(fd, fd + i-1), None)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000610
611 def test_dup2(self):
Kristján Valur Jónsson4f69b7e2009-01-15 22:46:26 +0000612 if hasattr(os, "dup2"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000613 self.check(os.dup2, 20)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000614
615 def test_fchmod(self):
616 if hasattr(os, "fchmod"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000617 self.check(os.fchmod, 0)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000618
619 def test_fchown(self):
620 if hasattr(os, "fchown"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000621 self.check(os.fchown, -1, -1)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000622
623 def test_fpathconf(self):
624 if hasattr(os, "fpathconf"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000625 self.check(os.fpathconf, "PC_NAME_MAX")
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000626
627 def test_ftruncate(self):
628 if hasattr(os, "ftruncate"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000629 self.check(os.ftruncate, 0)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000630
631 def test_lseek(self):
Kristján Valur Jónsson4f69b7e2009-01-15 22:46:26 +0000632 if hasattr(os, "lseek"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000633 self.check(os.lseek, 0, 0)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000634
635 def test_read(self):
Kristján Valur Jónsson4f69b7e2009-01-15 22:46:26 +0000636 if hasattr(os, "read"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000637 self.check(os.read, 1)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000638
639 def test_tcsetpgrpt(self):
640 if hasattr(os, "tcsetpgrp"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000641 self.check(os.tcsetpgrp, 0)
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000642
643 def test_write(self):
Kristján Valur Jónsson4f69b7e2009-01-15 22:46:26 +0000644 if hasattr(os, "write"):
Benjamin Peterson5539c782009-01-19 17:37:42 +0000645 self.check(os.write, " ")
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000646
Martin v. Löwis8e0d4942006-05-04 10:08:42 +0000647if sys.platform != 'win32':
648 class Win32ErrorTests(unittest.TestCase):
649 pass
650
Gregory P. Smith6d307932009-04-05 23:43:58 +0000651 class PosixUidGidTests(unittest.TestCase):
652 if hasattr(os, 'setuid'):
653 def test_setuid(self):
654 if os.getuid() != 0:
655 self.assertRaises(os.error, os.setuid, 0)
656 self.assertRaises(OverflowError, os.setuid, 1<<32)
657
658 if hasattr(os, 'setgid'):
659 def test_setgid(self):
660 if os.getuid() != 0:
661 self.assertRaises(os.error, os.setgid, 0)
662 self.assertRaises(OverflowError, os.setgid, 1<<32)
663
664 if hasattr(os, 'seteuid'):
665 def test_seteuid(self):
666 if os.getuid() != 0:
667 self.assertRaises(os.error, os.seteuid, 0)
668 self.assertRaises(OverflowError, os.seteuid, 1<<32)
669
670 if hasattr(os, 'setegid'):
671 def test_setegid(self):
672 if os.getuid() != 0:
673 self.assertRaises(os.error, os.setegid, 0)
674 self.assertRaises(OverflowError, os.setegid, 1<<32)
675
676 if hasattr(os, 'setreuid'):
677 def test_setreuid(self):
678 if os.getuid() != 0:
679 self.assertRaises(os.error, os.setreuid, 0, 0)
680 self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
681 self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
Gregory P. Smith467298c2010-03-06 07:35:19 +0000682
683 def test_setreuid_neg1(self):
684 # Needs to accept -1. We run this in a subprocess to avoid
685 # altering the test runner's process state (issue8045).
Gregory P. Smith467298c2010-03-06 07:35:19 +0000686 subprocess.check_call([
687 sys.executable, '-c',
688 'import os,sys;os.setreuid(-1,-1);sys.exit(0)'])
Gregory P. Smith6d307932009-04-05 23:43:58 +0000689
690 if hasattr(os, 'setregid'):
691 def test_setregid(self):
692 if os.getuid() != 0:
693 self.assertRaises(os.error, os.setregid, 0, 0)
694 self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
695 self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
Gregory P. Smith467298c2010-03-06 07:35:19 +0000696
697 def test_setregid_neg1(self):
698 # Needs to accept -1. We run this in a subprocess to avoid
699 # altering the test runner's process state (issue8045).
Gregory P. Smith467298c2010-03-06 07:35:19 +0000700 subprocess.check_call([
701 sys.executable, '-c',
702 'import os,sys;os.setregid(-1,-1);sys.exit(0)'])
Gregory P. Smith6d307932009-04-05 23:43:58 +0000703else:
704 class PosixUidGidTests(unittest.TestCase):
705 pass
706
Brian Curtine5aa8862010-04-02 23:26:06 +0000707@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
708class Win32KillTests(unittest.TestCase):
Brian Curtinb3dde132010-04-15 00:40:40 +0000709 def _kill(self, sig):
710 # Start sys.executable as a subprocess and communicate from the
711 # subprocess to the parent that the interpreter is ready. When it
712 # becomes ready, send *sig* via os.kill to the subprocess and check
713 # that the return code is equal to *sig*.
714 import ctypes
715 from ctypes import wintypes
716 import msvcrt
717
718 # Since we can't access the contents of the process' stdout until the
719 # process has exited, use PeekNamedPipe to see what's inside stdout
720 # without waiting. This is done so we can tell that the interpreter
721 # is started and running at a point where it could handle a signal.
722 PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe
723 PeekNamedPipe.restype = wintypes.BOOL
724 PeekNamedPipe.argtypes = (wintypes.HANDLE, # Pipe handle
725 ctypes.POINTER(ctypes.c_char), # stdout buf
726 wintypes.DWORD, # Buffer size
727 ctypes.POINTER(wintypes.DWORD), # bytes read
728 ctypes.POINTER(wintypes.DWORD), # bytes avail
729 ctypes.POINTER(wintypes.DWORD)) # bytes left
730 msg = "running"
731 proc = subprocess.Popen([sys.executable, "-c",
732 "import sys;"
733 "sys.stdout.write('{}');"
734 "sys.stdout.flush();"
735 "input()".format(msg)],
736 stdout=subprocess.PIPE,
737 stderr=subprocess.PIPE,
738 stdin=subprocess.PIPE)
Brian Curtinf4f0c8b2010-11-05 15:31:20 +0000739 self.addCleanup(proc.stdout.close)
740 self.addCleanup(proc.stderr.close)
741 self.addCleanup(proc.stdin.close)
Brian Curtinb3dde132010-04-15 00:40:40 +0000742
Brian Curtin83cba052010-05-28 15:49:21 +0000743 count, max = 0, 100
744 while count < max and proc.poll() is None:
745 # Create a string buffer to store the result of stdout from the pipe
746 buf = ctypes.create_string_buffer(len(msg))
747 # Obtain the text currently in proc.stdout
748 # Bytes read/avail/left are left as NULL and unused
749 rslt = PeekNamedPipe(msvcrt.get_osfhandle(proc.stdout.fileno()),
750 buf, ctypes.sizeof(buf), None, None, None)
751 self.assertNotEqual(rslt, 0, "PeekNamedPipe failed")
752 if buf.value:
753 self.assertEqual(msg, buf.value)
754 break
755 time.sleep(0.1)
756 count += 1
757 else:
758 self.fail("Did not receive communication from the subprocess")
Brian Curtinb3dde132010-04-15 00:40:40 +0000759
Brian Curtine5aa8862010-04-02 23:26:06 +0000760 os.kill(proc.pid, sig)
761 self.assertEqual(proc.wait(), sig)
762
763 def test_kill_sigterm(self):
764 # SIGTERM doesn't mean anything special, but make sure it works
Brian Curtinb3dde132010-04-15 00:40:40 +0000765 self._kill(signal.SIGTERM)
Brian Curtine5aa8862010-04-02 23:26:06 +0000766
767 def test_kill_int(self):
768 # os.kill on Windows can take an int which gets set as the exit code
Brian Curtinb3dde132010-04-15 00:40:40 +0000769 self._kill(100)
Brian Curtine5aa8862010-04-02 23:26:06 +0000770
771 def _kill_with_event(self, event, name):
Hirokazu Yamamoto1f504f12010-10-08 09:41:13 +0000772 tagname = "test_os_%s" % uuid.uuid1()
773 m = mmap.mmap(-1, 1, tagname)
774 m[0] = '0'
Brian Curtine5aa8862010-04-02 23:26:06 +0000775 # Run a script which has console control handling enabled.
776 proc = subprocess.Popen([sys.executable,
777 os.path.join(os.path.dirname(__file__),
Hirokazu Yamamoto1f504f12010-10-08 09:41:13 +0000778 "win_console_handler.py"), tagname],
Brian Curtine5aa8862010-04-02 23:26:06 +0000779 creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
780 # Let the interpreter startup before we send signals. See #3137.
Hirokazu Yamamoto1f504f12010-10-08 09:41:13 +0000781 count, max = 0, 20
782 while count < max and proc.poll() is None:
Brian Curtindbf8e832010-11-05 15:28:19 +0000783 if m[0] == '1':
Hirokazu Yamamoto1f504f12010-10-08 09:41:13 +0000784 break
785 time.sleep(0.5)
786 count += 1
787 else:
788 self.fail("Subprocess didn't finish initialization")
Brian Curtine5aa8862010-04-02 23:26:06 +0000789 os.kill(proc.pid, event)
790 # proc.send_signal(event) could also be done here.
791 # Allow time for the signal to be passed and the process to exit.
Brian Curtinfce1d312010-04-05 19:04:23 +0000792 time.sleep(0.5)
Brian Curtine5aa8862010-04-02 23:26:06 +0000793 if not proc.poll():
794 # Forcefully kill the process if we weren't able to signal it.
795 os.kill(proc.pid, signal.SIGINT)
796 self.fail("subprocess did not stop on {}".format(name))
797
798 @unittest.skip("subprocesses aren't inheriting CTRL+C property")
799 def test_CTRL_C_EVENT(self):
800 from ctypes import wintypes
801 import ctypes
802
803 # Make a NULL value by creating a pointer with no argument.
804 NULL = ctypes.POINTER(ctypes.c_int)()
805 SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
806 SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
807 wintypes.BOOL)
808 SetConsoleCtrlHandler.restype = wintypes.BOOL
809
810 # Calling this with NULL and FALSE causes the calling process to
811 # handle CTRL+C, rather than ignore it. This property is inherited
812 # by subprocesses.
813 SetConsoleCtrlHandler(NULL, 0)
814
815 self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
816
817 def test_CTRL_BREAK_EVENT(self):
818 self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT")
819
820
Fred Drake2e2be372001-09-20 21:33:42 +0000821def test_main():
Walter Dörwald21d3a322003-05-01 17:45:56 +0000822 test_support.run_unittest(
Martin v. Löwisee1e06d2006-07-02 18:44:00 +0000823 FileTests,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000824 TemporaryFileTests,
825 StatAttributeTests,
826 EnvironTests,
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000827 WalkTests,
828 MakedirTests,
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000829 DevNullTests,
Martin v. Löwis8e0d4942006-05-04 10:08:42 +0000830 URandomTests,
Kristján Valur Jónsson1c62b652009-01-12 18:09:27 +0000831 Win32ErrorTests,
Gregory P. Smith6d307932009-04-05 23:43:58 +0000832 TestInvalidFD,
Brian Curtine5aa8862010-04-02 23:26:06 +0000833 PosixUidGidTests,
834 Win32KillTests
Walter Dörwald21d3a322003-05-01 17:45:56 +0000835 )
Fred Drake2e2be372001-09-20 21:33:42 +0000836
837if __name__ == "__main__":
838 test_main()