diff --git a/samples/azure-pack/tests/test-sample.py b/samples/azure-pack/tests/test-sample.py new file mode 100644 index 0000000..56695b3 --- /dev/null +++ b/samples/azure-pack/tests/test-sample.py @@ -0,0 +1,22 @@ +import os, sys +EXPECT_PREFIX = os.getenv("BUILD_PREFIX") +print("EXPECT_PREFIX =", EXPECT_PREFIX) +sys.path.insert(0, os.path.join(EXPECT_PREFIX, "azure-pack")) + + +import azure +import azure.identity + +print("azure.identity.__spec__ =", azure.identity.__spec__) +assert azure.identity.__spec__.origin.startswith(EXPECT_PREFIX) +assert type(azure.identity.__spec__.loader).__name__ == "DllPackLoader_azure" + +import cryptography +print("cryptography.__spec__ =", cryptography.__spec__) +assert cryptography.__spec__.origin.startswith(EXPECT_PREFIX) +assert type(cryptography.__spec__.loader).__name__ == "DllPackLoader_cryptography" + +import cryptography.hazmat.bindings._rust as cryptography_rust +print("cryptography_rust.__spec__ =", cryptography_rust.__spec__) +assert cryptography_rust.__spec__.origin.startswith(EXPECT_PREFIX) +assert type(cryptography_rust.__spec__.loader).__name__ == "ExtensionFileLoader" diff --git a/tests/test_samples.py b/tests/test_samples.py index 835f607..bdc9e73 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -1,3 +1,4 @@ +import importlib.machinery import os import pytest import shutil @@ -49,6 +50,14 @@ def fresh_copy(sample, tmp_path): return TMP +def rglob_ext(root): + root = Path(root) + exts = set() + for suffix in importlib.machinery.EXTENSION_SUFFIXES: + exts.update(root.rglob(f"*{suffix}")) + return exts + + @all_samples def test_sample_build_inplace(sample, tmp_path): maybe_skip(sample) @@ -62,17 +71,25 @@ def test_sample_build_inplace(sample, tmp_path): [sys.executable, "-m", "pip", "install", "-r", DIR / "requirements.txt", "--target", PACKAGES], env=env, ) - env["PYTHONPATH"] = f"{PACKAGES}{os.pathsep}{env['PYTHONPATH']}" + env["PYTHONPATH"] = os.pathsep.join(str(s) for s in [PACKAGES, env["PYTHONPATH"]] if s) subprocess.check_call( [sys.executable, "-m", "pymsbuild"], cwd=DIR, env=env, ) - modules = {f.relative_to(DIR) for f in DIR.rglob("*.pyd")} + modules = {f.relative_to(DIR) for f in rglob_ext(DIR)} without_temp = {f for f in modules if f.parts[0] != "build"} assert without_temp + env["BUILD_PREFIX"] = str(DIR) + env["PYTHONPATH"] = "" + subprocess.check_call( + [sys.executable, DIR / "tests/test-sample.py"], + cwd=DIR, + env=env, + ) + @all_samples def test_sample_sdist(sample, tmp_path): maybe_skip(sample)