| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 errno | 5 import errno |
| 6 import unittest | 6 import unittest |
| 7 from array import array | 7 from array import array |
| 8 from weakref import proxy | 8 from weakref import proxy |
| 9 from functools import wraps | 9 from functools import wraps |
| 10 | 10 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 self.assertRaises(TypeError, _FileIO, "1", 0, 0) | 391 self.assertRaises(TypeError, _FileIO, "1", 0, 0) |
| 392 | 392 |
| 393 def testWarnings(self): | 393 def testWarnings(self): |
| 394 with check_warnings(quiet=True) as w: | 394 with check_warnings(quiet=True) as w: |
| 395 self.assertEqual(w.warnings, []) | 395 self.assertEqual(w.warnings, []) |
| 396 self.assertRaises(TypeError, _FileIO, []) | 396 self.assertRaises(TypeError, _FileIO, []) |
| 397 self.assertEqual(w.warnings, []) | 397 self.assertEqual(w.warnings, []) |
| 398 self.assertRaises(ValueError, _FileIO, "/some/invalid/name", "rt") | 398 self.assertRaises(ValueError, _FileIO, "/some/invalid/name", "rt") |
| 399 self.assertEqual(w.warnings, []) | 399 self.assertEqual(w.warnings, []) |
| 400 | 400 |
| 401 def test_create_fail(self): | |
|
Benjamin Peterson
2012/01/08 16:16:10
These should really be in test_io.
| |
| 402 # 'x' mode fails if file is existing | |
| 403 with open(TESTFN, 'w'): | |
| 404 pass | |
| 405 try: | |
| 406 self.assertRaises(IOError, _FileIO, TESTFN, 'x') | |
|
Benjamin Peterson
2012/01/08 16:16:10
You should check that it's an OSError with the exp
| |
| 407 finally: | |
| 408 os.unlink(TESTFN) | |
| 409 | |
| 410 def test_create_writes(self): | |
| 411 # 'x' mode opens for writing | |
| 412 with open(TESTFN, 'xb') as f: | |
| 413 f.write(b"spam") | |
| 414 with open(TESTFN, 'rb') as f: | |
| 415 self.assertEqual(b"spam", f.read()) | |
|
Charles-François Natali
2011/12/30 12:49:33
You should remove the file.
| |
| 401 | 416 |
| 402 def test_main(): | 417 def test_main(): |
| 403 # Historically, these tests have been sloppy about removing TESTFN. | 418 # Historically, these tests have been sloppy about removing TESTFN. |
| 404 # So get rid of it no matter what. | 419 # So get rid of it no matter what. |
| 405 try: | 420 try: |
| 406 run_unittest(AutoFileTests, OtherFileTests) | 421 run_unittest(AutoFileTests, OtherFileTests) |
| 407 finally: | 422 finally: |
| 408 if os.path.exists(TESTFN): | 423 if os.path.exists(TESTFN): |
| 409 os.unlink(TESTFN) | 424 os.unlink(TESTFN) |
| 410 | 425 |
| 411 if __name__ == '__main__': | 426 if __name__ == '__main__': |
| 412 test_main() | 427 test_main() |
| OLD | NEW |