From 8d470d398007a3124d1d21fa8e2ebc4bcd094adc Mon Sep 17 00:00:00 2001 From: Hal Blackburn Date: Fri, 13 Sep 2024 07:59:53 +0000 Subject: [PATCH] test: verify package can be installed and run We now run an integration test that installs and executes the package in a clean Python environment with the minimum allowed dependency versions. This should ensure that all runtime dependencies are listed, and the min dependency versions work. --- .dockerignore | 1 + .gitignore | 1 + Dockerfile | 29 +++++++++++++++++++++++++++++ docker-bake.hcl | 17 ++++++++++++++++- testing/smoketest/README.md | 0 testing/smoketest/pyproject.toml | 15 +++++++++++++++ testing/smoketest/smoketest.py | 18 ++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 testing/smoketest/README.md create mode 100644 testing/smoketest/pyproject.toml create mode 100644 testing/smoketest/smoketest.py diff --git a/.dockerignore b/.dockerignore index fcb6d1b..16d42a6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ .* **/__pycache__ +**/dist diff --git a/.gitignore b/.gitignore index 42bbd2c..5961c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ **/__pycache__ /htmlcov +**/dist diff --git a/Dockerfile b/Dockerfile index d6da1f1..adbab64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ ARG PYTHON_VER FROM python:${PYTHON_VER:?} AS python-base +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 FROM python-base AS poetry @@ -49,3 +50,31 @@ FROM lint-setup AS lint-mypy RUN --mount=source=.,target=/workspace,rw \ --mount=type=cache,target=.mypy_cache \ poetry run mypy . + + +FROM poetry AS smoketest-pkg-build +RUN --mount=source=testing/smoketest,target=.,rw \ + mkdir /dist && poetry build -o /dist + + +FROM scratch AS smoketest-pkg +COPY --from=smoketest-pkg-build /dist/* . + + +FROM poetry AS v8serialize-pkg-build +RUN --mount=source=.,target=/workspace,rw \ + mkdir /dist && poetry build -o /dist + + +FROM scratch AS v8serialize-pkg +COPY --from=v8serialize-pkg-build /dist/* . + + +FROM python-base AS test-package +RUN python -m venv /env +ENV PATH=/env/bin:$PATH +RUN --mount=from=smoketest-pkg,target=/pkg/smoketest \ + --mount=from=v8serialize-pkg,target=/pkg/v8serialize \ + pip install /pkg/smoketest/*.whl /pkg/v8serialize/*.whl +RUN pip list +RUN python -m smoketest diff --git a/docker-bake.hcl b/docker-bake.hcl index c7dfeca..0eeab21 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -4,10 +4,12 @@ group "default" { // TODO: integration +py_versions = ["3.9", "3.10", "3.11", "3.12", "3.13-rc"] + target "test" { name = "test_py${replace(py, ".", "")}" matrix = { - py = ["3.9", "3.10", "3.11", "3.12", "3.13-rc"], + py = py_versions, } args = { PYTHON_VER = py == "latest" ? "slim" : "${py}-slim" @@ -17,6 +19,19 @@ target "test" { output = ["type=cacheonly"] } +target "test_package" { + name = "test_package_py${replace(py, ".", "")}" + matrix = { + py = py_versions, + } + args = { + PYTHON_VER = py == "latest" ? "slim" : "${py}-slim" + } + target = "test-package" + no-cache-filter = ["test-package"] + output = ["type=cacheonly"] +} + target "lint" { name = "lint-${lint_type}" matrix = { diff --git a/testing/smoketest/README.md b/testing/smoketest/README.md new file mode 100644 index 0000000..e69de29 diff --git a/testing/smoketest/pyproject.toml b/testing/smoketest/pyproject.toml new file mode 100644 index 0000000..85e210c --- /dev/null +++ b/testing/smoketest/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "smoketest" +version = "0.1.0" +description = "A package that depends on v8serialize with the oldest supported dependencies." +authors = ["Your Name "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.9" +v8serialize = "*" +packaging = "<=14.5" # require the oldest version supported by v8serialize + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/testing/smoketest/smoketest.py b/testing/smoketest/smoketest.py new file mode 100644 index 0000000..15662cf --- /dev/null +++ b/testing/smoketest/smoketest.py @@ -0,0 +1,18 @@ +from v8serialize import SerializationFeature, dumps, loads + + +def main() -> None: + msg = "Don't let the smoke out!" + msg_out = loads( + dumps( + "Don't let the smoke out!", + v8_version=SerializationFeature.MaxCompatibility.first_v8_version, + ) + ) + if msg != msg_out: + raise AssertionError("Smoke test failed") + print(msg_out) + + +if __name__ == "__main__": + main()