|
29 | 29 | from test.support.os_helper import TESTFN
|
30 | 30 | from test.support.os_helper import unlink as safe_unlink
|
31 | 31 | from test.support import os_helper
|
32 |
| -from test.support import warnings_helper |
33 | 32 | from test import support
|
34 | 33 | from unittest import mock
|
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 |
| - def test_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 |
| - except ValueError: |
241 |
| - pass |
242 |
| - # try opening in universal newline mode |
243 |
| - t1 = self.writeTmp(b"A\nB\r\nC\rD", mode="wb") |
244 |
| - with warnings_helper.check_warnings(('', DeprecationWarning)): |
245 |
| - fi = FileInput(files=t1, mode="U", encoding="utf-8") |
246 |
| - with warnings_helper.check_warnings(('', DeprecationWarning)): |
247 |
| - lines = list(fi) |
248 |
| - self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"]) |
| 232 | + def test_invalid_opening_mode(self): |
| 233 | + for mode in ('w', 'rU', 'U'): |
| 234 | + with self.subTest(mode=mode): |
| 235 | + with self.assertRaises(ValueError): |
| 236 | + FileInput(mode=mode) |
249 | 237 |
|
250 | 238 | def test_stdin_binary_mode(self):
|
251 | 239 | with mock.patch('sys.stdin') as m_stdin:
|
@@ -380,44 +368,6 @@ def test_empty_files_list_specified_to_constructor(self):
|
380 | 368 | with FileInput(files=[], encoding="utf-8") as fi:
|
381 | 369 | self.assertEqual(fi._files, ('-',))
|
382 | 370 |
|
383 |
| - @warnings_helper.ignore_warnings(category=DeprecationWarning) |
384 |
| - def test__getitem__(self): |
385 |
| - """Tests invoking FileInput.__getitem__() with the current |
386 |
| - line number""" |
387 |
| - t = self.writeTmp("line1\nline2\n") |
388 |
| - with FileInput(files=[t], encoding="utf-8") as fi: |
389 |
| - retval1 = fi[0] |
390 |
| - self.assertEqual(retval1, "line1\n") |
391 |
| - retval2 = fi[1] |
392 |
| - self.assertEqual(retval2, "line2\n") |
393 |
| - |
394 |
| - def test__getitem___deprecation(self): |
395 |
| - t = self.writeTmp("line1\nline2\n") |
396 |
| - with self.assertWarnsRegex(DeprecationWarning, |
397 |
| - r'Use iterator protocol instead'): |
398 |
| - with FileInput(files=[t]) as fi: |
399 |
| - self.assertEqual(fi[0], "line1\n") |
400 |
| - |
401 |
| - @warnings_helper.ignore_warnings(category=DeprecationWarning) |
402 |
| - def test__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 |
| - with FileInput(files=[t], encoding="utf-8") as fi: |
407 |
| - with self.assertRaises(RuntimeError) as cm: |
408 |
| - fi[1] |
409 |
| - self.assertEqual(cm.exception.args, ("accessing lines out of order",)) |
410 |
| - |
411 |
| - @warnings_helper.ignore_warnings(category=DeprecationWarning) |
412 |
| - def test__getitem__eof(self): |
413 |
| - """Tests invoking FileInput.__getitem__() with the line number but at |
414 |
| - end-of-input""" |
415 |
| - t = self.writeTmp('') |
416 |
| - with FileInput(files=[t], encoding="utf-8") as fi: |
417 |
| - with self.assertRaises(IndexError) as cm: |
418 |
| - fi[0] |
419 |
| - self.assertEqual(cm.exception.args, ("end of input reached",)) |
420 |
| - |
421 | 371 | def test_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 |
| - with self.assertWarns(DeprecationWarning): |
1035 |
| - check('rU', ['A\n', 'B\n', 'C\n', 'D\u20ac']) |
1036 |
| - with self.assertWarns(DeprecationWarning): |
1037 |
| - check('U', ['A\n', 'B\n', 'C\n', 'D\u20ac']) |
1038 | 984 | with self.assertRaises(ValueError):
|
1039 | 985 | check('rb', ['A\n', 'B\r\n', 'C\r', 'D\u20ac'])
|
1040 | 986 |
|
|
0 commit comments