Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test installation and import also on local system #4

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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