1
1
import os
2
+ import stat
2
3
import sys
3
4
import subprocess
4
5
import platform
@@ -318,7 +319,7 @@ def test_packages(self, tmp_path):
318
319
assert mod1 .a == 42
319
320
assert mod2 .a == 43
320
321
expected = str ((tmp_path / "src1/pkg1/subpkg" ).resolve ())
321
- self . assert_path (subpkg , expected )
322
+ assert_path (subpkg , expected )
322
323
323
324
def test_namespace (self , tmp_path ):
324
325
files = {"pkg" : {"__init__.py" : "a = 13" , "text.txt" : "abc" }}
@@ -337,7 +338,7 @@ def test_namespace(self, tmp_path):
337
338
text = importlib_resources .files (pkg ) / "text.txt"
338
339
339
340
expected = str ((tmp_path / "pkg" ).resolve ())
340
- self . assert_path (pkg , expected )
341
+ assert_path (pkg , expected )
341
342
assert pkg .a == 13
342
343
343
344
# Make sure resources can also be found
@@ -365,16 +366,10 @@ def test_combine_namespaces(self, tmp_path, monkeypatch):
365
366
mod2 = import_module ("ns.mod2" )
366
367
367
368
expected = str ((tmp_path / "src1/ns/pkg1" ).resolve ())
368
- self . assert_path (pkgA , expected )
369
+ assert_path (pkgA , expected )
369
370
assert pkgA .a == 13
370
371
assert mod2 .b == 37
371
372
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
-
378
373
379
374
def test_pkg_roots (tmp_path ):
380
375
"""This test focus in getting a particular implementation detail right.
@@ -545,7 +540,7 @@ def test_generated_tree(self, tmp_path):
545
540
546
541
mod1 = next (build .glob ("**/mod1.py" ))
547
542
expected = tmp_path / "src/mypkg/mod1.py"
548
- assert str (mod1 . resolve ()) == str ( expected . resolve () )
543
+ assert_link_to (mod1 , expected )
549
544
550
545
# Ensure excluded packages don't show up
551
546
assert next (build .glob ("**/subpackage" ), None ) is None
@@ -592,3 +587,24 @@ def install_project(name, venv, tmp_path, files):
592
587
opts = ["--no-build-isolation" ] # force current version of setuptools
593
588
venv .run (["python" , "-m" , "pip" , "install" , "-e" , str (project ), * opts ])
594
589
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