summaryrefslogtreecommitdiff
path: root/Lib/test/test_fileinput.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-04-27 23:13:46 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-04-27 23:13:46 +0300
commit159dc3b31845ae04523bf11f9557fcac603114bc (patch)
treec96761dfa82da5eb8dd64f44231e2bcd457a2850 /Lib/test/test_fileinput.py
parent65618e2e7b127feddaf33e10ed087653e5f6c857 (diff)
downloadcpython-159dc3b31845ae04523bf11f9557fcac603114bc.tar.gz
Issue #25788: fileinput.hook_encoded() now supports an "errors" argument
for passing to open. Original patch by Joseph Hackman.
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r--Lib/test/test_fileinput.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index 4f67c25f90..565633fccc 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -945,7 +945,8 @@ class Test_hook_encoded(unittest.TestCase):
def test(self):
encoding = object()
- result = fileinput.hook_encoded(encoding)
+ errors = object()
+ result = fileinput.hook_encoded(encoding, errors=errors)
fake_open = InvocationRecorder()
original_open = builtins.open
@@ -963,8 +964,26 @@ class Test_hook_encoded(unittest.TestCase):
self.assertIs(args[0], filename)
self.assertIs(args[1], mode)
self.assertIs(kwargs.pop('encoding'), encoding)
+ self.assertIs(kwargs.pop('errors'), errors)
self.assertFalse(kwargs)
+ def test_errors(self):
+ with open(TESTFN, 'wb') as f:
+ f.write(b'\x80abc')
+ self.addCleanup(safe_unlink, TESTFN)
+
+ def check(errors, expected_lines):
+ with FileInput(files=TESTFN, mode='r',
+ openhook=hook_encoded('utf-8', errors=errors)) as fi:
+ lines = list(fi)
+ self.assertEqual(lines, expected_lines)
+
+ check('ignore', ['abc'])
+ with self.assertRaises(UnicodeDecodeError):
+ check('strict', ['abc'])
+ check('replace', ['\ufffdabc'])
+ check('backslashreplace', ['\\x80abc'])
+
def test_modes(self):
with open(TESTFN, 'wb') as f:
# UTF-7 is a convenient, seldom used encoding