diff options
Diffstat (limited to 'Lib/test/test_fileinput.py')
| -rw-r--r-- | Lib/test/test_fileinput.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py index 014f19e6cb..d5edf74938 100644 --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -24,8 +24,11 @@ from io import BytesIO, StringIO from fileinput import FileInput, hook_encoded from pathlib import Path -from test.support import verbose, TESTFN, check_warnings -from test.support import unlink as safe_unlink +from test.support import verbose +from test.support.os_helper import TESTFN +from test.support.os_helper import unlink as safe_unlink +from test.support import os_helper +from test.support import warnings_helper from test import support from unittest import mock @@ -39,7 +42,7 @@ class BaseTests: # temp file's name. def writeTmp(self, content, *, mode='w'): # opening in text mode is the default fd, name = tempfile.mkstemp() - self.addCleanup(support.unlink, name) + self.addCleanup(os_helper.unlink, name) with open(fd, mode) as f: f.write(content) return name @@ -234,9 +237,9 @@ class FileInputTests(BaseTests, unittest.TestCase): pass # try opening in universal newline mode t1 = self.writeTmp(b"A\nB\r\nC\rD", mode="wb") - with check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): fi = FileInput(files=t1, mode="U") - with check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): lines = list(fi) self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"]) @@ -353,7 +356,7 @@ class FileInputTests(BaseTests, unittest.TestCase): with FileInput(files=[]) as fi: self.assertEqual(fi._files, ('-',)) - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test__getitem__(self): """Tests invoking FileInput.__getitem__() with the current line number""" @@ -371,7 +374,7 @@ class FileInputTests(BaseTests, unittest.TestCase): with FileInput(files=[t]) as fi: self.assertEqual(fi[0], "line1\n") - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test__getitem__invalid_key(self): """Tests invoking FileInput.__getitem__() with an index unequal to the line number""" @@ -381,7 +384,7 @@ class FileInputTests(BaseTests, unittest.TestCase): fi[1] self.assertEqual(cm.exception.args, ("accessing lines out of order",)) - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test__getitem__eof(self): """Tests invoking FileInput.__getitem__() with the line number but at end-of-input""" @@ -400,7 +403,7 @@ class FileInputTests(BaseTests, unittest.TestCase): os_unlink_replacement = UnconditionallyRaise(OSError) try: t = self.writeTmp("\n") - self.addCleanup(support.unlink, t + '.bak') + self.addCleanup(safe_unlink, t + '.bak') with FileInput(files=[t], inplace=True) as fi: next(fi) # make sure the file is opened os.unlink = os_unlink_replacement |
