Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(48122)

Delta Between Two Patch Sets: Lib/test/test_fileinput.py

Issue 25788: fileinput.hook_encoded has no way to pass arguments to codecs
Left Patch Set: Created 3 years, 7 months ago
Right Patch Set: Created 3 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« Doc/whatsnew/3.6.rst ('K') | « Lib/fileinput.py ('k') | Misc/ACKS » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 ''' 1 '''
2 Tests for fileinput module. 2 Tests for fileinput module.
3 Nick Mathewson 3 Nick Mathewson
4 ''' 4 '''
5 import os 5 import os
6 import sys 6 import sys
7 import re 7 import re
8 import fileinput 8 import fileinput
9 import collections 9 import collections
10 import builtins 10 import builtins
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 890
891 args, kwargs = fake_open.last_invocation 891 args, kwargs = fake_open.last_invocation
892 self.assertIs(args[0], filename) 892 self.assertIs(args[0], filename)
893 self.assertIs(args[1], mode) 893 self.assertIs(args[1], mode)
894 self.assertIs(kwargs.pop('encoding'), encoding) 894 self.assertIs(kwargs.pop('encoding'), encoding)
895 self.assertIs(kwargs.pop('errors'), errors) 895 self.assertIs(kwargs.pop('errors'), errors)
896 self.assertFalse(kwargs) 896 self.assertFalse(kwargs)
897 897
898 def test_errors(self): 898 def test_errors(self):
899 with open(TESTFN, 'wb') as f: 899 with open(TESTFN, 'wb') as f:
900 # UTF-7 is a convenient, seldom used encoding
storchaka 2016/04/25 21:03:01 Unrelated comment.
901 f.write(b'\x80abc') 900 f.write(b'\x80abc')
902 self.addCleanup(safe_unlink, TESTFN) 901 self.addCleanup(safe_unlink, TESTFN)
903 902
904 def check(errors, expected_lines): 903 def check(errors, expected_lines):
905 with FileInput(files=TESTFN, mode='r', 904 with FileInput(files=TESTFN, mode='r',
906 openhook=hook_encoded('utf-8', errors=errors)) as fi: 905 openhook=hook_encoded('utf-8', errors=errors)) as fi:
907 lines = list(fi) 906 lines = list(fi)
908 self.assertEqual(lines, expected_lines) 907 self.assertEqual(lines, expected_lines)
909 908
910 check('ignore', ['abc']) 909 check('ignore', ['abc'])
911 with self.assertRaises(UnicodeDecodeError): 910 with self.assertRaises(UnicodeDecodeError):
912 check('strict', ['abc']) 911 check('strict', ['abc'])
913 check('replace', ['\ufffdabc']) 912 check('replace', ['\ufffdabc'])
914 check('backslashreplace', ['\\x80abc']) 913 check('backslashreplace', ['\\x80abc'])
915 914
storchaka 2016/04/25 21:03:01 Trailing whitespaces.
916 def test_modes(self): 915 def test_modes(self):
917 with open(TESTFN, 'wb') as f: 916 with open(TESTFN, 'wb') as f:
918 # UTF-7 is a convenient, seldom used encoding 917 # UTF-7 is a convenient, seldom used encoding
919 f.write(b'A\nB\r\nC\rD+IKw-') 918 f.write(b'A\nB\r\nC\rD+IKw-')
920 self.addCleanup(safe_unlink, TESTFN) 919 self.addCleanup(safe_unlink, TESTFN)
921 920
922 def check(mode, expected_lines): 921 def check(mode, expected_lines):
923 with FileInput(files=TESTFN, mode=mode, 922 with FileInput(files=TESTFN, mode=mode,
924 openhook=hook_encoded('utf-7')) as fi: 923 openhook=hook_encoded('utf-7')) as fi:
925 lines = list(fi) 924 lines = list(fi)
(...skipping 10 matching lines...) Expand all
936 935
937 class MiscTest(unittest.TestCase): 936 class MiscTest(unittest.TestCase):
938 937
939 def test_all(self): 938 def test_all(self):
940 blacklist = {'DEFAULT_BUFSIZE'} 939 blacklist = {'DEFAULT_BUFSIZE'}
941 support.check__all__(self, fileinput, blacklist=blacklist) 940 support.check__all__(self, fileinput, blacklist=blacklist)
942 941
943 942
944 if __name__ == "__main__": 943 if __name__ == "__main__":
945 unittest.main() 944 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+