Skip to content

Commit

Permalink
Fix problems with link assertions on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 13, 2022
1 parent bda7a62 commit 891711f
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions setuptools/tests/test_editable_install.py
@@ -1,4 +1,5 @@
import os
import stat
import sys
import subprocess
import platform
Expand Down Expand Up @@ -318,7 +319,7 @@ def test_packages(self, tmp_path):
assert mod1.a == 42
assert mod2.a == 43
expected = str((tmp_path / "src1/pkg1/subpkg").resolve())
self.assert_path(subpkg, expected)
assert_path(subpkg, expected)

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

expected = str((tmp_path / "pkg").resolve())
self.assert_path(pkg, expected)
assert_path(pkg, expected)
assert pkg.a == 13

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

expected = str((tmp_path / "src1/ns/pkg1").resolve())
self.assert_path(pkgA, expected)
assert_path(pkgA, expected)
assert pkgA.a == 13
assert mod2.b == 37

def assert_path(self, pkg, expected):
if pkg.__path__:
path = next(iter(pkg.__path__), None)
if path:
assert str(Path(path).resolve()) == expected


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

mod1 = next(build.glob("**/mod1.py"))
expected = tmp_path / "src/mypkg/mod1.py"
assert str(mod1.resolve()) == str(expected.resolve())
assert_link_to(mod1, expected)

# Ensure excluded packages don't show up
assert next(build.glob("**/subpackage"), None) is None
Expand Down Expand Up @@ -592,3 +587,24 @@ def install_project(name, venv, tmp_path, files):
opts = ["--no-build-isolation"] # force current version of setuptools
venv.run(["python", "-m", "pip", "install", "-e", str(project), *opts])
return project


# ---- Assertion Helpers ----


def assert_path(pkg, expected):
# __path__ is not guaranteed to exist, so we have to account for that
if pkg.__path__:
path = next(iter(pkg.__path__), None)
if path:
assert str(Path(path).resolve()) == expected


def assert_link_to(file: Path, other: Path):
if file.is_symlink():
assert str(file.resolve()) == str(other.resolve())
else:
file_stat = file.stat()
other_stat = other.stat()
assert file_stat[stat.ST_INO] == other_stat[stat.ST_INO]
assert file_stat[stat.ST_DEV] == other_stat[stat.ST_DEV]

0 comments on commit 891711f

Please sign in to comment.