Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime test for samples #79

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions samples/azure-pack/tests/test-sample.py
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 19 additions & 2 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.machinery
import os
import pytest
import shutil
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down