Skip to content

Commit

Permalink
Add runtime test for samples (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
zooba authored Dec 20, 2023
1 parent c4c1045 commit 6dfe56b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
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

0 comments on commit 6dfe56b

Please sign in to comment.