commit: 22ab1c323fdca03b27250017bc663d85d982ef39
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 8 08:10:04 2021 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Mar 11 08:47:57 2021 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=22ab1c32
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 <AT> gentoo.org>
eclass/distutils-r1.eclass | 93 +++++++++++++++++++++++-----------------------
1 file changed, 47 insertions(+), 46 deletions(-)
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index f5b151d4b8e..0e543412f64 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: