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

Side by Side Diff: Lib/test/test_fileio.py

Issue 18876: Problems with files opened in append mode with io module
Patch Set: Created 6 years, 4 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | Modules/_io/fileio.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Adapted from test_file.py by Daniel Stutzbach 1 # Adapted from test_file.py by Daniel Stutzbach
2 2
3 import sys 3 import sys
4 import os 4 import os
5 import io 5 import io
6 import errno 6 import errno
7 import unittest 7 import unittest
8 from array import array 8 from array import array
9 from weakref import proxy 9 from weakref import proxy
10 from functools import wraps 10 from functools import wraps
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 if sys.platform != "darwin" and \ 297 if sys.platform != "darwin" and \
298 'bsd' not in sys.platform and \ 298 'bsd' not in sys.platform and \
299 not sys.platform.startswith('sunos'): 299 not sys.platform.startswith('sunos'):
300 # Somehow /dev/tty appears seekable on some BSDs 300 # Somehow /dev/tty appears seekable on some BSDs
301 self.assertEqual(f.seekable(), False) 301 self.assertEqual(f.seekable(), False)
302 self.assertEqual(f.isatty(), True) 302 self.assertEqual(f.isatty(), True)
303 f.close() 303 f.close()
304 finally: 304 finally:
305 os.unlink(TESTFN) 305 os.unlink(TESTFN)
306 306
307 def testModeStrings(self): 307 def testInvalidModeStrings(self):
308 # check invalid mode strings 308 # check invalid mode strings
309 for mode in ("", "aU", "wU+", "rw", "rt"): 309 for mode in ("", "aU", "wU+", "rw", "rt"):
310 try: 310 try:
311 f = _FileIO(TESTFN, mode) 311 f = _FileIO(TESTFN, mode)
312 except ValueError: 312 except ValueError:
313 pass 313 pass
314 else: 314 else:
315 f.close() 315 f.close()
316 self.fail('%r is an invalid file mode' % mode) 316 self.fail('%r is an invalid file mode' % mode)
317
318 def testModeStrings(self):
319 # test that the mode attribute is correct for various mode strings
320 # given as init args
321 try:
322 for modes in [('w', 'wb'), ('wb', 'wb'), ('wb+', 'rb+'),
323 ('w+b', 'rb+'), ('a', 'ab'), ('ab', 'ab'),
324 ('ab+', 'ab+'), ('a+b', 'ab+'), ('r', 'rb'),
325 ('rb', 'rb'), ('rb+', 'rb+'), ('r+b', 'rb+')]:
326 # read modes are last so that TESTFN will exist first
327 with _FileIO(TESTFN, modes[0]) as f:
328 self.assertEqual(f.mode, modes[1])
329 finally:
330 if os.path.exists(TESTFN):
331 os.unlink(TESTFN)
317 332
318 def testUnicodeOpen(self): 333 def testUnicodeOpen(self):
319 # verify repr works for unicode too 334 # verify repr works for unicode too
320 f = _FileIO(str(TESTFN), "w") 335 f = _FileIO(str(TESTFN), "w")
321 f.close() 336 f.close()
322 os.unlink(TESTFN) 337 os.unlink(TESTFN)
323 338
324 def testBytesOpen(self): 339 def testBytesOpen(self):
325 # Opening a bytes filename 340 # Opening a bytes filename
326 try: 341 try:
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 # Historically, these tests have been sloppy about removing TESTFN. 469 # Historically, these tests have been sloppy about removing TESTFN.
455 # So get rid of it no matter what. 470 # So get rid of it no matter what.
456 try: 471 try:
457 run_unittest(AutoFileTests, OtherFileTests) 472 run_unittest(AutoFileTests, OtherFileTests)
458 finally: 473 finally:
459 if os.path.exists(TESTFN): 474 if os.path.exists(TESTFN):
460 os.unlink(TESTFN) 475 os.unlink(TESTFN)
461 476
462 if __name__ == '__main__': 477 if __name__ == '__main__':
463 test_main() 478 test_main()
OLDNEW
« no previous file with comments | « no previous file | Modules/_io/fileio.c » ('j') | no next file with comments »

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