Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(155776)

Delta Between Two Patch Sets: Lib/test/test_posix.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years ago
Right Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_platform.py ('k') | Lib/test/test_property.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 "Test posix functions" 1 "Test posix functions"
2 2
3 from test import support 3 from test import support
4 4
5 # Skip these tests if there is no posix module. 5 # Skip these tests if there is no posix module.
6 posix = support.import_module('posix') 6 posix = support.import_module('posix')
7 7
8 import errno 8 import errno
9 import sys 9 import sys
10 import time 10 import time
11 import os 11 import os
12 import fcntl 12 import fcntl
13 import platform 13 import platform
14 import pwd 14 import pwd
15 import shutil 15 import shutil
16 import stat 16 import stat
17 import tempfile 17 import tempfile
18 import unittest 18 import unittest
19 import warnings 19 import warnings
20 import _testcapi
21 20
22 _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(), 21 _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
23 support.TESTFN + '-dummy-symlink') 22 support.TESTFN + '-dummy-symlink')
24 23
25 class PosixTester(unittest.TestCase): 24 class PosixTester(unittest.TestCase):
26 25
27 def setUp(self): 26 def setUp(self):
28 # create empty file 27 # create empty file
29 fp = open(support.TESTFN, 'w+') 28 fp = open(support.TESTFN, 'w+')
30 fp.close() 29 fp.close()
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 self.assertRaises(TypeError, posix.utime, support.TESTFN, (now, None), f ollow_symlinks=False) 275 self.assertRaises(TypeError, posix.utime, support.TESTFN, (now, None), f ollow_symlinks=False)
277 self.assertRaises(TypeError, posix.utime, support.TESTFN, (None, now), f ollow_symlinks=False) 276 self.assertRaises(TypeError, posix.utime, support.TESTFN, (None, now), f ollow_symlinks=False)
278 posix.utime(support.TESTFN, (int(now), int(now)), follow_symlinks=False) 277 posix.utime(support.TESTFN, (int(now), int(now)), follow_symlinks=False)
279 posix.utime(support.TESTFN, (now, now), follow_symlinks=False) 278 posix.utime(support.TESTFN, (now, now), follow_symlinks=False)
280 posix.utime(support.TESTFN, follow_symlinks=False) 279 posix.utime(support.TESTFN, follow_symlinks=False)
281 280
282 @unittest.skipUnless(hasattr(posix, 'writev'), "test needs posix.writev()") 281 @unittest.skipUnless(hasattr(posix, 'writev'), "test needs posix.writev()")
283 def test_writev(self): 282 def test_writev(self):
284 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) 283 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
285 try: 284 try:
286 os.writev(fd, (b'test1', b'tt2', b't3')) 285 n = os.writev(fd, (b'test1', b'tt2', b't3'))
286 self.assertEqual(n, 10)
287
287 os.lseek(fd, 0, os.SEEK_SET) 288 os.lseek(fd, 0, os.SEEK_SET)
288 self.assertEqual(b'test1tt2t3', posix.read(fd, 10)) 289 self.assertEqual(b'test1tt2t3', posix.read(fd, 10))
290
291 # Issue #20113: empty list of buffers should not crash
292 try:
293 size = posix.writev(fd, [])
294 except OSError:
295 # writev(fd, []) raises OSError(22, "Invalid argument")
296 # on OpenIndiana
297 pass
298 else:
299 self.assertEqual(size, 0)
289 finally: 300 finally:
290 os.close(fd) 301 os.close(fd)
291 302
292 @unittest.skipUnless(hasattr(posix, 'readv'), "test needs posix.readv()") 303 @unittest.skipUnless(hasattr(posix, 'readv'), "test needs posix.readv()")
293 def test_readv(self): 304 def test_readv(self):
294 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) 305 fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
295 try: 306 try:
296 os.write(fd, b'test1tt2t3') 307 os.write(fd, b'test1tt2t3')
297 os.lseek(fd, 0, os.SEEK_SET) 308 os.lseek(fd, 0, os.SEEK_SET)
298 buf = [bytearray(i) for i in [5, 3, 2]] 309 buf = [bytearray(i) for i in [5, 3, 2]]
299 self.assertEqual(posix.readv(fd, buf), 10) 310 self.assertEqual(posix.readv(fd, buf), 10)
300 self.assertEqual([b'test1', b'tt2', b't3'], [bytes(i) for i in buf]) 311 self.assertEqual([b'test1', b'tt2', b't3'], [bytes(i) for i in buf])
312
313 # Issue #20113: empty list of buffers should not crash
314 try:
315 size = posix.readv(fd, [])
316 except OSError:
317 # readv(fd, []) raises OSError(22, "Invalid argument")
318 # on OpenIndiana
319 pass
320 else:
321 self.assertEqual(size, 0)
301 finally: 322 finally:
302 os.close(fd) 323 os.close(fd)
303 324
304 @unittest.skipUnless(hasattr(posix, 'dup'), 325 @unittest.skipUnless(hasattr(posix, 'dup'),
305 'test needs posix.dup()') 326 'test needs posix.dup()')
306 def test_dup(self): 327 def test_dup(self):
307 fp = open(support.TESTFN) 328 fp = open(support.TESTFN)
308 try: 329 try:
309 fd = posix.dup(fp.fileno()) 330 fd = posix.dup(fp.fileno())
310 self.assertIsInstance(fd, int) 331 self.assertIsInstance(fd, int)
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 self.assertTrue(fcntl.fcntl(w, fcntl.F_GETFL) & os.O_NONBLOCK) 609 self.assertTrue(fcntl.fcntl(w, fcntl.F_GETFL) & os.O_NONBLOCK)
589 # try reading from an empty pipe: this should fail, not block 610 # try reading from an empty pipe: this should fail, not block
590 self.assertRaises(OSError, os.read, r, 1) 611 self.assertRaises(OSError, os.read, r, 1)
591 # try a write big enough to fill-up the pipe: this should either 612 # try a write big enough to fill-up the pipe: this should either
592 # fail or perform a partial write, not block 613 # fail or perform a partial write, not block
593 try: 614 try:
594 os.write(w, b'x' * support.PIPE_MAX_SIZE) 615 os.write(w, b'x' * support.PIPE_MAX_SIZE)
595 except OSError: 616 except OSError:
596 pass 617 pass
597 618
619 @support.cpython_only
620 @unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
621 @support.requires_linux_version(2, 6, 27)
622 def test_pipe2_c_limits(self):
598 # Issue 15989 623 # Issue 15989
624 import _testcapi
599 self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1) 625 self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1)
600 self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1) 626 self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1)
601 627
602 @unittest.skipUnless(hasattr(posix, 'utime'), 'test needs posix.utime()') 628 @unittest.skipUnless(hasattr(posix, 'utime'), 'test needs posix.utime()')
603 def test_utime(self): 629 def test_utime(self):
604 now = time.time() 630 now = time.time()
605 posix.utime(support.TESTFN, None) 631 posix.utime(support.TESTFN, None)
606 self.assertRaises(TypeError, posix.utime, support.TESTFN, (None, None)) 632 self.assertRaises(TypeError, posix.utime, support.TESTFN, (None, None))
607 self.assertRaises(TypeError, posix.utime, support.TESTFN, (now, None)) 633 self.assertRaises(TypeError, posix.utime, support.TESTFN, (now, None))
608 self.assertRaises(TypeError, posix.utime, support.TESTFN, (None, now)) 634 self.assertRaises(TypeError, posix.utime, support.TESTFN, (None, now))
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 self.assertListEqual(groups, posix.getgroups()) 1157 self.assertListEqual(groups, posix.getgroups())
1132 1158
1133 def test_main(): 1159 def test_main():
1134 try: 1160 try:
1135 support.run_unittest(PosixTester, PosixGroupsTester) 1161 support.run_unittest(PosixTester, PosixGroupsTester)
1136 finally: 1162 finally:
1137 support.reap_children() 1163 support.reap_children()
1138 1164
1139 if __name__ == '__main__': 1165 if __name__ == '__main__':
1140 test_main() 1166 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+