|
29 | 29 | fromtest.support.os_helperimportTESTFN |
30 | 30 | fromtest.support.os_helperimportunlinkassafe_unlink |
31 | 31 | fromtest.supportimportos_helper |
32 | | -fromtest.supportimportwarnings_helper |
33 | 32 | fromtestimportsupport |
34 | 33 | fromunittestimportmock |
35 | 34 |
|
@@ -230,22 +229,11 @@ def test_fileno(self): |
230 | 229 | line=list(fi) |
231 | 230 | self.assertEqual(fi.fileno(),-1) |
232 | 231 |
|
233 | | -# TODO: RUSTPYTHON |
234 | | -@unittest.expectedFailure |
235 | | -deftest_opening_mode(self): |
236 | | -try: |
237 | | -# invalid mode, should raise ValueError |
238 | | -fi=FileInput(mode="w",encoding="utf-8") |
239 | | -self.fail("FileInput should reject invalid mode argument") |
240 | | -exceptValueError: |
241 | | -pass |
242 | | -# try opening in universal newline mode |
243 | | -t1=self.writeTmp(b"A\nB\r\nC\rD",mode="wb") |
244 | | -withwarnings_helper.check_warnings(('',DeprecationWarning)): |
245 | | -fi=FileInput(files=t1,mode="U",encoding="utf-8") |
246 | | -withwarnings_helper.check_warnings(('',DeprecationWarning)): |
247 | | -lines=list(fi) |
248 | | -self.assertEqual(lines, ["A\n","B\n","C\n","D"]) |
| 232 | +deftest_invalid_opening_mode(self): |
| 233 | +formodein ('w','rU','U'): |
| 234 | +withself.subTest(mode=mode): |
| 235 | +withself.assertRaises(ValueError): |
| 236 | +FileInput(mode=mode) |
249 | 237 |
|
250 | 238 | deftest_stdin_binary_mode(self): |
251 | 239 | withmock.patch('sys.stdin')asm_stdin: |
@@ -380,44 +368,6 @@ def test_empty_files_list_specified_to_constructor(self): |
380 | 368 | withFileInput(files=[],encoding="utf-8")asfi: |
381 | 369 | self.assertEqual(fi._files, ('-',)) |
382 | 370 |
|
383 | | -@warnings_helper.ignore_warnings(category=DeprecationWarning) |
384 | | -deftest__getitem__(self): |
385 | | -"""Tests invoking FileInput.__getitem__() with the current |
386 | | - line number""" |
387 | | -t=self.writeTmp("line1\nline2\n") |
388 | | -withFileInput(files=[t],encoding="utf-8")asfi: |
389 | | -retval1=fi[0] |
390 | | -self.assertEqual(retval1,"line1\n") |
391 | | -retval2=fi[1] |
392 | | -self.assertEqual(retval2,"line2\n") |
393 | | - |
394 | | -deftest__getitem___deprecation(self): |
395 | | -t=self.writeTmp("line1\nline2\n") |
396 | | -withself.assertWarnsRegex(DeprecationWarning, |
397 | | -r'Use iterator protocol instead'): |
398 | | -withFileInput(files=[t])asfi: |
399 | | -self.assertEqual(fi[0],"line1\n") |
400 | | - |
401 | | -@warnings_helper.ignore_warnings(category=DeprecationWarning) |
402 | | -deftest__getitem__invalid_key(self): |
403 | | -"""Tests invoking FileInput.__getitem__() with an index unequal to |
404 | | - the line number""" |
405 | | -t=self.writeTmp("line1\nline2\n") |
406 | | -withFileInput(files=[t],encoding="utf-8")asfi: |
407 | | -withself.assertRaises(RuntimeError)ascm: |
408 | | -fi[1] |
409 | | -self.assertEqual(cm.exception.args, ("accessing lines out of order",)) |
410 | | - |
411 | | -@warnings_helper.ignore_warnings(category=DeprecationWarning) |
412 | | -deftest__getitem__eof(self): |
413 | | -"""Tests invoking FileInput.__getitem__() with the line number but at |
414 | | - end-of-input""" |
415 | | -t=self.writeTmp('') |
416 | | -withFileInput(files=[t],encoding="utf-8")asfi: |
417 | | -withself.assertRaises(IndexError)ascm: |
418 | | -fi[0] |
419 | | -self.assertEqual(cm.exception.args, ("end of input reached",)) |
420 | | - |
421 | 371 | deftest_nextfile_oserror_deleting_backup(self): |
422 | 372 | """Tests invoking FileInput.nextfile() when the attempt to delete |
423 | 373 | the backup file would raise OSError. This error is expected to be |
@@ -1031,10 +981,6 @@ def check(mode, expected_lines): |
1031 | 981 | self.assertEqual(lines,expected_lines) |
1032 | 982 |
|
1033 | 983 | check('r', ['A\n','B\n','C\n','D\u20ac']) |
1034 | | -withself.assertWarns(DeprecationWarning): |
1035 | | -check('rU', ['A\n','B\n','C\n','D\u20ac']) |
1036 | | -withself.assertWarns(DeprecationWarning): |
1037 | | -check('U', ['A\n','B\n','C\n','D\u20ac']) |
1038 | 984 | withself.assertRaises(ValueError): |
1039 | 985 | check('rb', ['A\n','B\r\n','C\r','D\u20ac']) |
1040 | 986 |
|
|