URL: https://github.com/freeipa/freeipa/pull/618
Author: tiran
 Title: #618: Tox testing support for client wheel packages
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/618/head:pr618
git checkout pr618
From 794f76e8526ac11fa063357b2c7bb662b01befe4 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Thu, 17 Nov 2016 16:43:17 +0100
Subject: [PATCH] tox testing support for client wheel packages

Add tox infrastructure to test client wheel packages workflow:

* build client packages
* install client packages
* ipa-run-tests --ipaclient-unittests under Python 2 and 3
* pylint of client packages under Python 2 and 3
* placeholder packages work as expected

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 .gitignore               |  2 ++
 .tox-install.sh          | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
 Makefile.am              |  6 ++--
 configure.ac             |  1 +
 freeipa.spec.in          |  3 ++
 ipatests/conftest.py     |  4 ++-
 pypi/test_placeholder.py | 47 ++++++++++++++++++++++++
 tox.ini                  | 55 ++++++++++++++++++++++++++++
 8 files changed, 209 insertions(+), 3 deletions(-)
 create mode 100755 .tox-install.sh
 create mode 100644 pypi/test_placeholder.py
 create mode 100644 tox.ini

diff --git a/.gitignore b/.gitignore
index 8941fd8..8b57dbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,6 +61,8 @@ freeipa2-dev-doc
 # Root directory
 /freeipa.spec
 /dist/
+/.tox/
+/.cache/
 /*/dist/
 /RELEASE
 /rpmbuild/
diff --git a/.tox-install.sh b/.tox-install.sh
new file mode 100755
index 0000000..8f9d221
--- /dev/null
+++ b/.tox-install.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+set -ex
+
+FLAVOR="$1"
+ENVPYTHON="$2"
+ENVSITEPACKAGESDIR="$3"
+# 3...end are package requirements
+shift 3
+
+TOXINIDIR="$(cd "$(dirname "$0")" && pwd)"
+
+# sanity checks
+if [ ! -x "${ENVPYTHON}" ]; then
+    echo "${ENVPYTHON}: no such executable"
+    exit 1
+fi
+
+if [ ! -d "${ENVSITEPACKAGESDIR}" ]; then
+    echo "${ENVSITEPACKAGESDIR}: no such directory"
+    exit 2
+fi
+
+if [ ! -f "${TOXINIDIR}/tox.ini" ]; then
+    echo "${TOXINIDIR}: no such directory"
+    exit 3
+fi
+
+# https://pip.pypa.io/en/stable/user_guide/#environment-variables
+export PIP_CACHE_DIR="${TOXINIDIR}/.tox/cache"
+mkdir -p "${PIP_CACHE_DIR}"
+
+DISTBUNDLE="${TOXINIDIR}/dist/bundle"
+mkdir -p "${DISTBUNDLE}"
+
+DISTPYPI="${TOXINIDIR}/dist/pypi"
+mkdir -p "${DISTPYPI}"
+
+# create configure
+pushd "${TOXINIDIR}"
+if [ ! -f "configure" ]; then
+    autoreconf -i -f
+fi
+# (re)create Makefile
+./configure --disable-server
+popd
+
+case $FLAVOR in
+wheel_bundle)
+    # copy pylint plugin
+    cp "${TOXINIDIR}/pylint_plugins.py" "${ENVSITEPACKAGESDIR}"
+
+    # build packages and bundles
+    make -C "${TOXINIDIR}" \
+        wheel_bundle \
+        PYTHON="${ENVPYTHON}" \
+        IPA_EXTRA_WHEELS="$*"
+
+    # chdir to prevent local .egg-info from messing up pip
+    pushd "${ENVSITEPACKAGESDIR}"
+
+    # Install packages with dist/bundle/ as extra source for wheels while ignoring
+    # upstream Python Package Index.
+    $ENVPYTHON -m pip install \
+        --no-index \
+        --disable-pip-version-check \
+        --constraint "${TOXINIDIR}/.wheelconstraints" \
+        --find-links "${DISTBUNDLE}" \
+        $@
+
+    popd
+    ;;
+pypi_packages)
+    # build packages and bundles
+    make -C "${TOXINIDIR}" \
+        pypi_packages \
+        PYTHON="${ENVPYTHON}"
+
+    # chdir to prevent local .egg-info from messing up pip
+    pushd "${ENVSITEPACKAGESDIR}"
+
+    # Install packages from dist/pypi
+    $ENVPYTHON -m pip install \
+        --disable-pip-version-check \
+        --constraint "${TOXINIDIR}/.wheelconstraints" \
+        --find-links "${DISTPYPI}" \
+        $@
+
+    popd
+    ;;
+*)
+    echo "Unknown install flavor $FLAVOR"
+    exit 1
+    ;;
+esac
diff --git a/Makefile.am b/Makefile.am
index ab69f49..7608dfa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,6 +57,7 @@ EXTRA_DIST = .mailmap \
 clean-local:
 	rm -rf "$(RPMBUILD)"
 	rm -rf "$(top_builddir)/dist"
+	rm -rf "$(top_builddir)/.tox"
 	rm -rf "$(top_srcdir)/__pycache__"
 	rm -f "$(top_builddir)"/$(PACKAGE)-*.tar.gz
 
@@ -212,6 +213,7 @@ pylint: $(top_builddir)/ipapython/version.py ipasetup.py
 		-path './freeipa-*' -prune -o \
 		-path './dist' -prune -o \
 		-path './pypi' -prune -o \
+		-path './.tox' -prune -o \
 		-name '.*' -o \
 		-name '*.in' -o \
 		-name '*~' -o \
@@ -299,12 +301,12 @@ pypi_packages: $(WHEELPYPIDIR) .wheelconstraints
 	rm -f $(WHEELPYPIDIR)/*
 	for dir in $(IPACLIENT_SUBDIRS); do \
 	    $(MAKE) $(AM_MAKEFLAGS) \
-	        IPA_OMIT_INSTALL=1 WHEELDISTDIR=$(abspath $(WHEELPYPIDIR)) \
+	        IPA_OMIT_INSTALL=1 WHEELDISTDIR="$(abspath $(WHEELPYPIDIR))" \
 	        -C $${dir} bdist_wheel || exit 1; \
 	done
 	for dir in $(IPA_PLACEHOLDERS); do \
 	    $(MAKE) $(AM_MAKEFLAGS) \
-	        IPA_OMIT_INSTALL=1 WHEELDISTDIR=$(abspath $(WHEELPYPIDIR)) \
+	        IPA_OMIT_INSTALL=1 WHEELDISTDIR="$(abspath $(WHEELPYPIDIR))" \
 	        -C $(top_srcdir)/pypi/$${dir} bdist_wheel || exit 1; \
 	done
 	@echo -e "\n\nTo upload packages to PyPI, run:\n"
diff --git a/configure.ac b/configure.ac
index 8f8751a..68601de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -276,6 +276,7 @@ AC_CONFIG_COMMANDS([po/POTFILES.in],
 			-path "./${PACKAGE}-*" -prune -o dnl dist directories
 			-path '*/build' -prune -o dnl Python builds
 			-path '*/dist' -prune -o dnl Python dists
