pathlib tests: annotate tests needing symlinks with decorator (#114625)

Add `@needs_symlinks` decorator for tests that require symlink support in
the path class.

Also add `@needs_windows` and `@needs_posix` decorators for tests that
require a specific a specific path flavour. These aren't much used yet, but
will be later.
This commit is contained in:
Barney Gale 2024-01-26 22:29:28 +00:00 committed by GitHub
parent b5c7c84673
commit 7a9727e10c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 48 deletions

View file

@ -19,6 +19,7 @@ from test.support import set_recursion_limit
from test.support import os_helper
from test.support.os_helper import TESTFN, FakePath
from test.test_pathlib import test_pathlib_abc
from test.test_pathlib.test_pathlib_abc import needs_posix, needs_windows, needs_symlinks
try:
import grp, pwd
@ -26,11 +27,6 @@ except ImportError:
grp = pwd = None
only_nt = unittest.skipIf(os.name != 'nt',
'test requires a Windows-compatible system')
only_posix = unittest.skipIf(os.name == 'nt',
'test requires a POSIX-compatible system')
root_in_posix = False
if hasattr(os, 'geteuid'):
root_in_posix = (os.geteuid() == 0)
@ -1268,7 +1264,7 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
self.assertEqual(p.stat().st_mode, new_mode)
# On Windows, os.chmod does not follow symlinks (issue #15411)
@only_posix
@needs_posix
@os_helper.skip_unless_working_chmod
def test_chmod_follow_symlinks_true(self):
p = self.cls(self.base) / 'linkA'
@ -1537,7 +1533,7 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
self.cls('/').resolve().mkdir(exist_ok=True)
self.cls('/').resolve().mkdir(parents=True, exist_ok=True)
@only_nt # XXX: not sure how to test this on POSIX.
@needs_windows # XXX: not sure how to test this on POSIX.
def test_mkdir_with_unknown_drive(self):
for d in 'ZYXWVUTSRQPONMLKJIHGFEDCBA':
p = self.cls(d + ':\\')
@ -1602,9 +1598,8 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
self.assertNotIn(str(p12), concurrently_created)
self.assertTrue(p.exists())
@needs_symlinks
def test_symlink_to(self):
if not self.can_symlink:
self.skipTest("symlinks required")
P = self.cls(self.base)
target = P / 'fileA'
# Symlinking a path target.
@ -1848,7 +1843,7 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
self.assertEqual(expect, set(p.rglob(FakePath(pattern))))
@only_posix
@unittest.skipIf(os.name == 'nt', 'test requires a POSIX-compatible system')
class PosixPathTest(PathTest, PurePosixPathTest):
cls = pathlib.PosixPath
@ -2024,7 +2019,7 @@ class PosixPathTest(PathTest, PurePosixPathTest):
self.assertEqual(P.from_uri('file:' + pathname2url('//foo/bar')), P('//foo/bar'))
@only_nt
@unittest.skipIf(os.name != 'nt', 'test requires a Windows-compatible system')
class WindowsPathTest(PathTest, PureWindowsPathTest):
cls = pathlib.WindowsPath