commit:     af8df08e6c3112d88612f76e53dd238f198c0372
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sun Dec  7 12:39:11 2025 +0000
Commit:     Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sun Dec  7 12:39:11 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=af8df08e

fix(tests): handle pypi and it's ilk for test_remove_py_extension

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>

 tests/test_python_namespaces.py | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/tests/test_python_namespaces.py b/tests/test_python_namespaces.py
index cddc0a6..b501373 100644
--- a/tests/test_python_namespaces.py
+++ b/tests/test_python_namespaces.py
@@ -120,21 +120,22 @@ class test_python_namespaces:
 
 
 def test_remove_py_extension():
-    # no need to mock, python standards intersect.
-    cpy = [
-        x
-        for x in machinery.all_suffixes()
-        if x.startswith(".cpython") or x.startswith(".pypy")
-    ]
-    assert cpy, (
-        f"couldn't find an extension of .cpython per PEP3147.  Is this pypy?  
Known extensions to this python install: {machinery.all_suffixes()}"
-    )
-    cpy = cpy[0]
-    suffix = f".{cpy.rsplit('.')[-1]}"
-    assert suffix in machinery.all_suffixes()  # confirm .so or .dylib is in 
there
-    assert "blah" == remove_py_extension(f"blah{cpy}")
-    assert "blah" == remove_py_extension(f"blah{suffix}")
-    assert f"blah{suffix}" == remove_py_extension(f"blah{suffix}.py"), (
+    """Test to verify remove_py_extension strips the longest suffix."""
+    conflict_long = None
+    for ext in (suffixes := machinery.all_suffixes()):
+        # remember, ext is '.py' or similar. Thus 2- ['', 'py']
+        if len(chunked := ext.split(".")) > 2:
+            if (conflict_short := f".{chunked[-1]}") in suffixes:
+                conflict_long = ext
+                break
+    else:
+        pytest.skip(
+            "The interpretter has no self-conflicting python source 
extensions."
+        )
+
+    assert "blah" == remove_py_extension(f"blah{conflict_long}")
+    assert "blah" == remove_py_extension(f"blah{conflict_short}")
+    assert f"blah{conflict_short}" == 
remove_py_extension(f"blah{conflict_short}.py"), (
         "the code is double stripping suffixes"
     )
     assert None is remove_py_extension("asdf")

Reply via email to