Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Tue, 01 Dec 2020 10:32:11
Message-Id: 1606818712.2fa29ae45ece5e6c8a7c8b944e8731f383bf101b.mgorny@gentoo
1 commit: 2fa29ae45ece5e6c8a7c8b944e8731f383bf101b
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sat Nov 28 23:45:00 2020 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Tue Dec 1 10:31:52 2020 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2fa29ae4
7
8 distutils-r1.eclass: Accept distutils_enable_tests --install
9
10 Add a convenience --install option to distutils_enable_tests to call
11 distutils_install_for_testing.
12
13 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
14
15 eclass/distutils-r1.eclass | 74 ++++++++++++++++++++++++++++++++++++----------
16 1 file changed, 58 insertions(+), 16 deletions(-)
17
18 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
19 index a0eb41e689a..5ffc91be479 100644
20 --- a/eclass/distutils-r1.eclass
21 +++ b/eclass/distutils-r1.eclass
22 @@ -378,7 +378,7 @@ distutils_enable_sphinx() {
23 }
24
25 # @FUNCTION: distutils_enable_tests
26 -# @USAGE: <test-runner>
27 +# @USAGE: [--install] <test-runner>
28 # @DESCRIPTION:
29 # Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
30 # with the specified test runner. Also copies the current value
31 @@ -389,6 +389,10 @@ distutils_enable_sphinx() {
32 # - setup.py: setup.py test (no deps included)
33 # - unittest: for built-in Python unittest module
34 #
35 +# Additionally, if --install is passed as the first parameter,
36 +# 'distutils_install_for_testing --via-root' is called before running
37 +# the test suite.
38 +#
39 # This function is meant as a helper for common use cases, and it only
40 # takes care of basic setup. You still need to list additional test
41 # dependencies manually. If you have uncommon use case, you should
42 @@ -398,33 +402,71 @@ distutils_enable_sphinx() {
43 # declared. Take care not to overwrite the variables set by it.
44 distutils_enable_tests() {
45 debug-print-function ${FUNCNAME} "${@}"
46 - [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner"
47
48 + local do_install=
49 + case ${1} in
50 + --install)
51 + do_install=1
52 + shift
53 + ;;
54 + esac
55 +
56 + [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner"
57 local test_pkg
58 case ${1} in
59 nose)
60 test_pkg=">=dev-python/nose-1.3.7-r4"
61 - python_test() {
62 - nosetests -v || die "Tests fail with ${EPYTHON}"
63 - }
64 + if [[ ${do_install} ]]; then
65 + python_test() {
66 + distutils_install_for_testing --via-root
67 + nosetests -v || die "Tests fail with ${EPYTHON}"
68 + }
69 + else
70 + python_test() {
71 + nosetests -v || die "Tests fail with ${EPYTHON}"
72 + }
73 + fi
74 ;;
75 pytest)
76 test_pkg=">=dev-python/pytest-4.5.0"
77 - python_test() {
78 - pytest -vv || die "Tests fail with ${EPYTHON}"
79 - }
80 + if [[ ${do_install} ]]; then
81 + python_test() {
82 + distutils_install_for_testing --via-root
83 + pytest -vv || die "Tests fail with ${EPYTHON}"
84 + }
85 + else
86 + python_test() {
87 + pytest -vv || die "Tests fail with ${EPYTHON}"
88 + }
89 + fi
90 ;;
91 setup.py)
92 - python_test() {
93 - nonfatal esetup.py test --verbose ||
94 - die "Tests fail with ${EPYTHON}"
95 - }
96 + if [[ ${do_install} ]]; then
97 + python_test() {
98 + distutils_install_for_testing --via-root
99 + nonfatal esetup.py test --verbose ||
100 + die "Tests fail with ${EPYTHON}"
101 + }
102 + else
103 + python_test() {
104 + nonfatal esetup.py test --verbose ||
105 + die "Tests fail with ${EPYTHON}"
106 + }
107 + fi
108 ;;
109 unittest)
110 - python_test() {
111 - "${EPYTHON}" -m unittest discover -v ||
112 - die "Tests fail with ${EPYTHON}"
113 - }
114 + if [[ ${do_install} ]]; then
115 + python_test() {
116 + distutils_install_for_testing --via-root
117 + "${EPYTHON}" -m unittest discover -v ||
118 + die "Tests fail with ${EPYTHON}"
119 + }
120 + else
121 + python_test() {
122 + "${EPYTHON}" -m unittest discover -v ||
123 + die "Tests fail with ${EPYTHON}"
124 + }
125 + fi
126 ;;
127 *)
128 die "${FUNCNAME}: unsupported argument: ${1}"