diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2013-09-04 18:46:33 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-09-04 18:46:33 (GMT) |
| commit | 213fec4bff53e24626172a9963e4e90d62a3e082 (patch) | |
| tree | 43ded3d049f8561455bdc20851ac14ce27516dfc /Lib | |
| parent | ab70a7dc41d697ba597aa271f2aea191f6734932 (diff) | |
| download | cpython-213fec4bff53e24626172a9963e4e90d62a3e082.zip cpython-213fec4bff53e24626172a9963e4e90d62a3e082.tar.gz cpython-213fec4bff53e24626172a9963e4e90d62a3e082.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')
| -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 b74cec2..e7955cc 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -305,7 +305,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: @@ -316,6 +316,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") |