+			-path './.tox' -prune -o dnl Python tox test
 			-path './conf*' -prune -o dnl generated by configure
 			-name '*.py' -print -o dnl
 			-name '*.c' -print -o dnl
diff --git a/freeipa.spec.in b/freeipa.spec.in
index 6034f74..fbc67cb 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -144,9 +144,12 @@ BuildRequires:  python-cffi
 #
 %if 0%{?with_wheels}
 BuildRequires:  dbus-glib-devel
+BuildRequires:  libffi-devel
+BuildRequires:  python-tox
 BuildRequires:  python2-twine
 BuildRequires:  python2-wheel
 %if 0%{?with_python3}
+BuildRequires:  python3-tox
 BuildRequires:  python3-twine
 BuildRequires:  python3-wheel
 %endif
diff --git a/ipatests/conftest.py b/ipatests/conftest.py
index 61e889d..a57bf7d 100644
--- a/ipatests/conftest.py
+++ b/ipatests/conftest.py
@@ -52,7 +52,9 @@
     'ipaserver/build',
     'ipatests/build',
     # install/share/wsgi.py
-    'install/share'
+    'install/share',
+    # integration plugin imports from ipaplatform
+    'ipatests/pytest_plugins',
 ]
 
 
diff --git a/pypi/test_placeholder.py b/pypi/test_placeholder.py
new file mode 100644
index 0000000..d17b23a
--- /dev/null
+++ b/pypi/test_placeholder.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# Copyright (C) 2017  FreeIPA Contributors see COPYING for license
+
+import importlib
+
+import pkg_resources
+
+import pytest
+
+@pytest.mark.parametrize("modname", [
+    # placeholder packages raise ImportError
+    'ipaplatform',
+    'ipaserver',
+    'ipatests',
+    # PyPI packages do not have install subpackage
+    'ipaclient.install',
+    'ipalib.install',
+    'ipapython.install',
+])
+def test_fail_import(modname):
+    try:
+        importlib.import_module(modname)
+    except ImportError:
+        pass
+    else:
+        pytest.fail("'import {}' does not fail".format(modname))
+
+
+@pytest.mark.parametrize("modname", [
+    'ipaclient',
+    'ipalib',
+    'ipapython',
+])
+def test_import(modname):
+    importlib.import_module(modname)
+
+
+@pytest.mark.parametrize("pkgname", [
+    'ipaclient',
+    'ipalib',
+    'ipaplatform',
+    'ipapython',
+    'ipaserver',
+    'ipatests',
+])
+def test_package_installed(pkgname):
+    pkg_resources.require(pkgname)
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..db551df
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,55 @@
+[tox]
+minversion=2.3.1
+envlist=py27,py35,py36,pylint2,pylint3,pypi
+skip_missing_interpreters=true
+skipsdist=true
+
+[testenv]
+# always re-create virtual env. A special install helper is used to configure,
+# build and install packages.
+recreate=True
+install_command={toxinidir}/.tox-install.sh wheel_bundle {envpython} {envsitepackagesdir} {packages}
+changedir={envdir}
+setenv=
+    HOME={envtmpdir}
+deps=
+    ipaclient
+    ipatests
+commands=
+    {envbindir}/ipa --help
+    {envpython} -bb {envbindir}/ipa-run-tests --ipaclient-unittests
+
+[testenv:pylint2]
+basepython=python2.7
+deps=
+    ipaclient
+    ipapython[certmonger]
+    pylint
+commands=
+    {envpython} -m pylint \
+        --rcfile={toxinidir}/pylintrc \
+        --load-plugins pylint_plugins \
+        {envsitepackagesdir}/ipaclient \
+        {envsitepackagesdir}/ipalib \
+        {envsitepackagesdir}/ipapython
+
+[testenv:pylint3]
+basepython=python3
+deps={[testenv:pylint2]deps}
+commands={[testenv:pylint2]commands}
+
+[testenv:pypi]
+recreate=True
+install_command={toxinidir}/.tox-install.sh pypi_packages {envpython} {envsitepackagesdir} {packages}
+changedir={envdir}
+setenv=
+    HOME={envtmpdir}
+deps=
+    pytest
+    ipaclient
+    # placeholder
+    ipaplatform
+    ipaserver
+    ipatests
+commands=
+    {envpython} -m pytest {toxinidir}/pypi/test_placeholder.py
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to