diff --git a/Containerfile.tests b/Containerfile.tests deleted file mode 100644 index bf51aeb..0000000 --- a/Containerfile.tests +++ /dev/null @@ -1,12 +0,0 @@ -ARG BASE_IMAGE -FROM ${BASE_IMAGE} - -WORKDIR /workdir -COPY . . - -ARG INSTALL_DEPS_CMD -RUN sh -c "${INSTALL_DEPS_CMD}" - -RUN python3 -m pip install tox - -CMD ["tox", "--workdir", "/workdir"] diff --git a/Makefile b/Makefile index 1f38712..0317183 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker) test-image: $(CONTAINER_ENGINE) build --rm \ --tag $(TEST_IMAGE) \ - -f Containerfile.tests \ + -f tests/Containerfile \ --build-arg BASE_IMAGE=$(BASE_IMAGE) \ --build-arg INSTALL_DEPS_CMD="$(INSTALL_DEPS_CMD)" \ . diff --git a/tests/Containerfile b/tests/Containerfile new file mode 100644 index 0000000..ec9f496 --- /dev/null +++ b/tests/Containerfile @@ -0,0 +1,15 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +COPY tests/entrypoint.sh /entrypoint.sh + +WORKDIR /rpm-shim +COPY . . + +ARG INSTALL_DEPS_CMD +RUN sh -c "${INSTALL_DEPS_CMD}" + +RUN python3 -m pip install tox build + +WORKDIR / +ENTRYPOINT ["/entrypoint.sh"] diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh new file mode 100755 index 0000000..7187682 --- /dev/null +++ b/tests/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# fail early +set -e + + +### test import in virtualenvs + +pushd /rpm-shim +tox +popd + + +### test import on local system + +PYTHON=python3 +PLATFORM_PYTHON=/usr/libexec/platform-python +if [ ! -x "${PYTHON}" -a -x "${PLATFORM_PYTHON}" ]; then + # fallback to platform-python + PYTHON="${PLATFORM_PYTHON}" +fi + +${PYTHON} -m build --wheel /rpm-shim +# failure to install is most likely caused by existing RPM bindings, consider it a success +${PYTHON} -m pip install /rpm-shim/dist/*.whl || true +${PYTHON} /rpm-shim/tests/import.py +${PYTHON} -m pip check diff --git a/tests/import.py b/tests/import.py new file mode 100644 index 0000000..006c5d8 --- /dev/null +++ b/tests/import.py @@ -0,0 +1,18 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + +import logging + +# enable debug logging +logging.basicConfig(level=logging.DEBUG) + + +def test(): + import rpm + + # sanity check + print("RPM conf dir:", rpm.expandMacro("%getconfdir")) + + +if __name__ == "__main__": + test() diff --git a/tox.ini b/tox.ini index e7ec710..bc936b6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,14 @@ [tox] envlist = py{36,37,38,39,310,311} skip_missing_interpreters = true -skipsdist = true isolated_build = true [testenv] recreate = true -usedevelop = true sitepackages = false # pip < 19 requires setup.py deps = pip >= 19 setenv = PYTHONDONTWRITEBYTECODE=1 commands = - python -c "import rpm" + python tests/import.py python -m pip check