|
| 1 | +# Copyright 1999-2024 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=8 |
| 5 | + |
| 6 | +DISTUTILS_EXT=1 |
| 7 | +DISTUTILS_USE_PEP517=setuptools |
| 8 | +PYTHON_COMPAT=( python3_{11..13} ) |
| 9 | +PYTHON_REQ_USE="threads(+),sqlite(+)" |
| 10 | + |
| 11 | +inherit distutils-r1 pypi |
| 12 | + |
| 13 | +DESCRIPTION="Code coverage measurement for Python" |
| 14 | +HOMEPAGE=" |
| 15 | + https://coverage.readthedocs.io/en/latest/ |
| 16 | + https://github.com/nedbat/coveragepy/ |
| 17 | + https://pypi.org/project/coverage/ |
| 18 | +" |
| 19 | + |
| 20 | +LICENSE="BSD" |
| 21 | +SLOT="0" |
| 22 | +KEYWORDS="amd64 arm arm64 x86" |
| 23 | + |
| 24 | +RDEPEND=" |
| 25 | + $(python_gen_cond_dep ' |
| 26 | + dev-python/tomli[${PYTHON_USEDEP}] |
| 27 | + ' 3.{9..10}) |
| 28 | +" |
| 29 | +BDEPEND=" |
| 30 | + test? ( |
| 31 | + dev-python/flaky[${PYTHON_USEDEP}] |
| 32 | + dev-python/hypothesis[${PYTHON_USEDEP}] |
| 33 | + dev-python/pytest-xdist[${PYTHON_USEDEP}] |
| 34 | + >=dev-python/unittest-mixins-1.4[${PYTHON_USEDEP}] |
| 35 | + ) |
| 36 | +" |
| 37 | + |
| 38 | +distutils_enable_tests pytest |
| 39 | + |
| 40 | +src_prepare() { |
| 41 | + sed -i -e '/addopts/s:-q -n auto::' pyproject.toml || die |
| 42 | + distutils-r1_src_prepare |
| 43 | +} |
| 44 | + |
| 45 | +test_tracer() { |
| 46 | + local -x COVERAGE_CORE=${1} |
| 47 | + einfo " Testing with the ${COVERAGE_CORE} core ..." |
| 48 | + epytest -p flaky -p hypothesis -p xdist tests |
| 49 | +} |
| 50 | + |
| 51 | +python_test() { |
| 52 | + local EPYTEST_DESELECT=( |
| 53 | + # TODO: fails because of additional "Terminated" print on SIGTERM |
| 54 | + tests/test_concurrency.py::SigtermTest::test_sigterm_threading_saves_data |
| 55 | + # broken because of pytest plugins explicity loaded |
| 56 | + tests/test_debug.py::ShortStackTest::test_short_stack{,_skip} |
| 57 | + # these expect specific availability of C extension matching |
| 58 | + # COVERAGE_CORE (which breaks testing pytracer on CPython) |
| 59 | + tests/test_cmdline.py::CmdLineStdoutTest::test_version |
| 60 | + tests/test_debug.py::DebugTraceTest::test_debug_sys_ctracer |
| 61 | + ) |
| 62 | + local EPYTEST_IGNORE=( |
| 63 | + # pip these days insists on fetching build deps from Internet |
| 64 | + tests/test_venv.py |
| 65 | + ) |
| 66 | + |
| 67 | + "${EPYTHON}" igor.py zip_mods || die |
| 68 | + |
| 69 | + local -x COVERAGE_TESTING=True |
| 70 | + # TODO: figure out why they can't be imported inside test env |
| 71 | + local -x COVERAGE_NO_CONTRACTS=1 |
| 72 | + local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 |
| 73 | + |
| 74 | + local prev_opt=$(shopt -p nullglob) |
| 75 | + shopt -s nullglob |
| 76 | + local c_ext=( "${BUILD_DIR}/install$(python_get_sitedir)"/coverage/*.so ) |
| 77 | + ${prev_opt} |
| 78 | + |
| 79 | + if [[ -n ${c_ext} ]]; then |
| 80 | + cp "${c_ext}" coverage/ || die |
| 81 | + test_tracer ctrace |
| 82 | + fi |
| 83 | + |
| 84 | + test_tracer pytrace |
| 85 | + |
| 86 | + case ${EPYTHON} in |
| 87 | + python3.1[01]|pypy3) |
| 88 | + ;; |
| 89 | + *) |
| 90 | + # available since Python 3.12 |
| 91 | + test_tracer sysmon |
| 92 | + ;; |
| 93 | + esac |
| 94 | + |
| 95 | + if [[ -n ${c_ext} ]]; then |
| 96 | + rm coverage/*.so || die |
| 97 | + fi |
| 98 | +} |
0 commit comments