|
| 1 | +"""Exercise built wheels from a separate consumer environment.""" |
| 2 | + |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +import subprocess |
| 6 | +import sys |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | + |
| 12 | +def _run(*, args: list[str | Path], cwd: Path) -> None: |
| 13 | + """Run a local tool, failing the test if it fails.""" |
| 14 | + # Commands use a local executable and fixed options or built wheel paths. |
| 15 | + _ = subprocess.run(args=args, cwd=cwd, check=True) # noqa: S603 |
| 16 | + |
| 17 | + |
| 18 | +def test_installed_suite( |
| 19 | + *, tmp_path: Path, monkeypatch: pytest.MonkeyPatch |
| 20 | +) -> None: |
| 21 | + """Collect without an implementation, then run the Flask adapter.""" |
| 22 | + consumer = Path(__file__).resolve().parent |
| 23 | + repository = consumer.parent.parent |
| 24 | + dist = tmp_path / "dist" |
| 25 | + environment = tmp_path / "venv" |
| 26 | + uv = shutil.which(cmd="uv") |
| 27 | + assert uv is not None |
| 28 | + monkeypatch.delenv(name="PYTHONPATH", raising=False) |
| 29 | + |
| 30 | + _run( |
| 31 | + args=[uv, "build", "--all-packages", "--wheel", "--out-dir", dist], |
| 32 | + cwd=repository, |
| 33 | + ) |
| 34 | + _run( |
| 35 | + args=[uv, "venv", "--python", sys.executable, environment], |
| 36 | + cwd=tmp_path, |
| 37 | + ) |
| 38 | + python = environment / ( |
| 39 | + "Scripts/python.exe" if sys.platform == "win32" else "bin/python" |
| 40 | + ) |
| 41 | + suite = next(dist.glob(pattern="vws_mock_contract_tests-*.whl")) |
| 42 | + _run(args=[uv, "pip", "install", "--python", python, suite], cwd=tmp_path) |
| 43 | + for filename in ( |
| 44 | + "pytest.ini", |
| 45 | + "dependency_checks.py", |
| 46 | + "contract_checks.py", |
| 47 | + ): |
| 48 | + _ = shutil.copyfile(src=consumer / filename, dst=tmp_path / filename) |
| 49 | + |
| 50 | + _run( |
| 51 | + args=[ |
| 52 | + python, |
| 53 | + "-m", |
| 54 | + "pytest", |
| 55 | + "-p", |
| 56 | + "dependency_checks", |
| 57 | + "-p", |
| 58 | + "vws_mock_contract_tests.fixtures.plugin", |
| 59 | + "--pyargs", |
| 60 | + "vws_mock_contract_tests", |
| 61 | + "--collect-only", |
| 62 | + "-q", |
| 63 | + ], |
| 64 | + cwd=tmp_path, |
| 65 | + ) |
| 66 | + _run( |
| 67 | + args=[ |
| 68 | + uv, |
| 69 | + "pip", |
| 70 | + "install", |
| 71 | + "--python", |
| 72 | + python, |
| 73 | + *dist.glob(pattern="*.whl"), |
| 74 | + ], |
| 75 | + cwd=tmp_path, |
| 76 | + ) |
| 77 | + _run( |
| 78 | + args=[ |
| 79 | + python, |
| 80 | + "-m", |
| 81 | + "pytest", |
| 82 | + "-p", |
| 83 | + "contract_checks", |
| 84 | + "-p", |
| 85 | + "vws_mock_contract_tests.fixtures.plugin", |
| 86 | + "-p", |
| 87 | + "vws_mock_test_backends.vuforia_backends", |
| 88 | + "--pyargs", |
| 89 | + os.environ.get( |
| 90 | + key="CONTRACT_TEST_TARGET", |
| 91 | + default="vws_mock_contract_tests.database_summary", |
| 92 | + ), |
| 93 | + "--skip-backend=real", |
| 94 | + "--skip-backend=mock", |
| 95 | + "-q", |
| 96 | + ], |
| 97 | + cwd=tmp_path, |
| 98 | + ) |
0 commit comments