[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

@ -63,16 +63,10 @@ class TestLowLevelInternals(unittest.TestCase):
tempfile._infer_return_type(b'', None, '')
def test_infer_return_type_pathlib(self):
self.assertIs(str, tempfile._infer_return_type(pathlib.Path('/')))
self.assertIs(str, tempfile._infer_return_type(os_helper.FakePath('/')))
def test_infer_return_type_pathlike(self):
class Path:
def __init__(self, path):
self.path = path
def __fspath__(self):
return self.path
Path = os_helper.FakePath
self.assertIs(str, tempfile._infer_return_type(Path('/')))
self.assertIs(bytes, tempfile._infer_return_type(Path(b'/')))
self.assertIs(str, tempfile._infer_return_type('', Path('')))
@ -443,7 +437,7 @@ class TestMkstempInner(TestBadTempdir, BaseTestCase):
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir).write(b"blat")
self.do_create(dir=pathlib.Path(dir)).write(b"blat")
self.do_create(dir=os_helper.FakePath(dir)).write(b"blat")
finally:
support.gc_collect() # For PyPy or other GCs.
os.rmdir(dir)
@ -681,7 +675,7 @@ class TestMkstemp(BaseTestCase):
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir)
self.do_create(dir=pathlib.Path(dir))
self.do_create(dir=os_helper.FakePath(dir))
finally:
os.rmdir(dir)
@ -782,7 +776,7 @@ class TestMkdtemp(TestBadTempdir, BaseTestCase):
dir = tempfile.mkdtemp()
try:
os.rmdir(self.do_create(dir=dir))
os.rmdir(self.do_create(dir=pathlib.Path(dir)))
os.rmdir(self.do_create(dir=os_helper.FakePath(dir)))
finally:
os.rmdir(dir)