Skip to content

Commit

Permalink
test: verify package can be installed and run
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
h4l committed Sep 14, 2024
1 parent dd6f65a commit 8d470d3
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.*
**/__pycache__
**/dist
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

**/__pycache__
/htmlcov
**/dist
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
17 changes: 16 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = {
Expand Down
Empty file added testing/smoketest/README.md
Empty file.
15 changes: 15 additions & 0 deletions testing/smoketest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <you@example.com>"]
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"
18 changes: 18 additions & 0 deletions testing/smoketest/smoketest.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8d470d3

Please sign in to comment.