[3.12] gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests (GH-119065) (GH-119088)

(cherry picked from commit 0152dc4ff5)
This commit is contained in:
Serhiy Storchaka 2024-05-16 11:04:37 +03:00 committed by GitHub
parent ed395f5c0e
commit 33a9f0ce65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 116 additions and 128 deletions

View file

@ -23,10 +23,9 @@ except ImportError:
from io import BytesIO, StringIO
from fileinput import FileInput, hook_encoded
from pathlib import Path
from test.support import verbose
from test.support.os_helper import TESTFN
from test.support.os_helper import TESTFN, FakePath
from test.support.os_helper import unlink as safe_unlink
from test.support import os_helper
from test import support
@ -478,23 +477,23 @@ class FileInputTests(BaseTests, unittest.TestCase):
self.assertRaises(StopIteration, next, fi)
self.assertEqual(src.linesread, [])
def test_pathlib_file(self):
t1 = Path(self.writeTmp("Pathlib file."))
def test_pathlike_file(self):
t1 = FakePath(self.writeTmp("Path-like file."))
with FileInput(t1, encoding="utf-8") as fi:
line = fi.readline()
self.assertEqual(line, 'Pathlib file.')
self.assertEqual(line, 'Path-like file.')
self.assertEqual(fi.lineno(), 1)
self.assertEqual(fi.filelineno(), 1)
self.assertEqual(fi.filename(), os.fspath(t1))
def test_pathlib_file_inplace(self):
t1 = Path(self.writeTmp('Pathlib file.'))
def test_pathlike_file_inplace(self):
t1 = FakePath(self.writeTmp('Path-like file.'))
with FileInput(t1, inplace=True, encoding="utf-8") as fi:
line = fi.readline()
self.assertEqual(line, 'Pathlib file.')
self.assertEqual(line, 'Path-like file.')
print('Modified %s' % line)
with open(t1, encoding="utf-8") as f:
self.assertEqual(f.read(), 'Modified Pathlib file.\n')
self.assertEqual(f.read(), 'Modified Path-like file.\n')
class MockFileInput: