summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib/test_pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-26 22:29:28 (GMT)
committerGitHub <noreply@github.com>2024-01-26 22:29:28 (GMT)
commit7a9727e10c14a82e8e20f5b85e368a6f937db203 (patch)
treea195b05685ff1a39e42177477ce643026496f8ff /Lib/test/test_pathlib/test_pathlib.py
parentb5c7c84673b96bfdd7c877521a970f7a4beafece (diff)
downloadcpython-7a9727e10c14a82e8e20f5b85e368a6f937db203.zip
cpython-7a9727e10c14a82e8e20f5b85e368a6f937db203.tar.gz
cpython-7a9727e10c14a82e8e20f5b85e368a6f937db203.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib/test_pathlib.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py
index 2da3afdd..2cef3b2 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -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