Gentoo Archives: gentoo-dev

From: Joonas Niilola <juippis@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing
Date: Tue, 05 Nov 2019 05:36:04
Message-Id: 8ecc195f-1b32-d3a4-3e78-da8176d4232d@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing by "Michał Górny"
1 Beautiful work, but is there a way to integrate "esetup.py test" into
2 this as well?
3
4
5 -- juippis
6
7
8 On 11/4/19 11:00 PM, Michał Górny wrote:
9 > Add a helpful function to handle adding common stuff for the most common
10 > test runners.
11 >
12 > Signed-off-by: Michał Górny <mgorny@g.o>
13 > ---
14 > eclass/distutils-r1.eclass | 60 ++++++++++++++++++++++++++++++++++++++
15 > 1 file changed, 60 insertions(+)
16 >
17 > Example ebuild use sent in replies.
18 >
19 > diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
20 > index d3eb8f22ead2..2edffdb2d7c5 100644
21 > --- a/eclass/distutils-r1.eclass
22 > +++ b/eclass/distutils-r1.eclass
23 > @@ -232,6 +232,66 @@ fi
24 > # }
25 > # @CODE
26 >
27 > +# @FUNCTION: distutils_enable_tests
28 > +# @USAGE: <test-runner>
29 > +# @DESCRIPTION:
30 > +# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
31 > +# with the specified test runner. Also copies the current value
32 > +# of RDEPEND to test?-BDEPEND. The test-runner argument must be one of:
33 > +#
34 > +# - nose: nosetests (dev-python/nose)
35 > +# - pytest: dev-python/pytest
36 > +# - unittest: for built-in Python unittest module
37 > +#
38 > +# This function is meant as a helper for common use cases, and it only
39 > +# takes care of basic setup. You still need to list additional test
40 > +# dependencies manually. If you have uncommon use case, you should
41 > +# not use it and instead enable tests manually.
42 > +#
43 > +# This function must be called in global scope, after RDEPEND has been
44 > +# declared. Take care not to overwrite the variables set by it.
45 > +distutils_enable_tests() {
46 > + debug-print-function ${FUNCNAME} "${@}"
47 > + [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner"
48 > +
49 > + [[ ${EAPI} == [56] ]] && local BDEPEND
50 > +
51 > + IUSE+=" test"
52 > + RESTRICT+=" !test? ( test )"
53 > + BDEPEND+=" test? ("
54 > +
55 > + case ${1} in
56 > + nose)
57 > + BDEPEND+=" dev-python/nose[${PYTHON_USEDEP}]"
58 > + python_test() {
59 > + nosetests -v || die "Tests fail with ${EPYTHON}"
60 > + }
61 > + ;;
62 > + pytest)
63 > + BDEPEND+=" dev-python/pytest[${PYTHON_USEDEP}]"
64 > + python_test() {
65 > + pytest -vv || die "Tests fail with ${EPYTHON}"
66 > + }
67 > + ;;
68 > + unittest)
69 > + python_test() {
70 > + "${EPYTHON}" -m unittest discover -v ||
71 > + die "Tests fail with ${EPYTHON}"
72 > + }
73 > + ;;
74 > + *)
75 > + die "${FUNCNAME}: unsupported argument: ${1}"
76 > + esac
77 > +
78 > + BDEPEND+=" ${RDEPEND} )"
79 > +
80 > + [[ ${EAPI} == [56] ]] && DEPEND+=" ${BDEPEND}"
81 > +
82 > + # we need to ensure successful return in case we're called last,
83 > + # otherwise Portage may wrongly assume sourcing failed
84 > + return 0
85 > +}
86 > +
87 > # @FUNCTION: esetup.py
88 > # @USAGE: [<args>...]
89 > # @DESCRIPTION:

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies