From: Serhiy Storchaka Date: Wed, 26 Feb 2014 19:03:19 +0000 (+0200) Subject: Added tests for issue #20501. X-Git-Tag: v3.4.1rc1~233^2~189 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9fff849dbfe31642fac2e58d42e0ef73891f5c04;p=thirdparty%2FPython%2Fcpython.git Added tests for issue #20501. --- 9fff849dbfe31642fac2e58d42e0ef73891f5c04 diff --cc Lib/test/test_fileinput.py index db6082cb12e6,a7624d3c3d97..a537bc8c7cb7 --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@@ -837,6 -853,40 +855,26 @@@ class Test_hook_encoded(unittest.TestCa self.assertIs(kwargs.pop('encoding'), encoding) self.assertFalse(kwargs) + def test_modes(self): + # Unlikely UTF-7 is locale encoding + with open(TESTFN, 'wb') as f: + f.write(b'A\nB\r\nC\rD+IKw-') + self.addCleanup(safe_unlink, TESTFN) + + def check(mode, expected_lines): + with FileInput(files=TESTFN, mode=mode, + openhook=hook_encoded('utf-7')) as fi: + lines = list(fi) + self.assertEqual(lines, expected_lines) + + check('r', ['A\n', 'B\n', 'C\n', 'D\u20ac']) - check('rU', ['A\n', 'B\n', 'C\n', 'D\u20ac']) - check('U', ['A\n', 'B\n', 'C\n', 'D\u20ac']) ++ with self.assertWarns(DeprecationWarning): ++ check('rU', ['A\n', 'B\n', 'C\n', 'D\u20ac']) ++ with self.assertWarns(DeprecationWarning): ++ check('U', ['A\n', 'B\n', 'C\n', 'D\u20ac']) + with self.assertRaises(ValueError): + check('rb', ['A\n', 'B\r\n', 'C\r', 'D\u20ac']) + -def test_main(): - run_unittest( - BufferSizesTests, - FileInputTests, - Test_fileinput_input, - Test_fileinput_close, - Test_fileinput_nextfile, - Test_fileinput_filename, - Test_fileinput_lineno, - Test_fileinput_filelineno, - Test_fileinput_fileno, - Test_fileinput_isfirstline, - Test_fileinput_isstdin, - Test_hook_compressed, - Test_hook_encoded, - ) if __name__ == "__main__": - test_main() + unittest.main()