Skip to content

Commit

Permalink
Fixes py.path.local.samefile in Python 3 on Windows
Browse files Browse the repository at this point in the history
Python 3 on Windows contains a working implementation
of os.path.samefile that should be used.
  • Loading branch information
nicoddemus committed Dec 26, 2019
1 parent 1e99d20 commit e4fe48a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Unreleased
==========

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

- ``py.path.local.samefile`` now works correctly in Python 3 on Windows when dealing with symlinks.

1.8.0 (2019-02-21)
==================

Expand Down
4 changes: 2 additions & 2 deletions py/_path/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def samefile(self, other):
other = abspath(other)
if self == other:
return True
if iswin32:
return False # there is no samefile
if not hasattr(os.path, "samefile"):
return False
return py.error.checked_call(
os.path.samefile, self.strpath, other)

Expand Down
11 changes: 11 additions & 0 deletions testing/path/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ def test_samefile(tmpdir):
p2 = p.__class__(str(p).upper())
assert p1.samefile(p2)

@pytest.mark.skipif(not hasattr(os, "symlink"), reason="os.symlink not available")
def test_samefile_symlink(tmpdir):
p1 = tmpdir.ensure("foo.txt")
p2 = tmpdir.join("linked.txt")
try:
os.symlink(str(p1), str(p2))
except OSError as e:
# on Windows this might fail if the user doesn't have special symlink permissions
pytest.skip(str(e.args[0]))

assert p1.samefile(p2)

def test_listdir_single_arg(tmpdir):
tmpdir.ensure("hello")
Expand Down

0 comments on commit e4fe48a

Please sign in to comment.