diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-09-04 18:52:14 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-09-04 18:52:14 (GMT) |
commit | e619427f7eb17c370f31c6d4f7625eda8a0e9dce (patch) | |
tree | 7c14183bbff4e2935a6173f287ae210080b337d5 /Lib/test/test_fileio.py | |
parent | 73821c47dcf56b02a30ab9ab524f0c0fc2875c22 (diff) | |
parent | e93b63b74b101c65807af7d9311de70012a2e49d (diff) | |
download | cpython-e619427f7eb17c370f31c6d4f7625eda8a0e9dce.zip cpython-e619427f7eb17c370f31c6d4f7625eda8a0e9dce.tar.gz cpython-e619427f7eb17c370f31c6d4f7625eda8a0e9dce.tar.bz2 |
Issue #18876: The FileIO.mode attribute now better reflects the actual mode under which the file was opened.
Patch by Erik Bray.
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r-- | Lib/test/test_fileio.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 0ccbda2..e678769 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -304,7 +304,7 @@ class OtherFileTests(unittest.TestCase): finally: os.unlink(TESTFN) - def testModeStrings(self): + def testInvalidModeStrings(self): # check invalid mode strings for mode in ("", "aU", "wU+", "rw", "rt"): try: @@ -315,6 +315,21 @@ class OtherFileTests(unittest.TestCase): f.close() self.fail('%r is an invalid file mode' % mode) + def testModeStrings(self): + # test that the mode attribute is correct for various mode strings + # given as init args + try: + for modes in [('w', 'wb'), ('wb', 'wb'), ('wb+', 'rb+'), + ('w+b', 'rb+'), ('a', 'ab'), ('ab', 'ab'), + ('ab+', 'ab+'), ('a+b', 'ab+'), ('r', 'rb'), + ('rb', 'rb'), ('rb+', 'rb+'), ('r+b', 'rb+')]: + # read modes are last so that TESTFN will exist first + with _FileIO(TESTFN, modes[0]) as f: + self.assertEqual(f.mode, modes[1]) + finally: + if os.path.exists(TESTFN): + os.unlink(TESTFN) + def testUnicodeOpen(self): # verify repr works for unicode too f = _FileIO(str(TESTFN), "w") |