public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing
@ 2019-11-04 21:00 Michał Górny
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 2/4] dev-python/cssselect: Example use of distutils_enable_tests Michał Górny
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Michał Górny @ 2019-11-04 21:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Add a helpful function to handle adding common stuff for the most common
test runners.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/distutils-r1.eclass | 60 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

Example ebuild use sent in replies.

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index d3eb8f22ead2..2edffdb2d7c5 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -232,6 +232,66 @@ fi
 # }
 # @CODE
 
+# @FUNCTION: distutils_enable_tests
+# @USAGE: <test-runner>
+# @DESCRIPTION:
+# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
+# with the specified test runner.  Also copies the current value
+# of RDEPEND to test?-BDEPEND.  The test-runner argument must be one of:
+#
+# - nose: nosetests (dev-python/nose)
+# - pytest: dev-python/pytest
+# - unittest: for built-in Python unittest module
+#
+# This function is meant as a helper for common use cases, and it only
+# takes care of basic setup.  You still need to list additional test
+# dependencies manually.  If you have uncommon use case, you should
+# not use it and instead enable tests manually.
+#
+# This function must be called in global scope, after RDEPEND has been
+# declared.  Take care not to overwrite the variables set by it.
+distutils_enable_tests() {
+	debug-print-function ${FUNCNAME} "${@}"
+	[[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner"
+
+	[[ ${EAPI} == [56] ]] && local BDEPEND
+
+	IUSE+=" test"
+	RESTRICT+=" !test? ( test )"
+	BDEPEND+=" test? ("
+
+	case ${1} in
+		nose)
+			BDEPEND+=" dev-python/nose[${PYTHON_USEDEP}]"
+			python_test() {
+				nosetests -v || die "Tests fail with ${EPYTHON}"
+			}
+			;;
+		pytest)
+			BDEPEND+=" dev-python/pytest[${PYTHON_USEDEP}]"
+			python_test() {
+				pytest -vv || die "Tests fail with ${EPYTHON}"
+			}
+			;;
+		unittest)
+			python_test() {
+				"${EPYTHON}" -m unittest discover -v ||
+					die "Tests fail with ${EPYTHON}"
+			}
+			;;
+		*)
+			die "${FUNCNAME}: unsupported argument: ${1}"
+	esac
+
+	BDEPEND+=" ${RDEPEND} )"
+
+	[[ ${EAPI} == [56] ]] && DEPEND+=" ${BDEPEND}"
+
+	# we need to ensure successful return in case we're called last,
+	# otherwise Portage may wrongly assume sourcing failed
+	return 0
+}
+
 # @FUNCTION: esetup.py
 # @USAGE: [<args>...]
 # @DESCRIPTION:
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 2/4] dev-python/cssselect: Example use of distutils_enable_tests
  2019-11-04 21:00 [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Michał Górny
@ 2019-11-04 21:00 ` Michał Górny
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 3/4] dev-python/pyee: " Michał Górny
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2019-11-04 21:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 dev-python/cssselect/cssselect-1.0.3.ebuild | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/dev-python/cssselect/cssselect-1.0.3.ebuild b/dev-python/cssselect/cssselect-1.0.3.ebuild
index 2d91e85a4ac2..d4216abcd6e7 100644
--- a/dev-python/cssselect/cssselect-1.0.3.ebuild
+++ b/dev-python/cssselect/cssselect-1.0.3.ebuild
@@ -23,7 +23,7 @@ DEPEND="
 	doc? ( dev-python/sphinx[${PYTHON_USEDEP}] )
 	test? ( dev-python/lxml[${PYTHON_USEDEP}] )"
 
-RDEPEND=""
+distutils_enable_tests unittest
 
 python_prepare_all() {
 	# prevent non essential d'load of files in doc build
@@ -37,10 +37,6 @@ python_compile_all() {
 	fi
 }
 
-python_test() {
-	"${EPYTHON}" -m unittest discover -v || die "Tests fail with ${EPYTHON}"
-}
-
 python_install_all() {
 	use doc && local HTML_DOCS=( docs/_build/html/. )
 	distutils-r1_python_install_all
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 3/4] dev-python/pyee: Example use of distutils_enable_tests
  2019-11-04 21:00 [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Michał Górny
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 2/4] dev-python/cssselect: Example use of distutils_enable_tests Michał Górny
@ 2019-11-04 21:00 ` Michał Górny
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 4/4] dev-python/trustme: " Michał Górny
  2019-11-05  5:35 ` [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Joonas Niilola
  3 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2019-11-04 21:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 dev-python/pyee/pyee-1.0.2.ebuild | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/dev-python/pyee/pyee-1.0.2.ebuild b/dev-python/pyee/pyee-1.0.2.ebuild
index f25af4da8a1d..dd6ccee38a9d 100644
--- a/dev-python/pyee/pyee-1.0.2.ebuild
+++ b/dev-python/pyee/pyee-1.0.2.ebuild
@@ -14,12 +14,5 @@ SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
 SLOT="0"
 LICENSE="MIT"
 KEYWORDS="~amd64"
-IUSE="test"
 
-RDEPEND=""
-DEPEND="${RDEPEND}
-	test? ( dev-python/nose[${PYTHON_USEDEP}] )"
-
-python_test() {
-	nosetests -v || die
-}
+distutils_enable_tests nose
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 4/4] dev-python/trustme: Example use of distutils_enable_tests
  2019-11-04 21:00 [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Michał Górny
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 2/4] dev-python/cssselect: Example use of distutils_enable_tests Michał Górny
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 3/4] dev-python/pyee: " Michał Górny
@ 2019-11-04 21:00 ` Michał Górny
  2019-11-05  5:35 ` [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Joonas Niilola
  3 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2019-11-04 21:00 UTC (permalink / raw
  To: gentoo-dev; +Cc: python, Michał Górny

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 dev-python/trustme/trustme-0.5.2.ebuild | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/dev-python/trustme/trustme-0.5.2.ebuild b/dev-python/trustme/trustme-0.5.2.ebuild
index ee3f8b306297..eb4e41b0cf42 100644
--- a/dev-python/trustme/trustme-0.5.2.ebuild
+++ b/dev-python/trustme/trustme-0.5.2.ebuild
@@ -14,20 +14,15 @@ LICENSE="|| ( Apache-2.0 MIT )"
 SLOT="0"
 KEYWORDS="~amd64 ~arm ~arm64 ~x86"
 IUSE="test"
-RESTRICT="!test? ( test )"
 
 RDEPEND="dev-python/cryptography[${PYTHON_USEDEP}]
 	dev-python/idna[${PYTHON_USEDEP}]
 	$(python_gen_cond_dep '>=dev-python/ipaddress-1.0.16[${PYTHON_USEDEP}]' -2 )"
-DEPEND="${RDEPEND}
-	dev-python/setuptools[${PYTHON_USEDEP}]
+DEPEND="dev-python/setuptools[${PYTHON_USEDEP}]
 	test? (
-		dev-python/pytest[${PYTHON_USEDEP}]
 		dev-python/pyopenssl[${PYTHON_USEDEP}]
 		dev-python/service_identity[${PYTHON_USEDEP}]
 		$(python_gen_cond_dep 'dev-python/futures[${PYTHON_USEDEP}]' -2 )
 	)"
 
-python_test() {
-	pytest -vv || die "Tests failed under ${EPYTHON}"
-}
+distutils_enable_tests pytest
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing
  2019-11-04 21:00 [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Michał Górny
                   ` (2 preceding siblings ...)
  2019-11-04 21:00 ` [gentoo-dev] [PATCH 4/4] dev-python/trustme: " Michał Górny
@ 2019-11-05  5:35 ` Joonas Niilola
  2019-11-05  6:53   ` Michał Górny
  3 siblings, 1 reply; 6+ messages in thread
From: Joonas Niilola @ 2019-11-05  5:35 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 2766 bytes --]


Beautiful work, but is there a way to integrate "esetup.py test" into
this as well?


-- juippis


On 11/4/19 11:00 PM, Michał Górny wrote:
> Add a helpful function to handle adding common stuff for the most common
> test runners.
>
> Signed-off-by: Michał Górny <mgorny@gentoo.org>
> ---
>  eclass/distutils-r1.eclass | 60 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
>
> Example ebuild use sent in replies.
>
> diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
> index d3eb8f22ead2..2edffdb2d7c5 100644
> --- a/eclass/distutils-r1.eclass
> +++ b/eclass/distutils-r1.eclass
> @@ -232,6 +232,66 @@ fi
>  # }
>  # @CODE
>  
> +# @FUNCTION: distutils_enable_tests
> +# @USAGE: <test-runner>
> +# @DESCRIPTION:
> +# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
> +# with the specified test runner.  Also copies the current value
> +# of RDEPEND to test?-BDEPEND.  The test-runner argument must be one of:
> +#
> +# - nose: nosetests (dev-python/nose)
> +# - pytest: dev-python/pytest
> +# - unittest: for built-in Python unittest module
> +#
> +# This function is meant as a helper for common use cases, and it only
> +# takes care of basic setup.  You still need to list additional test
> +# dependencies manually.  If you have uncommon use case, you should
> +# not use it and instead enable tests manually.
> +#
> +# This function must be called in global scope, after RDEPEND has been
> +# declared.  Take care not to overwrite the variables set by it.
> +distutils_enable_tests() {
> +	debug-print-function ${FUNCNAME} "${@}"
> +	[[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner"
> +
> +	[[ ${EAPI} == [56] ]] && local BDEPEND
> +
> +	IUSE+=" test"
> +	RESTRICT+=" !test? ( test )"
> +	BDEPEND+=" test? ("
> +
> +	case ${1} in
> +		nose)
> +			BDEPEND+=" dev-python/nose[${PYTHON_USEDEP}]"
> +			python_test() {
> +				nosetests -v || die "Tests fail with ${EPYTHON}"
> +			}
> +			;;
> +		pytest)
> +			BDEPEND+=" dev-python/pytest[${PYTHON_USEDEP}]"
> +			python_test() {
> +				pytest -vv || die "Tests fail with ${EPYTHON}"
> +			}
> +			;;
> +		unittest)
> +			python_test() {
> +				"${EPYTHON}" -m unittest discover -v ||
> +					die "Tests fail with ${EPYTHON}"
> +			}
> +			;;
> +		*)
> +			die "${FUNCNAME}: unsupported argument: ${1}"
> +	esac
> +
> +	BDEPEND+=" ${RDEPEND} )"
> +
> +	[[ ${EAPI} == [56] ]] && DEPEND+=" ${BDEPEND}"
> +
> +	# we need to ensure successful return in case we're called last,
> +	# otherwise Portage may wrongly assume sourcing failed
> +	return 0
> +}
> +
>  # @FUNCTION: esetup.py
>  # @USAGE: [<args>...]
>  # @DESCRIPTION:


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 642 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing
  2019-11-05  5:35 ` [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Joonas Niilola
@ 2019-11-05  6:53   ` Michał Górny
  0 siblings, 0 replies; 6+ messages in thread
From: Michał Górny @ 2019-11-05  6:53 UTC (permalink / raw
  To: gentoo-dev, Joonas Niilola

Dnia November 5, 2019 5:35:48 AM UTC, Joonas Niilola <juippis@gentoo.org> napisał(a):
>
>Beautiful work, but is there a way to integrate "esetup.py test" into
>this as well?. 

Not sure, would use some research for that. The main question is what test runners (deps) are commonly used. I'd like to avoid people mistakenly assuming that correct deps have been added for it.

>
>
>-- juippis
>
>
>On 11/4/19 11:00 PM, Michał Górny wrote:
>> Add a helpful function to handle adding common stuff for the most
>common
>> test runners.
>>
>> Signed-off-by: Michał Górny <mgorny@gentoo.org>
>> ---
>>  eclass/distutils-r1.eclass | 60
>++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 60 insertions(+)
>>
>> Example ebuild use sent in replies.
>>
>> diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
>> index d3eb8f22ead2..2edffdb2d7c5 100644
>> --- a/eclass/distutils-r1.eclass
>> +++ b/eclass/distutils-r1.eclass
>> @@ -232,6 +232,66 @@ fi
>>  # }
>>  # @CODE
>>  
>> +# @FUNCTION: distutils_enable_tests
>> +# @USAGE: <test-runner>
>> +# @DESCRIPTION:
>> +# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
>> +# with the specified test runner.  Also copies the current value
>> +# of RDEPEND to test?-BDEPEND.  The test-runner argument must be one
>of:
>> +#
>> +# - nose: nosetests (dev-python/nose)
>> +# - pytest: dev-python/pytest
>> +# - unittest: for built-in Python unittest module
>> +#
>> +# This function is meant as a helper for common use cases, and it
>only
>> +# takes care of basic setup.  You still need to list additional test
>> +# dependencies manually.  If you have uncommon use case, you should
>> +# not use it and instead enable tests manually.
>> +#
>> +# This function must be called in global scope, after RDEPEND has
>been
>> +# declared.  Take care not to overwrite the variables set by it.
>> +distutils_enable_tests() {
>> +	debug-print-function ${FUNCNAME} "${@}"
>> +	[[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument:
>test-runner"
>> +
>> +	[[ ${EAPI} == [56] ]] && local BDEPEND
>> +
>> +	IUSE+=" test"
>> +	RESTRICT+=" !test? ( test )"
>> +	BDEPEND+=" test? ("
>> +
>> +	case ${1} in
>> +		nose)
>> +			BDEPEND+=" dev-python/nose[${PYTHON_USEDEP}]"
>> +			python_test() {
>> +				nosetests -v || die "Tests fail with ${EPYTHON}"
>> +			}
>> +			;;
>> +		pytest)
>> +			BDEPEND+=" dev-python/pytest[${PYTHON_USEDEP}]"
>> +			python_test() {
>> +				pytest -vv || die "Tests fail with ${EPYTHON}"
>> +			}
>> +			;;
>> +		unittest)
>> +			python_test() {
>> +				"${EPYTHON}" -m unittest discover -v ||
>> +					die "Tests fail with ${EPYTHON}"
>> +			}
>> +			;;
>> +		*)
>> +			die "${FUNCNAME}: unsupported argument: ${1}"
>> +	esac
>> +
>> +	BDEPEND+=" ${RDEPEND} )"
>> +
>> +	[[ ${EAPI} == [56] ]] && DEPEND+=" ${BDEPEND}"
>> +
>> +	# we need to ensure successful return in case we're called last,
>> +	# otherwise Portage may wrongly assume sourcing failed
>> +	return 0
>> +}
>> +
>>  # @FUNCTION: esetup.py
>>  # @USAGE: [<args>...]
>>  # @DESCRIPTION:


--
Best regards, 
Michał Górny


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-05  6:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-04 21:00 [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Michał Górny
2019-11-04 21:00 ` [gentoo-dev] [PATCH 2/4] dev-python/cssselect: Example use of distutils_enable_tests Michał Górny
2019-11-04 21:00 ` [gentoo-dev] [PATCH 3/4] dev-python/pyee: " Michał Górny
2019-11-04 21:00 ` [gentoo-dev] [PATCH 4/4] dev-python/trustme: " Michał Górny
2019-11-05  5:35 ` [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing Joonas Niilola
2019-11-05  6:53   ` Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox