mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
bpo-32964: Reuse a testing implementation of the path protocol in tests. (GH-5930)
(cherry picked from commit b21d155f57
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
0e06be836c
commit
a13b65422a
11 changed files with 70 additions and 103 deletions
|
@ -3,7 +3,7 @@ import os
|
|||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
from test.support import TestFailed
|
||||
from test.support import TestFailed, FakePath
|
||||
from test import support, test_genericpath
|
||||
from tempfile import TemporaryFile
|
||||
|
||||
|
@ -459,18 +459,9 @@ class PathLikeTests(unittest.TestCase):
|
|||
|
||||
path = ntpath
|
||||
|
||||
class PathLike:
|
||||
def __init__(self, path=''):
|
||||
self.path = path
|
||||
def __fspath__(self):
|
||||
if isinstance(self.path, BaseException):
|
||||
raise self.path
|
||||
else:
|
||||
return self.path
|
||||
|
||||
def setUp(self):
|
||||
self.file_name = support.TESTFN.lower()
|
||||
self.file_path = self.PathLike(support.TESTFN)
|
||||
self.file_path = FakePath(support.TESTFN)
|
||||
self.addCleanup(support.unlink, self.file_name)
|
||||
with open(self.file_name, 'xb', 0) as file:
|
||||
file.write(b"test_ntpath.PathLikeTests")
|
||||
|
@ -485,7 +476,7 @@ class PathLikeTests(unittest.TestCase):
|
|||
self.assertPathEqual(self.path.isabs)
|
||||
|
||||
def test_path_join(self):
|
||||
self.assertEqual(self.path.join('a', self.PathLike('b'), 'c'),
|
||||
self.assertEqual(self.path.join('a', FakePath('b'), 'c'),
|
||||
self.path.join('a', 'b', 'c'))
|
||||
|
||||
def test_path_split(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue