Skip to content

Commit 9a219c6

Browse files
committed
Lib: Add pathlib test for missing symlink support
This adds a test case to test_pathlib.py to test the NotImplementedError raised when symlink support is not present on the system. Also add the missing @staticmethod decorator to the function definition in pathlib.py for that error path. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
1 parent 2eb0150 commit 9a219c6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/pathlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ def link_to(self, target):
435435
if supports_symlinks:
436436
symlink = os.symlink
437437
else:
438+
@staticmethod
438439
def symlink(a, b, target_is_directory):
439440
raise NotImplementedError("symlink() not available on this system")
440441
else:

Lib/test/test_pathlib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,15 @@ def test_symlink_to(self):
20212021
self.assertTrue(link.is_dir())
20222022
self.assertTrue(list(link.iterdir()))
20232023

2024+
@unittest.skipIf(support.can_symlink(), "symlink support is present")
2025+
def test_symlink_to_not_implemented(self):
2026+
P = self.cls(BASE)
2027+
target = P / 'fileA'
2028+
# Symlinking a path target.
2029+
link = P / 'dirA' / 'linkAA'
2030+
with self.assertRaises(NotImplementedError):
2031+
link.symlink_to(target)
2032+
20242033
def test_is_dir(self):
20252034
P = self.cls(BASE)
20262035
self.assertTrue((P / 'dirA').is_dir())

0 commit comments

Comments
 (0)