Skip to content

Commit 192abed

Browse files
dura0okcursoragent
andcommitted
gh-154690: Test ensure_distinct_paths() fallback when resolve() fails
Cover AttributeError and OSError from resolve(), which fall back to the lexical self-copy check. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b5c0284 commit 192abed

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,17 @@ def test_copy_dir_into_itself_via_symlink(self):
14811481
self.assertRaises(OSError, source.copy, target, follow_symlinks=False)
14821482
self.assertFalse((source / 'copyC').exists())
14831483

1484+
def test_copy_dir_into_itself_when_resolve_fails(self):
1485+
# Fall back to lexical comparison if resolve() is missing or errors.
1486+
base = self.cls(self.base)
1487+
source = base / 'dirC'
1488+
target = source / 'copyC'
1489+
for exc in (AttributeError, OSError):
1490+
with self.subTest(exc=exc):
1491+
with mock.patch.object(self.cls, 'resolve', side_effect=exc):
1492+
self.assertRaises(OSError, source.copy, target)
1493+
self.assertFalse(target.exists())
1494+
14841495
@needs_symlinks
14851496
def test_copy_directory_symlink_to_existing_symlink(self):
14861497
base = self.cls(self.base)

0 commit comments

Comments
 (0)