Skip to content

Commit 891711f

Browse files
committed
Fix problems with link assertions on Windows
1 parent bda7a62 commit 891711f

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
# Ensure excluded packages don't show up
551546
assert next(build.glob("**/subpackage"), None) is None
@@ -592,3 +587,24 @@ def install_project(name, venv, tmp_path, files):
592587
opts = ["--no-build-isolation"] # force current version of setuptools
593588
venv.run(["python", "-m", "pip", "install", "-e", str(project), *opts])
594589
return project
590+
591+
592+
# ---- Assertion Helpers ----
593+
594+
595+
def assert_path(pkg, expected):
596+
# __path__ is not guaranteed to exist, so we have to account for that
597+
if pkg.__path__:
598+
path = next(iter(pkg.__path__), None)
599+
if path:
600+
assert str(Path(path).resolve()) == expected
601+
602+
603+
def assert_link_to(file: Path, other: Path):
604+
if file.is_symlink():
605+
assert str(file.resolve()) == str(other.resolve())
606+
else:
607+
file_stat = file.stat()
608+
other_stat = other.stat()
609+
assert file_stat[stat.ST_INO] == other_stat[stat.ST_INO]
610+
assert file_stat[stat.ST_DEV] == other_stat[stat.ST_DEV]

0 commit comments

Comments
 (0)