Skip to content

Commit 63b4b42

Browse files
committed
Fix problems with link assertions on Windows
1 parent 83dab61 commit 63b4b42

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

setuptools/tests/test_editable_install.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import stat
23
import sys
34
import subprocess
45
import platform
@@ -318,7 +319,7 @@ def test_packages(self, tmp_path):
318319
assert mod1.a == 42
319320
assert mod2.a == 43
320321
expected = str((tmp_path / "src1/pkg1/subpkg").resolve())
321-
self.assert_path(subpkg, expected)
322+
assert_path(subpkg, expected)
322323

323324
def test_namespace(self, tmp_path):
324325
files = {"pkg": {"__init__.py": "a = 13", "text.txt": "abc"}}
@@ -337,7 +338,7 @@ def test_namespace(self, tmp_path):
337338
text = importlib_resources.files(pkg) / "text.txt"
338339

339340
expected = str((tmp_path / "pkg").resolve())
340-
self.assert_path(pkg, expected)
341+
assert_path(pkg, expected)
341342
assert pkg.a == 13
342343

343344
# Make sure resources can also be found
@@ -365,16 +366,10 @@ def test_combine_namespaces(self, tmp_path, monkeypatch):
365366
mod2 = import_module("ns.mod2")
366367

367368
expected = str((tmp_path / "src1/ns/pkg1").resolve())
368-
self.assert_path(pkgA, expected)
369+
assert_path(pkgA, expected)
369370
assert pkgA.a == 13
370371
assert mod2.b == 37
371372

372-
def assert_path(self, pkg, expected):
373-
if pkg.__path__:
374-
path = next(iter(pkg.__path__), None)
375-
if path:
376-
assert str(Path(path).resolve()) == expected
377-
378373

379374
def test_pkg_roots(tmp_path):
380375
"""This test focus in getting a particular implementation detail right.
@@ -545,7 +540,7 @@ def test_generated_tree(self, tmp_path):
545540

546541
mod1 = next(build.glob("**/mod1.py"))
547542
expected = tmp_path / "src/mypkg/mod1.py"
548-
assert str(mod1.resolve()) == str(expected.resolve())
543+
assert_link_to(mod1, expected)
549544

550545
with pytest.raises(AssertionError): # ignore problems caused by #3260
551546
# Ensure excluded packages don't show up
@@ -595,3 +590,24 @@ def install_project(name, venv, tmp_path, files):
595590
opts = ["--no-build-isolation"] # force current version of setuptools
596591
venv.run(["python", "-m", "pip", "install", "-e", str(project), *opts])
597592
return project
593+
594+
595+
# ---- Assertion Helpers ----
596+
597+
598+
def assert_path(pkg, expected):
599+
# __path__ is not guaranteed to exist, so we have to account for that
600+
if pkg.__path__:
601+
path = next(iter(pkg.__path__), None)
602+
if path:
603+
assert str(Path(path).resolve()) == expected
604+
605+
606+
def assert_link_to(file: Path, other: Path):
607+
if file.is_symlink():
608+
assert str(file.resolve()) == str(other.resolve())
609+
else:
610+
file_stat = file.stat()
611+
other_stat = other.stat()
612+
assert file_stat[stat.ST_INO] == other_stat[stat.ST_INO]
613+
assert file_stat[stat.ST_DEV] == other_stat[stat.ST_DEV]

0 commit comments

Comments
 (0)