/Lib/test/test_os.py

http://unladen-swallow.googlecode.com/ · Python · 673 lines · 473 code · 93 blank · 107 comment · 107 complexity · ab26482c6f1e4b674f18703d275cf798 MD5 · raw file

  1. # As a test suite for the os module, this is woefully inadequate, but this
  2. # does add tests for a few functions which have been determined to be more
  3. # portable than they had been thought to be.
  4. import os
  5. import unittest
  6. import warnings
  7. import sys
  8. from test import test_support
  9. warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
  10. warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__)
  11. # Tests creating TESTFN
  12. class FileTests(unittest.TestCase):
  13. def setUp(self):
  14. if os.path.exists(test_support.TESTFN):
  15. os.unlink(test_support.TESTFN)
  16. tearDown = setUp
  17. def test_access(self):
  18. f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
  19. os.close(f)
  20. self.assert_(os.access(test_support.TESTFN, os.W_OK))
  21. def test_closerange(self):
  22. first = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
  23. # We must allocate two consecutive file descriptors, otherwise
  24. # it will mess up other file descriptors (perhaps even the three
  25. # standard ones).
  26. second = os.dup(first)
  27. try:
  28. retries = 0
  29. while second != first + 1:
  30. os.close(first)
  31. retries += 1
  32. if retries > 10:
  33. # XXX test skipped
  34. print >> sys.stderr, (
  35. "couldn't allocate two consecutive fds, "
  36. "skipping test_closerange")
  37. return
  38. first, second = second, os.dup(second)
  39. finally:
  40. os.close(second)
  41. # close a fd that is open, and one that isn't
  42. os.closerange(first, first + 2)
  43. self.assertRaises(OSError, os.write, first, "a")
  44. def test_rename(self):
  45. path = unicode(test_support.TESTFN)
  46. old = sys.getrefcount(path)
  47. self.assertRaises(TypeError, os.rename, path, 0)
  48. new = sys.getrefcount(path)
  49. self.assertEqual(old, new)
  50. class TemporaryFileTests(unittest.TestCase):
  51. def setUp(self):
  52. self.files = []
  53. os.mkdir(test_support.TESTFN)
  54. def tearDown(self):
  55. for name in self.files:
  56. os.unlink(name)
  57. os.rmdir(test_support.TESTFN)
  58. def check_tempfile(self, name):
  59. # make sure it doesn't already exist:
  60. self.failIf(os.path.exists(name),
  61. "file already exists for temporary file")
  62. # make sure we can create the file
  63. open(name, "w")
  64. self.files.append(name)
  65. def test_tempnam(self):
  66. if not hasattr(os, "tempnam"):
  67. return
  68. warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
  69. r"test_os$")
  70. self.check_tempfile(os.tempnam())
  71. name = os.tempnam(test_support.TESTFN)
  72. self.check_tempfile(name)
  73. name = os.tempnam(test_support.TESTFN, "pfx")
  74. self.assert_(os.path.basename(name)[:3] == "pfx")
  75. self.check_tempfile(name)
  76. def test_tmpfile(self):
  77. if not hasattr(os, "tmpfile"):
  78. return
  79. # As with test_tmpnam() below, the Windows implementation of tmpfile()
  80. # attempts to create a file in the root directory of the current drive.
  81. # On Vista and Server 2008, this test will always fail for normal users
  82. # as writing to the root directory requires elevated privileges. With
  83. # XP and below, the semantics of tmpfile() are the same, but the user
  84. # running the test is more likely to have administrative privileges on
  85. # their account already. If that's the case, then os.tmpfile() should
  86. # work. In order to make this test as useful as possible, rather than
  87. # trying to detect Windows versions or whether or not the user has the
  88. # right permissions, just try and create a file in the root directory
  89. # and see if it raises a 'Permission denied' OSError. If it does, then
  90. # test that a subsequent call to os.tmpfile() raises the same error. If
  91. # it doesn't, assume we're on XP or below and the user running the test
  92. # has administrative privileges, and proceed with the test as normal.
  93. if sys.platform == 'win32':
  94. name = '\\python_test_os_test_tmpfile.txt'
  95. if os.path.exists(name):
  96. os.remove(name)
  97. try:
  98. fp = open(name, 'w')
  99. except IOError, first:
  100. # open() failed, assert tmpfile() fails in the same way.
  101. # Although open() raises an IOError and os.tmpfile() raises an
  102. # OSError(), 'args' will be (13, 'Permission denied') in both
  103. # cases.
  104. try:
  105. fp = os.tmpfile()
  106. except OSError, second:
  107. self.assertEqual(first.args, second.args)
  108. else:
  109. self.fail("expected os.tmpfile() to raise OSError")
  110. return
  111. else:
  112. # open() worked, therefore, tmpfile() should work. Close our
  113. # dummy file and proceed with the test as normal.
  114. fp.close()
  115. os.remove(name)
  116. fp = os.tmpfile()
  117. fp.write("foobar")
  118. fp.seek(0,0)
  119. s = fp.read()
  120. fp.close()
  121. self.assert_(s == "foobar")
  122. def test_tmpnam(self):
  123. import sys
  124. if not hasattr(os, "tmpnam"):
  125. return
  126. warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
  127. r"test_os$")
  128. name = os.tmpnam()
  129. if sys.platform in ("win32",):
  130. # The Windows tmpnam() seems useless. From the MS docs:
  131. #
  132. # The character string that tmpnam creates consists of
  133. # the path prefix, defined by the entry P_tmpdir in the
  134. # file STDIO.H, followed by a sequence consisting of the
  135. # digit characters '0' through '9'; the numerical value
  136. # of this string is in the range 1 - 65,535. Changing the
  137. # definitions of L_tmpnam or P_tmpdir in STDIO.H does not
  138. # change the operation of tmpnam.
  139. #
  140. # The really bizarre part is that, at least under MSVC6,
  141. # P_tmpdir is "\\". That is, the path returned refers to
  142. # the root of the current drive. That's a terrible place to
  143. # put temp files, and, depending on privileges, the user
  144. # may not even be able to open a file in the root directory.
  145. self.failIf(os.path.exists(name),
  146. "file already exists for temporary file")
  147. else:
  148. self.check_tempfile(name)
  149. # Test attributes on return values from os.*stat* family.
  150. class StatAttributeTests(unittest.TestCase):
  151. def setUp(self):
  152. os.mkdir(test_support.TESTFN)
  153. self.fname = os.path.join(test_support.TESTFN, "f1")
  154. f = open(self.fname, 'wb')
  155. f.write("ABC")
  156. f.close()
  157. def tearDown(self):
  158. os.unlink(self.fname)
  159. os.rmdir(test_support.TESTFN)
  160. def test_stat_attributes(self):
  161. if not hasattr(os, "stat"):
  162. return
  163. import stat
  164. result = os.stat(self.fname)
  165. # Make sure direct access works
  166. self.assertEquals(result[stat.ST_SIZE], 3)
  167. self.assertEquals(result.st_size, 3)
  168. import sys
  169. # Make sure all the attributes are there
  170. members = dir(result)
  171. for name in dir(stat):
  172. if name[:3] == 'ST_':
  173. attr = name.lower()
  174. if name.endswith("TIME"):
  175. def trunc(x): return int(x)
  176. else:
  177. def trunc(x): return x
  178. self.assertEquals(trunc(getattr(result, attr)),
  179. result[getattr(stat, name)])
  180. self.assert_(attr in members)
  181. try:
  182. result[200]
  183. self.fail("No exception thrown")
  184. except IndexError:
  185. pass
  186. # Make sure that assignment fails
  187. try:
  188. result.st_mode = 1
  189. self.fail("No exception thrown")
  190. except TypeError:
  191. pass
  192. try:
  193. result.st_rdev = 1
  194. self.fail("No exception thrown")
  195. except (AttributeError, TypeError):
  196. pass
  197. try:
  198. result.parrot = 1
  199. self.fail("No exception thrown")
  200. except AttributeError:
  201. pass
  202. # Use the stat_result constructor with a too-short tuple.
  203. try:
  204. result2 = os.stat_result((10,))
  205. self.fail("No exception thrown")
  206. except TypeError:
  207. pass
  208. # Use the constructr with a too-long tuple.
  209. try:
  210. result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
  211. except TypeError:
  212. pass
  213. def test_statvfs_attributes(self):
  214. if not hasattr(os, "statvfs"):
  215. return
  216. try:
  217. result = os.statvfs(self.fname)
  218. except OSError, e:
  219. # On AtheOS, glibc always returns ENOSYS
  220. import errno
  221. if e.errno == errno.ENOSYS:
  222. return
  223. # Make sure direct access works
  224. self.assertEquals(result.f_bfree, result[3])
  225. # 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):
  229. self.assertEquals(getattr(result, 'f_' + member), result[value])
  230. # Make sure that assignment really fails
  231. try:
  232. result.f_bfree = 1
  233. self.fail("No exception thrown")
  234. except TypeError:
  235. pass
  236. try:
  237. result.parrot = 1
  238. self.fail("No exception thrown")
  239. except AttributeError:
  240. pass
  241. # Use the constructor with a too-short tuple.
  242. try:
  243. result2 = os.statvfs_result((10,))
  244. self.fail("No exception thrown")
  245. except TypeError:
  246. pass
  247. # Use the constructr with a too-long tuple.
  248. try:
  249. result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
  250. except TypeError:
  251. pass
  252. def test_utime_dir(self):
  253. delta = 1000000
  254. st = os.stat(test_support.TESTFN)
  255. # round to int, because some systems may support sub-second
  256. # time stamps in stat, but not in utime.
  257. os.utime(test_support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
  258. st2 = os.stat(test_support.TESTFN)
  259. self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))
  260. # Restrict test to Win32, since there is no guarantee other
  261. # systems support centiseconds
  262. if sys.platform == 'win32':
  263. def get_file_system(path):
  264. root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
  265. import ctypes
  266. kernel32 = ctypes.windll.kernel32
  267. buf = ctypes.create_string_buffer("", 100)
  268. if kernel32.GetVolumeInformationA(root, None, 0, None, None, None, buf, len(buf)):
  269. return buf.value
  270. if get_file_system(test_support.TESTFN) == "NTFS":
  271. def test_1565150(self):
  272. t1 = 1159195039.25
  273. os.utime(self.fname, (t1, t1))
  274. self.assertEquals(os.stat(self.fname).st_mtime, t1)
  275. def test_1686475(self):
  276. # Verify that an open file can be stat'ed
  277. try:
  278. os.stat(r"c:\pagefile.sys")
  279. except WindowsError, e:
  280. if e.errno == 2: # file does not exist; cannot run test
  281. return
  282. self.fail("Could not stat pagefile.sys")
  283. from test import mapping_tests
  284. class EnvironTests(mapping_tests.BasicTestMappingProtocol):
  285. """check that os.environ object conform to mapping protocol"""
  286. type2test = None
  287. def _reference(self):
  288. return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
  289. def _empty_mapping(self):
  290. os.environ.clear()
  291. return os.environ
  292. def setUp(self):
  293. self.__save = dict(os.environ)
  294. os.environ.clear()
  295. def tearDown(self):
  296. os.environ.clear()
  297. os.environ.update(self.__save)
  298. # Bug 1110478
  299. def test_update2(self):
  300. if os.path.exists("/bin/sh"):
  301. os.environ.update(HELLO="World")
  302. value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
  303. self.assertEquals(value, "World")
  304. class WalkTests(unittest.TestCase):
  305. """Tests for os.walk()."""
  306. def test_traversal(self):
  307. import os
  308. from os.path import join
  309. # Build:
  310. # TESTFN/
  311. # TEST1/ a file kid and two directory kids
  312. # tmp1
  313. # SUB1/ a file kid and a directory kid
  314. # tmp2
  315. # SUB11/ no kids
  316. # SUB2/ a file kid and a dirsymlink kid
  317. # tmp3
  318. # link/ a symlink to TESTFN.2
  319. # TEST2/
  320. # tmp4 a lone file
  321. walk_path = join(test_support.TESTFN, "TEST1")
  322. sub1_path = join(walk_path, "SUB1")
  323. sub11_path = join(sub1_path, "SUB11")
  324. sub2_path = join(walk_path, "SUB2")
  325. tmp1_path = join(walk_path, "tmp1")
  326. tmp2_path = join(sub1_path, "tmp2")
  327. tmp3_path = join(sub2_path, "tmp3")
  328. link_path = join(sub2_path, "link")
  329. t2_path = join(test_support.TESTFN, "TEST2")
  330. tmp4_path = join(test_support.TESTFN, "TEST2", "tmp4")
  331. # Create stuff.
  332. os.makedirs(sub11_path)
  333. os.makedirs(sub2_path)
  334. os.makedirs(t2_path)
  335. for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
  336. f = file(path, "w")
  337. f.write("I'm " + path + " and proud of it. Blame test_os.\n")
  338. f.close()
  339. if hasattr(os, "symlink"):
  340. os.symlink(os.path.abspath(t2_path), link_path)
  341. sub2_tree = (sub2_path, ["link"], ["tmp3"])
  342. else:
  343. sub2_tree = (sub2_path, [], ["tmp3"])
  344. # Walk top-down.
  345. all = list(os.walk(walk_path))
  346. self.assertEqual(len(all), 4)
  347. # We can't know which order SUB1 and SUB2 will appear in.
  348. # Not flipped: TESTFN, SUB1, SUB11, SUB2
  349. # flipped: TESTFN, SUB2, SUB1, SUB11
  350. flipped = all[0][1][0] != "SUB1"
  351. all[0][1].sort()
  352. self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
  353. self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
  354. self.assertEqual(all[2 + flipped], (sub11_path, [], []))
  355. self.assertEqual(all[3 - 2 * flipped], sub2_tree)
  356. # Prune the search.
  357. all = []
  358. for root, dirs, files in os.walk(walk_path):
  359. all.append((root, dirs, files))
  360. # Don't descend into SUB1.
  361. if 'SUB1' in dirs:
  362. # Note that this also mutates the dirs we appended to all!
  363. dirs.remove('SUB1')
  364. self.assertEqual(len(all), 2)
  365. self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"]))
  366. self.assertEqual(all[1], sub2_tree)
  367. # Walk bottom-up.
  368. all = list(os.walk(walk_path, topdown=False))
  369. self.assertEqual(len(all), 4)
  370. # We can't know which order SUB1 and SUB2 will appear in.
  371. # Not flipped: SUB11, SUB1, SUB2, TESTFN
  372. # flipped: SUB2, SUB11, SUB1, TESTFN
  373. flipped = all[3][1][0] != "SUB1"
  374. all[3][1].sort()
  375. self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
  376. self.assertEqual(all[flipped], (sub11_path, [], []))
  377. self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
  378. self.assertEqual(all[2 - 2 * flipped], sub2_tree)
  379. if hasattr(os, "symlink"):
  380. # Walk, following symlinks.
  381. for root, dirs, files in os.walk(walk_path, followlinks=True):
  382. if root == link_path:
  383. self.assertEqual(dirs, [])
  384. self.assertEqual(files, ["tmp4"])
  385. break
  386. else:
  387. self.fail("Didn't follow symlink with followlinks=True")
  388. def tearDown(self):
  389. # Tear everything down. This is a decent use for bottom-up on
  390. # Windows, which doesn't have a recursive delete command. The
  391. # (not so) subtlety is that rmdir will fail unless the dir's
  392. # kids are removed first, so bottom up is essential.
  393. for root, dirs, files in os.walk(test_support.TESTFN, topdown=False):
  394. for name in files:
  395. os.remove(os.path.join(root, name))
  396. for name in dirs:
  397. dirname = os.path.join(root, name)
  398. if not os.path.islink(dirname):
  399. os.rmdir(dirname)
  400. else:
  401. os.remove(dirname)
  402. os.rmdir(test_support.TESTFN)
  403. class MakedirTests (unittest.TestCase):
  404. def setUp(self):
  405. os.mkdir(test_support.TESTFN)
  406. def test_makedir(self):
  407. base = test_support.TESTFN
  408. path = os.path.join(base, 'dir1', 'dir2', 'dir3')
  409. os.makedirs(path) # Should work
  410. path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
  411. os.makedirs(path)
  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)
  419. def tearDown(self):
  420. path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
  421. 'dir4', 'dir5', 'dir6')
  422. # If the tests failed, the bottom-most directory ('../dir6')
  423. # may not have been created, so we look for the outermost directory
  424. # that exists.
  425. while not os.path.exists(path) and path != test_support.TESTFN:
  426. path = os.path.dirname(path)
  427. os.removedirs(path)
  428. class DevNullTests (unittest.TestCase):
  429. def test_devnull(self):
  430. f = file(os.devnull, 'w')
  431. f.write('hello')
  432. f.close()
  433. f = file(os.devnull, 'r')
  434. self.assertEqual(f.read(), '')
  435. f.close()
  436. class URandomTests (unittest.TestCase):
  437. def test_urandom(self):
  438. try:
  439. self.assertEqual(len(os.urandom(1)), 1)
  440. self.assertEqual(len(os.urandom(10)), 10)
  441. self.assertEqual(len(os.urandom(100)), 100)
  442. self.assertEqual(len(os.urandom(1000)), 1000)
  443. # see http://bugs.python.org/issue3708
  444. self.assertEqual(len(os.urandom(0.9)), 0)
  445. self.assertEqual(len(os.urandom(1.1)), 1)
  446. self.assertEqual(len(os.urandom(2.0)), 2)
  447. except NotImplementedError:
  448. pass
  449. class Win32ErrorTests(unittest.TestCase):
  450. def test_rename(self):
  451. self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak")
  452. def test_remove(self):
  453. self.assertRaises(WindowsError, os.remove, test_support.TESTFN)
  454. def test_chdir(self):
  455. self.assertRaises(WindowsError, os.chdir, test_support.TESTFN)
  456. def test_mkdir(self):
  457. self.assertRaises(WindowsError, os.chdir, test_support.TESTFN)
  458. def test_utime(self):
  459. self.assertRaises(WindowsError, os.utime, test_support.TESTFN, None)
  460. def test_access(self):
  461. self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0)
  462. def test_chmod(self):
  463. self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0)
  464. class TestInvalidFD(unittest.TestCase):
  465. singles = ["fchdir", "fdopen", "dup", "fdatasync", "fstat",
  466. "fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
  467. #singles.append("close")
  468. #We omit close because it doesn'r raise an exception on some platforms
  469. def get_single(f):
  470. def helper(self):
  471. if hasattr(os, f):
  472. self.check(getattr(os, f))
  473. return helper
  474. for f in singles:
  475. locals()["test_"+f] = get_single(f)
  476. def check(self, f, *args):
  477. self.assertRaises(OSError, f, test_support.make_bad_fd(), *args)
  478. def test_isatty(self):
  479. if hasattr(os, "isatty"):
  480. self.assertEqual(os.isatty(test_support.make_bad_fd()), False)
  481. def test_closerange(self):
  482. if hasattr(os, "closerange"):
  483. fd = test_support.make_bad_fd()
  484. # Make sure none of the descriptors we are about to close are
  485. # currently valid (issue 6542).
  486. for i in range(10):
  487. try: os.fstat(fd+i)
  488. except OSError:
  489. pass
  490. else:
  491. break
  492. if i < 2:
  493. # Unable to acquire a range of invalid file descriptors,
  494. # so skip the test (in 2.6+ this is a unittest.SkipTest).
  495. return
  496. self.assertEqual(os.closerange(fd, fd + i-1), None)
  497. def test_dup2(self):
  498. if hasattr(os, "dup2"):
  499. self.check(os.dup2, 20)
  500. def test_fchmod(self):
  501. if hasattr(os, "fchmod"):
  502. self.check(os.fchmod, 0)
  503. def test_fchown(self):
  504. if hasattr(os, "fchown"):
  505. self.check(os.fchown, -1, -1)
  506. def test_fpathconf(self):
  507. if hasattr(os, "fpathconf"):
  508. self.check(os.fpathconf, "PC_NAME_MAX")
  509. #this is a weird one, it raises IOError unlike the others
  510. def test_ftruncate(self):
  511. if hasattr(os, "ftruncate"):
  512. self.assertRaises(IOError, os.ftruncate, test_support.make_bad_fd(),
  513. 0)
  514. def test_lseek(self):
  515. if hasattr(os, "lseek"):
  516. self.check(os.lseek, 0, 0)
  517. def test_read(self):
  518. if hasattr(os, "read"):
  519. self.check(os.read, 1)
  520. def test_tcsetpgrpt(self):
  521. if hasattr(os, "tcsetpgrp"):
  522. self.check(os.tcsetpgrp, 0)
  523. def test_write(self):
  524. if hasattr(os, "write"):
  525. self.check(os.write, " ")
  526. if sys.platform != 'win32':
  527. class Win32ErrorTests(unittest.TestCase):
  528. pass
  529. class PosixUidGidTests(unittest.TestCase):
  530. if hasattr(os, 'setuid'):
  531. def test_setuid(self):
  532. if os.getuid() != 0:
  533. self.assertRaises(os.error, os.setuid, 0)
  534. self.assertRaises(OverflowError, os.setuid, 1<<32)
  535. if hasattr(os, 'setgid'):
  536. def test_setgid(self):
  537. if os.getuid() != 0:
  538. self.assertRaises(os.error, os.setgid, 0)
  539. self.assertRaises(OverflowError, os.setgid, 1<<32)
  540. if hasattr(os, 'seteuid'):
  541. def test_seteuid(self):
  542. if os.getuid() != 0:
  543. self.assertRaises(os.error, os.seteuid, 0)
  544. self.assertRaises(OverflowError, os.seteuid, 1<<32)
  545. if hasattr(os, 'setegid'):
  546. def test_setegid(self):
  547. if os.getuid() != 0:
  548. self.assertRaises(os.error, os.setegid, 0)
  549. self.assertRaises(OverflowError, os.setegid, 1<<32)
  550. if hasattr(os, 'setreuid'):
  551. def test_setreuid(self):
  552. if os.getuid() != 0:
  553. self.assertRaises(os.error, os.setreuid, 0, 0)
  554. self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
  555. self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
  556. if hasattr(os, 'setregid'):
  557. def test_setregid(self):
  558. if os.getuid() != 0:
  559. self.assertRaises(os.error, os.setregid, 0, 0)
  560. self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
  561. self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
  562. else:
  563. class PosixUidGidTests(unittest.TestCase):
  564. pass
  565. def test_main():
  566. test_support.run_unittest(
  567. FileTests,
  568. TemporaryFileTests,
  569. StatAttributeTests,
  570. EnvironTests,
  571. WalkTests,
  572. MakedirTests,
  573. DevNullTests,
  574. URandomTests,
  575. Win32ErrorTests,
  576. TestInvalidFD,
  577. PosixUidGidTests
  578. )
  579. if __name__ == "__main__":
  580. test_main()