diff options
author | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:14:18 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:14:18 -0800 |
commit | 7fbf6af205939dee36bd679058140620a9efefe2 (patch) | |
tree | 7208d20bacae24a49a701c97189f28a840cb1b02 /Lib/test/test_fileio.py | |
parent | 3b0e4320092ac0504b6670cafaf0301b908c91fc (diff) | |
parent | b23f2a20c4a98dc6d012e9fd9ce36f7c83f79d57 (diff) | |
download | cpython-7fbf6af205939dee36bd679058140620a9efefe2.tar.gz |
Merge issue #28164 and issue #29409
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r-- | Lib/test/test_fileio.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 12f2f119b5..3da210ae19 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -9,7 +9,8 @@ from array import array from weakref import proxy from functools import wraps -from test.support import TESTFN, check_warnings, run_unittest, make_bad_fd, cpython_only +from test.support import (TESTFN, TESTFN_UNICODE, check_warnings, run_unittest, + make_bad_fd, cpython_only) from collections import UserList import _io # C implementation of io @@ -432,6 +433,23 @@ class OtherFileTests: finally: os.unlink(TESTFN) + @unittest.skipIf(sys.getfilesystemencoding() != 'utf-8', + "test only works for utf-8 filesystems") + def testUtf8BytesOpen(self): + # Opening a UTF-8 bytes filename + try: + fn = TESTFN_UNICODE.encode("utf-8") + except UnicodeEncodeError: + self.skipTest('could not encode %r to utf-8' % TESTFN_UNICODE) + f = self.FileIO(fn, "w") + try: + f.write(b"abc") + f.close() + with open(TESTFN_UNICODE, "rb") as f: + self.assertEqual(f.read(), b"abc") + finally: + os.unlink(TESTFN_UNICODE) + def testConstructorHandlesNULChars(self): fn_with_NUL = 'foo\0bar' self.assertRaises(ValueError, self.FileIO, fn_with_NUL, 'w') |