blob: 05932f52509639cda2e142ee6a2fa74764a90287 [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
6import unittest
Jeremy Hyltona7fc21b2001-08-20 20:10:01 +00007import warnings
Thomas Wouters477c8d52006-05-27 19:21:47 +00008import sys
Walter Dörwald21d3a322003-05-01 17:45:56 +00009from test import test_support
Fred Drake38c2ef02001-07-17 20:52:51 +000010
Barry Warsaw60f01882001-08-22 19:24:42 +000011warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
12warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__)
13
Thomas Wouters0e3f5912006-08-11 14:57:12 +000014# Tests creating TESTFN
15class FileTests(unittest.TestCase):
16 def setUp(self):
17 if os.path.exists(test_support.TESTFN):
18 os.unlink(test_support.TESTFN)
19 tearDown = setUp
20
21 def test_access(self):
22 f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
23 os.close(f)
24 self.assert_(os.access(test_support.TESTFN, os.W_OK))
25
26
Fred Drake38c2ef02001-07-17 20:52:51 +000027class TemporaryFileTests(unittest.TestCase):
28 def setUp(self):
29 self.files = []
Walter Dörwald21d3a322003-05-01 17:45:56 +000030 os.mkdir(test_support.TESTFN)
Fred Drake38c2ef02001-07-17 20:52:51 +000031
32 def tearDown(self):
33 for name in self.files:
34 os.unlink(name)
Walter Dörwald21d3a322003-05-01 17:45:56 +000035 os.rmdir(test_support.TESTFN)
Fred Drake38c2ef02001-07-17 20:52:51 +000036
37 def check_tempfile(self, name):
38 # make sure it doesn't already exist:
39 self.failIf(os.path.exists(name),
40 "file already exists for temporary file")
41 # make sure we can create the file
42 open(name, "w")
43 self.files.append(name)
44
45 def test_tempnam(self):
46 if not hasattr(os, "tempnam"):
47 return
Jeremy Hyltona7fc21b2001-08-20 20:10:01 +000048 warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
Tim Petersd3925062002-04-16 01:27:44 +000049 r"test_os$")
Fred Drake38c2ef02001-07-17 20:52:51 +000050 self.check_tempfile(os.tempnam())
51
Walter Dörwald21d3a322003-05-01 17:45:56 +000052 name = os.tempnam(test_support.TESTFN)
Fred Drake38c2ef02001-07-17 20:52:51 +000053 self.check_tempfile(name)
54
Walter Dörwald21d3a322003-05-01 17:45:56 +000055 name = os.tempnam(test_support.TESTFN, "pfx")
Guido van Rossume61fd5b2007-07-11 12:20:59 +000056 self.assertEqual(os.path.basename(name)[:3], "pfx")
Fred Drake38c2ef02001-07-17 20:52:51 +000057 self.check_tempfile(name)
58
59 def test_tmpfile(self):
60 if not hasattr(os, "tmpfile"):
61 return
62 fp = os.tmpfile()
Guido van Rossum26d95c32007-08-27 23:18:54 +000063 fp.write(b"foobar")
Guido van Rossumff0ffb32007-06-13 01:55:50 +000064 fp.seek(0)
Fred Drake38c2ef02001-07-17 20:52:51 +000065 s = fp.read()
66 fp.close()
Guido van Rossumff0ffb32007-06-13 01:55:50 +000067 self.assertEquals(s, b"foobar")
Fred Drake38c2ef02001-07-17 20:52:51 +000068
69 def test_tmpnam(self):
Tim Peters5501b5e2003-04-28 03:13:03 +000070 import sys
Fred Drake38c2ef02001-07-17 20:52:51 +000071 if not hasattr(os, "tmpnam"):
72 return
Jeremy Hyltona7fc21b2001-08-20 20:10:01 +000073 warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
Tim Petersd3925062002-04-16 01:27:44 +000074 r"test_os$")
Tim Peters5501b5e2003-04-28 03:13:03 +000075 name = os.tmpnam()
76 if sys.platform in ("win32",):
77 # The Windows tmpnam() seems useless. From the MS docs:
78 #
79 # The character string that tmpnam creates consists of
80 # the path prefix, defined by the entry P_tmpdir in the
81 # file STDIO.H, followed by a sequence consisting of the
82 # digit characters '0' through '9'; the numerical value
83 # of this string is in the range 1 - 65,535. Changing the
84 # definitions of L_tmpnam or P_tmpdir in STDIO.H does not
85 # change the operation of tmpnam.
86 #
87 # The really bizarre part is that, at least under MSVC6,
88 # P_tmpdir is "\\". That is, the path returned refers to
89 # the root of the current drive. That's a terrible place to
90 # put temp files, and, depending on privileges, the user
91 # may not even be able to open a file in the root directory.
92 self.failIf(os.path.exists(name),
93 "file already exists for temporary file")
94 else:
95 self.check_tempfile(name)
Tim Peters87cc0c32001-07-21 01:41:30 +000096
Guido van Rossum98bf58f2001-10-18 20:34:25 +000097# Test attributes on return values from os.*stat* family.
98class StatAttributeTests(unittest.TestCase):
99 def setUp(self):
Walter Dörwald21d3a322003-05-01 17:45:56 +0000100 os.mkdir(test_support.TESTFN)
101 self.fname = os.path.join(test_support.TESTFN, "f1")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000102 f = open(self.fname, 'wb')
Guido van Rossum26d95c32007-08-27 23:18:54 +0000103 f.write(b"ABC")
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000104 f.close()
Tim Peterse0c446b2001-10-18 21:57:37 +0000105
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000106 def tearDown(self):
107 os.unlink(self.fname)
Walter Dörwald21d3a322003-05-01 17:45:56 +0000108 os.rmdir(test_support.TESTFN)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000109
110 def test_stat_attributes(self):
111 if not hasattr(os, "stat"):
112 return
113
114 import stat
115 result = os.stat(self.fname)
116
117 # Make sure direct access works
118 self.assertEquals(result[stat.ST_SIZE], 3)
119 self.assertEquals(result.st_size, 3)
120
121 import sys
122
123 # Make sure all the attributes are there
124 members = dir(result)
125 for name in dir(stat):
126 if name[:3] == 'ST_':
127 attr = name.lower()
Martin v. Löwis4d394df2005-01-23 09:19:22 +0000128 if name.endswith("TIME"):
129 def trunc(x): return int(x)
130 else:
131 def trunc(x): return x
132 self.assertEquals(trunc(getattr(result, attr)),
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000133 result[getattr(stat, name)])
134 self.assert_(attr in members)
135
136 try:
137 result[200]
138 self.fail("No exception thrown")
139 except IndexError:
140 pass
141
142 # Make sure that assignment fails
143 try:
144 result.st_mode = 1
145 self.fail("No exception thrown")
Collin Winter42dae6a2007-03-28 21:44:53 +0000146 except AttributeError:
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000147 pass
148
149 try:
150 result.st_rdev = 1
151 self.fail("No exception thrown")
Guido van Rossum1fff8782001-10-18 21:19:31 +0000152 except (AttributeError, TypeError):
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000153 pass
154
155 try:
156 result.parrot = 1
157 self.fail("No exception thrown")
158 except AttributeError:
159 pass
160
161 # Use the stat_result constructor with a too-short tuple.
162 try:
163 result2 = os.stat_result((10,))
164 self.fail("No exception thrown")
165 except TypeError:
166 pass
167
168 # Use the constructr with a too-long tuple.
169 try:
170 result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
171 except TypeError:
172 pass
173
Tim Peterse0c446b2001-10-18 21:57:37 +0000174
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000175 def test_statvfs_attributes(self):
176 if not hasattr(os, "statvfs"):
177 return
178
179 import statvfs
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000180 try:
181 result = os.statvfs(self.fname)
Guido van Rossumb940e112007-01-10 16:19:56 +0000182 except OSError as e:
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000183 # On AtheOS, glibc always returns ENOSYS
184 import errno
185 if e.errno == errno.ENOSYS:
186 return
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000187
188 # Make sure direct access works
189 self.assertEquals(result.f_bfree, result[statvfs.F_BFREE])
190
191 # Make sure all the attributes are there
192 members = dir(result)
193 for name in dir(statvfs):
194 if name[:2] == 'F_':
195 attr = name.lower()
196 self.assertEquals(getattr(result, attr),
197 result[getattr(statvfs, name)])
198 self.assert_(attr in members)
199
200 # Make sure that assignment really fails
201 try:
202 result.f_bfree = 1
203 self.fail("No exception thrown")
Collin Winter42dae6a2007-03-28 21:44:53 +0000204 except AttributeError:
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000205 pass
206
207 try:
208 result.parrot = 1
209 self.fail("No exception thrown")
210 except AttributeError:
211 pass
212
213 # Use the constructor with a too-short tuple.
214 try:
215 result2 = os.statvfs_result((10,))
216 self.fail("No exception thrown")
217 except TypeError:
218 pass
219
220 # Use the constructr with a too-long tuple.
221 try:
222 result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
223 except TypeError:
224 pass
Fred Drake38c2ef02001-07-17 20:52:51 +0000225
Thomas Wouters89f507f2006-12-13 04:49:30 +0000226 def test_utime_dir(self):
227 delta = 1000000
228 st = os.stat(test_support.TESTFN)
229 # round to int, because some systems may support sub-second
230 # time stamps in stat, but not in utime.
231 os.utime(test_support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
232 st2 = os.stat(test_support.TESTFN)
233 self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))
234
235 # Restrict test to Win32, since there is no guarantee other
236 # systems support centiseconds
237 if sys.platform == 'win32':
Thomas Wouters47b49bf2007-08-30 22:15:33 +0000238 def get_file_system(path):
239 import os
240 root = os.path.splitdrive(os.path.realpath("."))[0] + '\\'
241 import ctypes
242 kernel32 = ctypes.windll.kernel32
243 buf = ctypes.create_string_buffer("", 100)
244 if kernel32.GetVolumeInformationA(root, None, 0, None, None, None, buf, len(buf)):
245 return buf.value
246
247 if get_file_system(test_support.TESTFN) == "NTFS":
248 def test_1565150(self):
249 t1 = 1159195039.25
250 os.utime(self.fname, (t1, t1))
251 self.assertEquals(os.stat(self.fname).st_mtime, t1)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000252
Guido van Rossumd8faa362007-04-27 19:54:29 +0000253 def test_1686475(self):
254 # Verify that an open file can be stat'ed
255 try:
256 os.stat(r"c:\pagefile.sys")
257 except WindowsError as e:
258 if e == 2: # file does not exist; cannot run test
259 return
260 self.fail("Could not stat pagefile.sys")
261
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000262from test import mapping_tests
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000263
Walter Dörwald0a6d0ff2004-05-31 16:29:04 +0000264class EnvironTests(mapping_tests.BasicTestMappingProtocol):
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000265 """check that os.environ object conform to mapping protocol"""
Walter Dörwald118f9312004-06-02 18:42:25 +0000266 type2test = None
Raymond Hettinger2c2d3222003-03-09 07:05:43 +0000267 def _reference(self):
268 return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
269 def _empty_mapping(self):
270 os.environ.clear()
271 return os.environ
272 def setUp(self):
273 self.__save = dict(os.environ)
274 os.environ.clear()
275 def tearDown(self):
276 os.environ.clear()
277 os.environ.update(self.__save)
278
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000279 # Bug 1110478
Martin v. Löwis5510f652005-02-17 21:23:20 +0000280 def test_update2(self):
Martin v. Löwis1d11de62005-01-29 13:29:23 +0000281 if os.path.exists("/bin/sh"):
282 os.environ.update(HELLO="World")
283 value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
284 self.assertEquals(value, "World")
285
Guido van Rossum67aca9e2007-06-13 21:51:27 +0000286 # Verify environ keys and values from the OS are of the
287 # correct str type.
288 def test_keyvalue_types(self):
289 for key, val in os.environ.items():
290 self.assertEquals(type(key), str)
291 self.assertEquals(type(val), str)
292
Tim Petersc4e09402003-04-25 07:11:48 +0000293class WalkTests(unittest.TestCase):
294 """Tests for os.walk()."""
295
296 def test_traversal(self):
297 import os
298 from os.path import join
299
300 # Build:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000301 # TESTFN/
302 # TEST1/ a file kid and two directory kids
Tim Petersc4e09402003-04-25 07:11:48 +0000303 # tmp1
304 # SUB1/ a file kid and a directory kid
Guido van Rossumd8faa362007-04-27 19:54:29 +0000305 # tmp2
306 # SUB11/ no kids
307 # SUB2/ a file kid and a dirsymlink kid
308 # tmp3
309 # link/ a symlink to TESTFN.2
310 # TEST2/
311 # tmp4 a lone file
312 walk_path = join(test_support.TESTFN, "TEST1")
313 sub1_path = join(walk_path, "SUB1")
Tim Petersc4e09402003-04-25 07:11:48 +0000314 sub11_path = join(sub1_path, "SUB11")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000315 sub2_path = join(walk_path, "SUB2")
316 tmp1_path = join(walk_path, "tmp1")
Tim Petersc4e09402003-04-25 07:11:48 +0000317 tmp2_path = join(sub1_path, "tmp2")
318 tmp3_path = join(sub2_path, "tmp3")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000319 link_path = join(sub2_path, "link")
320 t2_path = join(test_support.TESTFN, "TEST2")
321 tmp4_path = join(test_support.TESTFN, "TEST2", "tmp4")
Tim Petersc4e09402003-04-25 07:11:48 +0000322
323 # Create stuff.
324 os.makedirs(sub11_path)
325 os.makedirs(sub2_path)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000326 os.makedirs(t2_path)
327 for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
Alex Martelli01c77c62006-08-24 02:58:11 +0000328 f = open(path, "w")
Tim Petersc4e09402003-04-25 07:11:48 +0000329 f.write("I'm " + path + " and proud of it. Blame test_os.\n")
330 f.close()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000331 if hasattr(os, "symlink"):
332 os.symlink(os.path.abspath(t2_path), link_path)
333 sub2_tree = (sub2_path, ["link"], ["tmp3"])
334 else:
335 sub2_tree = (sub2_path, [], ["tmp3"])
Tim Petersc4e09402003-04-25 07:11:48 +0000336
337 # Walk top-down.
Guido van Rossumd8faa362007-04-27 19:54:29 +0000338 all = list(os.walk(walk_path))
Tim Petersc4e09402003-04-25 07:11:48 +0000339 self.assertEqual(len(all), 4)
340 # We can't know which order SUB1 and SUB2 will appear in.
341 # Not flipped: TESTFN, SUB1, SUB11, SUB2
342 # flipped: TESTFN, SUB2, SUB1, SUB11
343 flipped = all[0][1][0] != "SUB1"
344 all[0][1].sort()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000345 self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000346 self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
347 self.assertEqual(all[2 + flipped], (sub11_path, [], []))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000348 self.assertEqual(all[3 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000349
350 # Prune the search.
351 all = []
Guido van Rossumd8faa362007-04-27 19:54:29 +0000352 for root, dirs, files in os.walk(walk_path):
Tim Petersc4e09402003-04-25 07:11:48 +0000353 all.append((root, dirs, files))
354 # Don't descend into SUB1.
355 if 'SUB1' in dirs:
356 # Note that this also mutates the dirs we appended to all!
357 dirs.remove('SUB1')
358 self.assertEqual(len(all), 2)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000359 self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"]))
360 self.assertEqual(all[1], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000361
362 # Walk bottom-up.
Guido van Rossumd8faa362007-04-27 19:54:29 +0000363 all = list(os.walk(walk_path, topdown=False))
Tim Petersc4e09402003-04-25 07:11:48 +0000364 self.assertEqual(len(all), 4)
365 # We can't know which order SUB1 and SUB2 will appear in.
366 # Not flipped: SUB11, SUB1, SUB2, TESTFN
367 # flipped: SUB2, SUB11, SUB1, TESTFN
368 flipped = all[3][1][0] != "SUB1"
369 all[3][1].sort()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000370 self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
Tim Petersc4e09402003-04-25 07:11:48 +0000371 self.assertEqual(all[flipped], (sub11_path, [], []))
372 self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
Guido van Rossumd8faa362007-04-27 19:54:29 +0000373 self.assertEqual(all[2 - 2 * flipped], sub2_tree)
Tim Petersc4e09402003-04-25 07:11:48 +0000374
Guido van Rossumd8faa362007-04-27 19:54:29 +0000375 if hasattr(os, "symlink"):
376 # Walk, following symlinks.
377 for root, dirs, files in os.walk(walk_path, followlinks=True):
378 if root == link_path:
379 self.assertEqual(dirs, [])
380 self.assertEqual(files, ["tmp4"])
381 break
382 else:
383 self.fail("Didn't follow symlink with followlinks=True")
384
385 def tearDown(self):
Tim Petersc4e09402003-04-25 07:11:48 +0000386 # Tear everything down. This is a decent use for bottom-up on
387 # Windows, which doesn't have a recursive delete command. The
388 # (not so) subtlety is that rmdir will fail unless the dir's
389 # kids are removed first, so bottom up is essential.
Walter Dörwald21d3a322003-05-01 17:45:56 +0000390 for root, dirs, files in os.walk(test_support.TESTFN, topdown=False):
Tim Petersc4e09402003-04-25 07:11:48 +0000391 for name in files:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000392 os.remove(os.path.join(root, name))
Tim Petersc4e09402003-04-25 07:11:48 +0000393 for name in dirs:
Guido van Rossumd8faa362007-04-27 19:54:29 +0000394 dirname = os.path.join(root, name)
395 if not os.path.islink(dirname):
396 os.rmdir(dirname)
397 else:
398 os.remove(dirname)
Walter Dörwald21d3a322003-05-01 17:45:56 +0000399 os.rmdir(test_support.TESTFN)
Tim Petersc4e09402003-04-25 07:11:48 +0000400
Guido van Rossume7ba4952007-06-06 23:52:48 +0000401class MakedirTests(unittest.TestCase):
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000402 def setUp(self):
403 os.mkdir(test_support.TESTFN)
404
405 def test_makedir(self):
406 base = test_support.TESTFN
407 path = os.path.join(base, 'dir1', 'dir2', 'dir3')
408 os.makedirs(path) # Should work
409 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
410 os.makedirs(path)
411
412 # Try paths with a '.' in them
413 self.failUnlessRaises(OSError, os.makedirs, os.curdir)
414 path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
415 os.makedirs(path)
416 path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
417 'dir5', 'dir6')
418 os.makedirs(path)
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000419
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000420 def tearDown(self):
421 path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
422 'dir4', 'dir5', 'dir6')
423 # If the tests failed, the bottom-most directory ('../dir6')
424 # may not have been created, so we look for the outermost directory
425 # that exists.
426 while not os.path.exists(path) and path != test_support.TESTFN:
427 path = os.path.dirname(path)
428
429 os.removedirs(path)
430
Guido van Rossume7ba4952007-06-06 23:52:48 +0000431class DevNullTests(unittest.TestCase):
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000432 def test_devnull(self):
Alex Martelli01c77c62006-08-24 02:58:11 +0000433 f = open(os.devnull, 'w')
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000434 f.write('hello')
435 f.close()
Alex Martelli01c77c62006-08-24 02:58:11 +0000436 f = open(os.devnull, 'r')
Tim Peters4182cfd2004-06-08 20:34:34 +0000437 self.assertEqual(f.read(), '')
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000438 f.close()
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000439
Guido van Rossume7ba4952007-06-06 23:52:48 +0000440class URandomTests(unittest.TestCase):
Martin v. Löwisdc3883f2004-08-29 15:46:35 +0000441 def test_urandom(self):
442 try:
443 self.assertEqual(len(os.urandom(1)), 1)
444 self.assertEqual(len(os.urandom(10)), 10)
445 self.assertEqual(len(os.urandom(100)), 100)
446 self.assertEqual(len(os.urandom(1000)), 1000)
447 except NotImplementedError:
448 pass
449
Guido van Rossume7ba4952007-06-06 23:52:48 +0000450class ExecTests(unittest.TestCase):
451 def test_execvpe_with_bad_program(self):
Thomas Hellerbd315c52007-08-30 17:57:21 +0000452 self.assertRaises(OSError, os.execvpe, 'no such app-', ['no such app-'], None)
Guido van Rossume7ba4952007-06-06 23:52:48 +0000453
Thomas Heller6790d602007-08-30 17:15:14 +0000454 def test_execvpe_with_bad_arglist(self):
455 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
456
Thomas Wouters477c8d52006-05-27 19:21:47 +0000457class Win32ErrorTests(unittest.TestCase):
458 def test_rename(self):
459 self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak")
460
461 def test_remove(self):
462 self.assertRaises(WindowsError, os.remove, test_support.TESTFN)
463
464 def test_chdir(self):
465 self.assertRaises(WindowsError, os.chdir, test_support.TESTFN)
466
467 def test_mkdir(self):
468 self.assertRaises(WindowsError, os.chdir, test_support.TESTFN)
469
470 def test_utime(self):
471 self.assertRaises(WindowsError, os.utime, test_support.TESTFN, None)
472
473 def test_access(self):
474 self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0)
475
476 def test_chmod(self):
477 self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0)
478
479if sys.platform != 'win32':
480 class Win32ErrorTests(unittest.TestCase):
481 pass
482
Fred Drake2e2be372001-09-20 21:33:42 +0000483def test_main():
Walter Dörwald21d3a322003-05-01 17:45:56 +0000484 test_support.run_unittest(
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000485 FileTests,
Walter Dörwald21d3a322003-05-01 17:45:56 +0000486 TemporaryFileTests,
487 StatAttributeTests,
488 EnvironTests,
Andrew M. Kuchlingb386f6a2003-12-23 16:36:11 +0000489 WalkTests,
490 MakedirTests,
Martin v. Löwisbdec50f2004-06-08 08:29:33 +0000491 DevNullTests,
Thomas Wouters477c8d52006-05-27 19:21:47 +0000492 URandomTests,
Guido van Rossume7ba4952007-06-06 23:52:48 +0000493 ExecTests,
Thomas Wouters477c8d52006-05-27 19:21:47 +0000494 Win32ErrorTests
Walter Dörwald21d3a322003-05-01 17:45:56 +0000495 )
Fred Drake2e2be372001-09-20 21:33:42 +0000496
497if __name__ == "__main__":
498 test_main()