annotate Lib/test/test_posix.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents de63b7e8500d
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
1 "Test posix functions"
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
2
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
3 from test import test_support
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
4
53302
de63b7e8500d Restore skips of posix and pty tests on Windows by calling the
R. David Murray <rdmurray@bitdance.com>
parents: 52456
diff changeset
5 # Skip these tests if there is no posix module.
de63b7e8500d Restore skips of posix and pty tests on Windows by calling the
R. David Murray <rdmurray@bitdance.com>
parents: 52456
diff changeset
6 posix = test_support.import_module('posix')
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
7
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
8 import time
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
9 import os
45868
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
10 import pwd
47801
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
11 import shutil
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
12 import unittest
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
13 import warnings
52456
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
14
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
15
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
16 warnings.filterwarnings('ignore', '.* potential security risk .*',
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
17 RuntimeWarning)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
18
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
19 class PosixTester(unittest.TestCase):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
20
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
21 def setUp(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
22 # create empty file
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
23 fp = open(test_support.TESTFN, 'w+')
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
24 fp.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
25
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
26 def tearDown(self):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
27 os.unlink(test_support.TESTFN)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
28
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
29 def testNoArgFunctions(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
30 # test posix functions which take no arguments and have
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
31 # no side-effects which we need to cleanup (e.g., fork, wait, abort)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
32 NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname",
28029
6e20b049ed6f Fix SF bug #690081, test_posix fails when run in non-interactive mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 27924
diff changeset
33 "times", "getloadavg", "tmpnam",
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
34 "getegid", "geteuid", "getgid", "getgroups",
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
35 "getpid", "getpgrp", "getppid", "getuid",
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
36 ]
28029
6e20b049ed6f Fix SF bug #690081, test_posix fails when run in non-interactive mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 27924
diff changeset
37
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
38 for name in NO_ARG_FUNCTIONS:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
39 posix_func = getattr(posix, name, None)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
40 if posix_func is not None:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
41 posix_func()
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
42 self.assertRaises(TypeError, posix_func, 1)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
43
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
44 def test_statvfs(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
45 if hasattr(posix, 'statvfs'):
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
46 self.assert_(posix.statvfs(os.curdir))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
47
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
48 def test_fstatvfs(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
49 if hasattr(posix, 'fstatvfs'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
50 fp = open(test_support.TESTFN)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
51 try:
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
52 self.assert_(posix.fstatvfs(fp.fileno()))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
53 finally:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
54 fp.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
55
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
56 def test_ftruncate(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
57 if hasattr(posix, 'ftruncate'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
58 fp = open(test_support.TESTFN, 'w+')
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
59 try:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
60 # we need to have some data to truncate
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
61 fp.write('test')
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
62 fp.flush()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
63 posix.ftruncate(fp.fileno(), 0)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
64 finally:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
65 fp.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
66
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
67 def test_dup(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
68 if hasattr(posix, 'dup'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
69 fp = open(test_support.TESTFN)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
70 try:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
71 fd = posix.dup(fp.fileno())
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
72 self.assert_(isinstance(fd, int))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
73 os.close(fd)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
74 finally:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
75 fp.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
76
37860
d4ae9c0325b1 Correct implementation and documentation of os.confstr. Add a simple test
Skip Montanaro <skip@pobox.com>
parents: 35100
diff changeset
77 def test_confstr(self):
d4ae9c0325b1 Correct implementation and documentation of os.confstr. Add a simple test
Skip Montanaro <skip@pobox.com>
parents: 35100
diff changeset
78 if hasattr(posix, 'confstr'):
d4ae9c0325b1 Correct implementation and documentation of os.confstr. Add a simple test
Skip Montanaro <skip@pobox.com>
parents: 35100
diff changeset
79 self.assertRaises(ValueError, posix.confstr, "CS_garbage")
d4ae9c0325b1 Correct implementation and documentation of os.confstr. Add a simple test
Skip Montanaro <skip@pobox.com>
parents: 35100
diff changeset
80 self.assertEqual(len(posix.confstr("CS_PATH")) > 0, True)
d4ae9c0325b1 Correct implementation and documentation of os.confstr. Add a simple test
Skip Montanaro <skip@pobox.com>
parents: 35100
diff changeset
81
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
82 def test_dup2(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
83 if hasattr(posix, 'dup2'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
84 fp1 = open(test_support.TESTFN)
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
85 fp2 = open(test_support.TESTFN)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
86 try:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
87 posix.dup2(fp1.fileno(), fp2.fileno())
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
88 finally:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
89 fp1.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
90 fp2.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
91
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
92 def fdopen_helper(self, *args):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
93 fd = os.open(test_support.TESTFN, os.O_RDONLY)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
94 fp2 = posix.fdopen(fd, *args)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
95 fp2.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
96
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
97 def test_fdopen(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
98 if hasattr(posix, 'fdopen'):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
99 self.fdopen_helper()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
100 self.fdopen_helper('r')
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
101 self.fdopen_helper('r', 100)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
102
35100
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
103 def test_osexlock(self):
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
104 if hasattr(posix, "O_EXLOCK"):
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
105 fd = os.open(test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
106 os.O_WRONLY|os.O_EXLOCK|os.O_CREAT)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
107 self.assertRaises(OSError, os.open, test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
108 os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
109 os.close(fd)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
110
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
111 if hasattr(posix, "O_SHLOCK"):
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
112 fd = os.open(test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
113 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
114 self.assertRaises(OSError, os.open, test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
115 os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
116 os.close(fd)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
117
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
118 def test_osshlock(self):
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
119 if hasattr(posix, "O_SHLOCK"):
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
120 fd1 = os.open(test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
121 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
122 fd2 = os.open(test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
123 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
124 os.close(fd2)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
125 os.close(fd1)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
126
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
127 if hasattr(posix, "O_EXLOCK"):
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
128 fd = os.open(test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
129 os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
130 self.assertRaises(OSError, os.open, test_support.TESTFN,
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
131 os.O_RDONLY|os.O_EXLOCK|os.O_NONBLOCK)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
132 os.close(fd)
2d0693b9f0bd Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
Skip Montanaro <skip@pobox.com>
parents: 32283
diff changeset
133
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
134 def test_fstat(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
135 if hasattr(posix, 'fstat'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
136 fp = open(test_support.TESTFN)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
137 try:
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
138 self.assert_(posix.fstat(fp.fileno()))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
139 finally:
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
140 fp.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
141
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
142 def test_stat(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
143 if hasattr(posix, 'stat'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
144 self.assert_(posix.stat(test_support.TESTFN))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
145
45868
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
146 if hasattr(posix, 'chown'):
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
147 def test_chown(self):
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
148 # raise an OSError if the file does not exist
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
149 os.unlink(test_support.TESTFN)
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
150 self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1)
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
151
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
152 # re-create the file
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
153 open(test_support.TESTFN, 'w').close()
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
154 if os.getuid() == 0:
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
155 try:
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
156 # Many linux distros have a nfsnobody user as MAX_UID-2
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
157 # that makes a good test case for signedness issues.
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
158 # http://bugs.python.org/issue1747858
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
159 # This part of the test only runs when run as root.
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
160 # Only scary people run their tests as root.
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
161 ent = pwd.getpwnam('nfsnobody')
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
162 posix.chown(test_support.TESTFN, ent.pw_uid, ent.pw_gid)
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
163 except KeyError:
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
164 pass
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
165 else:
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
166 # non-root cannot chown to root, raises OSError
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
167 self.assertRaises(OSError, posix.chown,
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
168 test_support.TESTFN, 0, 0)
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
169
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
170 # test a successful chown call
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
171 posix.chown(test_support.TESTFN, os.getuid(), os.getgid())
3a72cbcc1bb8 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
Gregory P. Smith <greg@mad-scientist.com>
parents: 45468
diff changeset
172
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
173 def test_chdir(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
174 if hasattr(posix, 'chdir'):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
175 posix.chdir(os.curdir)
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
176 self.assertRaises(OSError, posix.chdir, test_support.TESTFN)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
177
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
178 def test_lsdir(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
179 if hasattr(posix, 'lsdir'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
180 self.assert_(test_support.TESTFN in posix.lsdir(os.curdir))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
181
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
182 def test_access(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
183 if hasattr(posix, 'access'):
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
184 self.assert_(posix.access(test_support.TESTFN, os.R_OK))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
185
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
186 def test_umask(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
187 if hasattr(posix, 'umask'):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
188 old_mask = posix.umask(0)
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
189 self.assert_(isinstance(old_mask, int))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
190 posix.umask(old_mask)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
191
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
192 def test_strerror(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
193 if hasattr(posix, 'strerror'):
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
194 self.assert_(posix.strerror(0))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
195
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
196 def test_pipe(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
197 if hasattr(posix, 'pipe'):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
198 reader, writer = posix.pipe()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
199 os.close(reader)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
200 os.close(writer)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
201
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
202 def test_tempnam(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
203 if hasattr(posix, 'tempnam'):
27924
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
204 self.assert_(posix.tempnam())
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
205 self.assert_(posix.tempnam(os.curdir))
3018f31f6830 Make changes suggested by Walter to use self.assert*() methods.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27922
diff changeset
206 self.assert_(posix.tempnam(os.curdir, 'blah'))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
207
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
208 def test_tmpfile(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
209 if hasattr(posix, 'tmpfile'):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
210 fp = posix.tmpfile()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
211 fp.close()
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
212
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
213 def test_utime(self):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
214 if hasattr(posix, 'utime'):
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
215 now = time.time()
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
216 posix.utime(test_support.TESTFN, None)
32283
6dbfee2ded89 Try to improve test coverage for utime()
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
217 self.assertRaises(TypeError, posix.utime, test_support.TESTFN, (None, None))
6dbfee2ded89 Try to improve test coverage for utime()
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
218 self.assertRaises(TypeError, posix.utime, test_support.TESTFN, (now, None))
6dbfee2ded89 Try to improve test coverage for utime()
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
219 self.assertRaises(TypeError, posix.utime, test_support.TESTFN, (None, now))
6dbfee2ded89 Try to improve test coverage for utime()
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
220 posix.utime(test_support.TESTFN, (int(now), int(now)))
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
221 posix.utime(test_support.TESTFN, (now, now))
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
222
40872
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
223 def test_chflags(self):
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
224 if hasattr(posix, 'chflags'):
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
225 st = os.stat(test_support.TESTFN)
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
226 if hasattr(st, 'st_flags'):
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
227 posix.chflags(test_support.TESTFN, st.st_flags)
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
228
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
229 def test_lchflags(self):
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
230 if hasattr(posix, 'lchflags'):
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
231 st = os.stat(test_support.TESTFN)
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
232 if hasattr(st, 'st_flags'):
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
233 posix.lchflags(test_support.TESTFN, st.st_flags)
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 37860
diff changeset
234
47801
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
235 def test_getcwd_long_pathnames(self):
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
236 if hasattr(posix, 'getcwd'):
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
237 dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
238 curdir = os.getcwd()
47806
da6893e2004f Trying to see if the problem in Martin's buildot is at
Facundo Batista <facundobatista@gmail.com>
parents: 47804
diff changeset
239 base_path = os.path.abspath(test_support.TESTFN) + '.getcwd'
47801
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
240
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
241 try:
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
242 os.mkdir(base_path)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
243 os.chdir(base_path)
47806
da6893e2004f Trying to see if the problem in Martin's buildot is at
Facundo Batista <facundobatista@gmail.com>
parents: 47804
diff changeset
244 except:
52353
e6009b9cd908 remove test_support.TestSkipped and just use unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 47810
diff changeset
245 # Just returning nothing instead of the SkipTest exception,
47810
88bd8eaa5152 Just returning nothing instead of rising TestSkipped, because
Facundo Batista <facundobatista@gmail.com>
parents: 47806
diff changeset
246 # because the test results in Error in that case.
88bd8eaa5152 Just returning nothing instead of rising TestSkipped, because
Facundo Batista <facundobatista@gmail.com>
parents: 47806
diff changeset
247 # Is that ok?
52353
e6009b9cd908 remove test_support.TestSkipped and just use unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 47810
diff changeset
248 # raise unittest.SkipTest, "cannot create directory for testing"
47810
88bd8eaa5152 Just returning nothing instead of rising TestSkipped, because
Facundo Batista <facundobatista@gmail.com>
parents: 47806
diff changeset
249 return
47801
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
250
47806
da6893e2004f Trying to see if the problem in Martin's buildot is at
Facundo Batista <facundobatista@gmail.com>
parents: 47804
diff changeset
251 try:
47801
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
252 def _create_and_do_getcwd(dirname, current_path_length = 0):
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
253 try:
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
254 os.mkdir(dirname)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
255 except:
52353
e6009b9cd908 remove test_support.TestSkipped and just use unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 47810
diff changeset
256 raise unittest.SkipTest, "mkdir cannot create directory sufficiently deep for getcwd test"
47801
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
257
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
258 os.chdir(dirname)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
259 try:
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
260 os.getcwd()
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
261 if current_path_length < 1027:
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
262 _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
263 finally:
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
264 os.chdir('..')
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
265 os.rmdir(dirname)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
266
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
267 _create_and_do_getcwd(dirname)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
268
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
269 finally:
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
270 shutil.rmtree(base_path)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
271 os.chdir(curdir)
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
272
96adf96d861a Issue #2722. Now the char buffer to support the path string has
Facundo Batista <facundobatista@gmail.com>
parents: 45868
diff changeset
273
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
274 def test_main():
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28323
diff changeset
275 test_support.run_unittest(PosixTester)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
276
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
277 if __name__ == '__main__':
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
278 test_main()