Skip to content

Commit

Permalink
Test installation and import also on local system (#4)
Browse files Browse the repository at this point in the history
Note that `python3 -m build` doesn't work with rootless podman, I can't
figure out why ☹️
  • Loading branch information
nforro authored Feb 15, 2023
2 parents 5317d3d + 940a5f2 commit e1fd0a9
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
12 changes: 0 additions & 12 deletions Containerfile.tests

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)" \
.
Expand Down
15 changes: 15 additions & 0 deletions tests/Containerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions tests/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions tests/import.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1fd0a9

Please sign in to comment.