mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
GH-110109: Adjust test_pathlib_abc
imports to ease backporting (#113411)
This very boring patch reduces the number of changes needed in `test_pathlib_abc.py` when backporting to the external `pathlib_abc` package.
This commit is contained in:
parent
daa658aba5
commit
d1c711e757
1 changed files with 13 additions and 12 deletions
|
@ -2,19 +2,20 @@ import collections.abc
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
import pathlib
|
|
||||||
import posixpath
|
|
||||||
import stat
|
import stat
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from pathlib._abc import UnsupportedOperation, PurePathBase, PathBase
|
||||||
|
import posixpath
|
||||||
|
|
||||||
from test.support import set_recursion_limit
|
from test.support import set_recursion_limit
|
||||||
from test.support.os_helper import TESTFN
|
from test.support.os_helper import TESTFN
|
||||||
|
|
||||||
|
|
||||||
class UnsupportedOperationTest(unittest.TestCase):
|
class UnsupportedOperationTest(unittest.TestCase):
|
||||||
def test_is_notimplemented(self):
|
def test_is_notimplemented(self):
|
||||||
self.assertTrue(issubclass(pathlib.UnsupportedOperation, NotImplementedError))
|
self.assertTrue(issubclass(UnsupportedOperation, NotImplementedError))
|
||||||
self.assertTrue(isinstance(pathlib.UnsupportedOperation(), NotImplementedError))
|
self.assertTrue(isinstance(UnsupportedOperation(), NotImplementedError))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -23,7 +24,7 @@ class UnsupportedOperationTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class PurePathBaseTest(unittest.TestCase):
|
class PurePathBaseTest(unittest.TestCase):
|
||||||
cls = pathlib._abc.PurePathBase
|
cls = PurePathBase
|
||||||
|
|
||||||
def test_magic_methods(self):
|
def test_magic_methods(self):
|
||||||
P = self.cls
|
P = self.cls
|
||||||
|
@ -42,7 +43,7 @@ class PurePathBaseTest(unittest.TestCase):
|
||||||
self.assertIs(self.cls.pathmod, posixpath)
|
self.assertIs(self.cls.pathmod, posixpath)
|
||||||
|
|
||||||
|
|
||||||
class DummyPurePath(pathlib._abc.PurePathBase):
|
class DummyPurePath(PurePathBase):
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, DummyPurePath):
|
if not isinstance(other, DummyPurePath):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
@ -637,12 +638,12 @@ class DummyPurePathTest(unittest.TestCase):
|
||||||
#
|
#
|
||||||
|
|
||||||
class PathBaseTest(PurePathBaseTest):
|
class PathBaseTest(PurePathBaseTest):
|
||||||
cls = pathlib._abc.PathBase
|
cls = PathBase
|
||||||
|
|
||||||
def test_unsupported_operation(self):
|
def test_unsupported_operation(self):
|
||||||
P = self.cls
|
P = self.cls
|
||||||
p = self.cls()
|
p = self.cls()
|
||||||
e = pathlib.UnsupportedOperation
|
e = UnsupportedOperation
|
||||||
self.assertRaises(e, p.stat)
|
self.assertRaises(e, p.stat)
|
||||||
self.assertRaises(e, p.lstat)
|
self.assertRaises(e, p.lstat)
|
||||||
self.assertRaises(e, p.exists)
|
self.assertRaises(e, p.exists)
|
||||||
|
@ -684,7 +685,7 @@ class PathBaseTest(PurePathBaseTest):
|
||||||
self.assertRaises(e, p.as_uri)
|
self.assertRaises(e, p.as_uri)
|
||||||
|
|
||||||
def test_as_uri_common(self):
|
def test_as_uri_common(self):
|
||||||
e = pathlib.UnsupportedOperation
|
e = UnsupportedOperation
|
||||||
self.assertRaises(e, self.cls().as_uri)
|
self.assertRaises(e, self.cls().as_uri)
|
||||||
|
|
||||||
def test_fspath_common(self):
|
def test_fspath_common(self):
|
||||||
|
@ -709,7 +710,7 @@ class DummyPathIO(io.BytesIO):
|
||||||
super().close()
|
super().close()
|
||||||
|
|
||||||
|
|
||||||
class DummyPath(pathlib._abc.PathBase):
|
class DummyPath(PathBase):
|
||||||
"""
|
"""
|
||||||
Simple implementation of PathBase that keeps files and directories in
|
Simple implementation of PathBase that keeps files and directories in
|
||||||
memory.
|
memory.
|
||||||
|
@ -1325,7 +1326,7 @@ class DummyPathTest(DummyPurePathTest):
|
||||||
def test_readlink_unsupported(self):
|
def test_readlink_unsupported(self):
|
||||||
P = self.cls(self.base)
|
P = self.cls(self.base)
|
||||||
p = P / 'fileA'
|
p = P / 'fileA'
|
||||||
with self.assertRaises(pathlib.UnsupportedOperation):
|
with self.assertRaises(UnsupportedOperation):
|
||||||
q.readlink(p)
|
q.readlink(p)
|
||||||
|
|
||||||
def _check_resolve(self, p, expected, strict=True):
|
def _check_resolve(self, p, expected, strict=True):
|
||||||
|
@ -1648,7 +1649,7 @@ class DummyPathTest(DummyPurePathTest):
|
||||||
# Resolve relative paths.
|
# Resolve relative paths.
|
||||||
try:
|
try:
|
||||||
self.cls().absolute()
|
self.cls().absolute()
|
||||||
except pathlib.UnsupportedOperation:
|
except UnsupportedOperation:
|
||||||
return
|
return
|
||||||
old_path = os.getcwd()
|
old_path = os.getcwd()
|
||||||
os.chdir(self.base)
|
os.chdir(self.base)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue