Skip to content

Fixes py.path.local.samefile in Python 3 on Windows #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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