summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2021-03-08 09:10:04 +0100
committerMichał Górny <mgorny@gentoo.org>2021-03-11 09:47:57 +0100
commit22ab1c323fdca03b27250017bc663d85d982ef39 (patch)
tree167ce8b770ee747ce867c3d2c9c164d410256346 /eclass/distutils-r1.eclass
parentsci-libs/gdal: fix autoconf 2.70+ (diff)
downloadgentoo-22ab1c323fdca03b27250017bc663d85d982ef39.tar.gz
gentoo-22ab1c323fdca03b27250017bc663d85d982ef39.tar.bz2
gentoo-22ab1c323fdca03b27250017bc663d85d982ef39.zip
distutils-r1.eclass: Use a common distutils-r1_python_test
Use a common distutils-r1_python_test function to simplify handling different test scenarios. This avoids code duplication due to defining a lot of python_test() variants, as well as it makes it possible for overriden python_test() to call the base implementation provided by distutils_enable_tests. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/distutils-r1.eclass')
-rw-r--r--eclass/distutils-r1.eclass93
1 files changed, 47 insertions, 46 deletions
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index f5b151d4b8e2..0e543412f645 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -406,10 +406,10 @@ distutils_enable_sphinx() {
distutils_enable_tests() {
debug-print-function ${FUNCNAME} "${@}"
- local do_install=
+ _DISTUTILS_TEST_INSTALL=
case ${1} in
--install)
- do_install=1
+ _DISTUTILS_TEST_INSTALL=1
shift
;;
esac
@@ -419,62 +419,21 @@ distutils_enable_tests() {
case ${1} in
nose)
test_pkg=">=dev-python/nose-1.3.7-r4"
- if [[ ${do_install} ]]; then
- python_test() {
- distutils_install_for_testing --via-root
- nosetests -v || die "Tests fail with ${EPYTHON}"
- }
- else
- python_test() {
- nosetests -v || die "Tests fail with ${EPYTHON}"
- }
- fi
;;
pytest)
test_pkg=">=dev-python/pytest-4.5.0"
- if [[ ${do_install} ]]; then
- python_test() {
- distutils_install_for_testing --via-root
- epytest
- }
- else
- python_test() {
- epytest
- }
- fi
;;
setup.py)
- if [[ ${do_install} ]]; then
- python_test() {
- distutils_install_for_testing --via-root
- nonfatal esetup.py test --verbose ||
- die "Tests fail with ${EPYTHON}"
- }
- else
- python_test() {
- nonfatal esetup.py test --verbose ||
- die "Tests fail with ${EPYTHON}"
- }
- fi
;;
unittest)
- if [[ ${do_install} ]]; then
- python_test() {
- distutils_install_for_testing --via-root
- "${EPYTHON}" -m unittest discover -v ||
- die "Tests fail with ${EPYTHON}"
- }
- else
- python_test() {
- "${EPYTHON}" -m unittest discover -v ||
- die "Tests fail with ${EPYTHON}"
- }
- fi
;;
*)
die "${FUNCNAME}: unsupported argument: ${1}"
esac
+ _DISTUTILS_TEST_RUNNER=${1}
+ python_test() { distutils-r1_python_test; }
+
local test_deps=${RDEPEND}
if [[ -n ${test_pkg} ]]; then
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
@@ -841,6 +800,48 @@ _distutils-r1_wrap_scripts() {
fi
}
+# @FUNCTION: distutils-r1_python_test
+# @USAGE: [additional-args...]
+# @DESCRIPTION:
+# The python_test() implementation used by distutils_enable_tests.
+# Runs tests using the specified test runner, possibly installing them
+# first.
+#
+# This function is used only if distutils_enable_tests is called.
+distutils-r1_python_test() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ if [[ -z ${_DISTUTILS_TEST_RUNNER} ]]; then
+ die "${FUNCNAME} can be only used after calling distutils_enable_tests"
+ fi
+
+ if [[ ${_DISTUTILS_TEST_INSTALL} ]]; then
+ distutils_install_for_testing
+ fi
+
+ case ${_DISTUTILS_TEST_RUNNER} in
+ nose)
+ nosetests -v "${@}"
+ ;;
+ pytest)
+ epytest
+ ;;
+ setup.py)
+ nonfatal esetup.py test --verbose
+ ;;
+ unittest)
+ "${EPYTHON}" -m unittest discover -v
+ ;;
+ *)
+ die "Mis-synced test runner between ${FUNCNAME} and distutils_enable_testing"
+ ;;
+ esac
+
+ if [[ ${?} -ne 0 ]]; then
+ die "Tests failed with ${EPYTHON}"
+ fi
+}
+
# @FUNCTION: distutils-r1_python_install
# @USAGE: [additional-args...]
# @DESCRIPTION: