Skip to content

Commit e4fe48a

Browse files
committed
Fixes py.path.local.samefile in Python 3 on Windows
Python 3 on Windows contains a working implementation of os.path.samefile that should be used.
1 parent 1e99d20 commit e4fe48a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
Unreleased
22
==========
33

4-
- handle ``FileNotFoundError`` when trying to import pathlib in ``path.common``
4+
- Handle ``FileNotFoundError`` when trying to import pathlib in ``path.common``
55
on Python 3.4 (#207).
66

7+
- ``py.path.local.samefile`` now works correctly in Python 3 on Windows when dealing with symlinks.
8+
79
1.8.0 (2019-02-21)
810
==================
911

py/_path/local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ def samefile(self, other):
196196
other = abspath(other)
197197
if self == other:
198198
return True
199-
if iswin32:
200-
return False # there is no samefile
199+
if not hasattr(os.path, "samefile"):
200+
return False
201201
return py.error.checked_call(
202202
os.path.samefile, self.strpath, other)
203203

testing/path/test_local.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,17 @@ def test_samefile(tmpdir):
704704
p2 = p.__class__(str(p).upper())
705705
assert p1.samefile(p2)
706706

707+
@pytest.mark.skipif(not hasattr(os, "symlink"), reason="os.symlink not available")
708+
def test_samefile_symlink(tmpdir):
709+
p1 = tmpdir.ensure("foo.txt")
710+
p2 = tmpdir.join("linked.txt")
711+
try:
712+
os.symlink(str(p1), str(p2))
713+
except OSError as e:
714+
# on Windows this might fail if the user doesn't have special symlink permissions
715+
pytest.skip(str(e.args[0]))
716+
717+
assert p1.samefile(p2)
707718

708719
def test_listdir_single_arg(tmpdir):
709720
tmpdir.ensure("hello")

0 commit comments

Comments
 (0)