diff options
author | Barney Gale <barney.gale@gmail.com> | 2022-02-02 12:38:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 12:38:25 (GMT) |
commit | 08f8301b21648d58d053e1a513db8ed32fbf37dd (patch) | |
tree | 5653595bd4eb375f7931e22a3cacd47bfdcf25dd /Lib/test | |
parent | 187930f74c44e460ba09c60ba5d9bb4fac543d8f (diff) | |
download | cpython-08f8301b21648d58d053e1a513db8ed32fbf37dd.zip cpython-08f8301b21648d58d053e1a513db8ed32fbf37dd.tar.gz cpython-08f8301b21648d58d053e1a513db8ed32fbf37dd.tar.bz2 |
bpo-43012: remove `pathlib._Accessor` (GH-25701)
Per Pitrou:
> The original intent for the “accessor” thing was to have a variant that did all accesses under a filesystem tree in a race condition-free way using openat and friends. It turned out to be much too hairy to actually implement, so was entirely abandoned, but the accessor abstraction was left there.
https://discuss.python.org/t/make-pathlib-extensible/3428/2
Accessors are:
- Lacking any internal purpose - '_NormalAccessor' is the only implementation
- Lacking any firm conceptual difference to `Path` objects themselves (inc. subclasses)
- Non-public, i.e. underscore prefixed - '_Accessor' and '_NormalAccessor'
- Unofficially used to implement customized `Path` objects, but once once [bpo-24132]() is addressed there will be a supported route for that.
This patch preserves all existing behaviour.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_pathlib.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 3fbf1d1..5e46b4f 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1,3 +1,4 @@ +import contextlib import collections.abc import io import os @@ -1459,7 +1460,7 @@ class _BasePathTest(object): def test_absolute_common(self): P = self.cls - with mock.patch("pathlib._normal_accessor.getcwd") as getcwd: + with mock.patch("os.getcwd") as getcwd: getcwd.return_value = BASE # Simple relative paths. @@ -1738,21 +1739,18 @@ class _BasePathTest(object): # Patching is needed to avoid relying on the filesystem # to return the order of the files as the error will not # happen if the symlink is the last item. - - with mock.patch("os.scandir") as scandir: - scandir.return_value = sorted(os.scandir(base)) + real_scandir = os.scandir + def my_scandir(path): + with real_scandir(path) as scandir_it: + entries = list(scandir_it) + entries.sort(key=lambda entry: entry.name) + return contextlib.nullcontext(entries) + + with mock.patch("os.scandir", my_scandir): self.assertEqual(len(set(base.glob("*"))), 3) - - subdir.mkdir() - - with mock.patch("os.scandir") as scandir: - scandir.return_value = sorted(os.scandir(base)) + subdir.mkdir() self.assertEqual(len(set(base.glob("*"))), 4) - - subdir.chmod(000) - - with mock.patch("os.scandir") as scandir: - scandir.return_value = sorted(os.scandir(base)) + subdir.chmod(000) self.assertEqual(len(set(base.glob("*"))), 4) def _check_resolve(self, p, expected, strict=True): @@ -2199,6 +2197,7 @@ class _BasePathTest(object): p = self.cls(BASE, 'dirCPC%d' % pattern_num) self.assertFalse(p.exists()) + real_mkdir = os.mkdir def my_mkdir(path, mode=0o777): path = str(path) # Emulate another process that would create the directory @@ -2207,15 +2206,15 @@ class _BasePathTest(object): # function is called at most 5 times (dirCPC/dir1/dir2, # dirCPC/dir1, dirCPC, dirCPC/dir1, dirCPC/dir1/dir2). if pattern.pop(): - os.mkdir(path, mode) # From another process. + real_mkdir(path, mode) # From another process. concurrently_created.add(path) - os.mkdir(path, mode) # Our real call. + real_mkdir(path, mode) # Our real call. pattern = [bool(pattern_num & (1 << n)) for n in range(5)] concurrently_created = set() p12 = p / 'dir1' / 'dir2' try: - with mock.patch("pathlib._normal_accessor.mkdir", my_mkdir): + with mock.patch("os.mkdir", my_mkdir): p12.mkdir(parents=True, exist_ok=False) except FileExistsError: self.assertIn(str(p12), concurrently_created) @@ -2676,7 +2675,7 @@ class WindowsPathTest(_BasePathTest, unittest.TestCase): self.assertEqual(str(P(share + 'a\\b').absolute()), share + 'a\\b') # UNC relative paths. - with mock.patch("pathlib._normal_accessor.getcwd") as getcwd: + with mock.patch("os.getcwd") as getcwd: getcwd.return_value = share self.assertEqual(str(P().absolute()), share) |