summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'dev-python')
-rw-r--r--dev-python/mccabe/Manifest1
-rw-r--r--dev-python/mccabe/files/mccabe-0.7.0-fix-tests-without-hypothesmith.patch74
-rw-r--r--dev-python/mccabe/mccabe-0.7.0.ebuild33
3 files changed, 108 insertions, 0 deletions
diff --git a/dev-python/mccabe/Manifest b/dev-python/mccabe/Manifest
index 112a1e13f737..5ecec9341694 100644
--- a/dev-python/mccabe/Manifest
+++ b/dev-python/mccabe/Manifest
@@ -1 +1,2 @@
DIST mccabe-0.6.1.tar.gz 8612 BLAKE2B 6828dfd852cf9b47de10bd889dd4c32dc1ee95910fbd27e0921cd7d9975a0831b1c2763eda5b2d77d7e4b44b5a9d0e89f0818cab71de655954cc87cacfe8d382 SHA512 d8fc251a29790887c14c5932c5172b4cd578cd37ccf14cb96e80f0b97f27023427ea032d14e1e2a99d72627b055eb285f60db69e679ecd79d90a34b0255703d8
+DIST mccabe-0.7.0.tar.gz 9658 BLAKE2B b4664a00d4760e2f662681875b548b67ad76d6b8a0ee46bf160e3232ad75172512ad7b4a99759dc13607cf06f3c772210b76a7051582d0bbd221091772543c07 SHA512 3e4141033c63434fad183f62dece872554302aeee8cb789586ac7d6d748d198799e2797df1d58458f4d431734f8899f11022d76666c848d43e6271304776346d
diff --git a/dev-python/mccabe/files/mccabe-0.7.0-fix-tests-without-hypothesmith.patch b/dev-python/mccabe/files/mccabe-0.7.0-fix-tests-without-hypothesmith.patch
new file mode 100644
index 000000000000..18728fe59826
--- /dev/null
+++ b/dev-python/mccabe/files/mccabe-0.7.0-fix-tests-without-hypothesmith.patch
@@ -0,0 +1,74 @@
+diff --git a/test_mccabe.py b/test_mccabe.py
+index fe6e8d3..14d8012 100644
+--- a/test_mccabe.py
++++ b/test_mccabe.py
+@@ -241,37 +241,38 @@ class RegressionTests(unittest.TestCase):
+
+ # This test uses the Hypothesis and Hypothesmith libraries to generate random
+ # syntatically-valid Python source code and applies McCabe on it.
+-@settings(
+- max_examples=1000, # roughly 1k tests/minute, or half that under coverage
+- derandomize=False, # deterministic mode to avoid CI flakiness
+- deadline=None, # ignore Hypothesis' health checks; we already know that
+- suppress_health_check=HealthCheck.all(), # this is slow and filter-heavy.
+-)
+-@given(
+- # Note that while Hypothesmith might generate code unlike that written by
+- # humans, it's a general test that should pass for any *valid* source code.
+- # (so e.g. running it against code scraped of the internet might also help)
+- src_contents=hypothesmith.from_grammar() | hypothesmith.from_node(),
+- max_complexity=st.integers(min_value=1),
+-)
+-@pytest.mark.skipif(not hypothesmith, reason="hypothesmith could not be imported")
+-def test_idempotent_any_syntatically_valid_python(
+- src_contents: str, max_complexity: int
+-) -> None:
+- """Property-based tests for mccabe.
+-
+- This test case is based on a similar test for Black, the code formatter.
+- Black's test was written by Zac Hatfield-Dodds, the author of Hypothesis
+- and the Hypothesmith tool for source code generation. You can run this
+- file with `python`, `pytest`, or (soon) a coverage-guided fuzzer Zac is
+- working on.
+- """
+-
+- # Before starting, let's confirm that the input string is valid Python:
+- compile(src_contents, "<string>", "exec") # else bug is in hypothesmith
+-
+- # Then try to apply get_complexity_number to the code...
+- get_code_complexity(src_contents, max_complexity)
++if hypothesmith:
++ @settings(
++ max_examples=1000, # roughly 1k tests/minute, or half that under coverage
++ derandomize=False, # deterministic mode to avoid CI flakiness
++ deadline=None, # ignore Hypothesis' health checks; we already know that
++ suppress_health_check=HealthCheck.all(), # this is slow and filter-heavy.
++ )
++ @given(
++ # Note that while Hypothesmith might generate code unlike that written by
++ # humans, it's a general test that should pass for any *valid* source code.
++ # (so e.g. running it against code scraped of the internet might also help)
++ src_contents=hypothesmith.from_grammar() | hypothesmith.from_node(),
++ max_complexity=st.integers(min_value=1),
++ )
++ @pytest.mark.skipif(not hypothesmith, reason="hypothesmith could not be imported")
++ def test_idempotent_any_syntatically_valid_python(
++ src_contents: str, max_complexity: int
++ ) -> None:
++ """Property-based tests for mccabe.
++
++ This test case is based on a similar test for Black, the code formatter.
++ Black's test was written by Zac Hatfield-Dodds, the author of Hypothesis
++ and the Hypothesmith tool for source code generation. You can run this
++ file with `python`, `pytest`, or (soon) a coverage-guided fuzzer Zac is
++ working on.
++ """
++
++ # Before starting, let's confirm that the input string is valid Python:
++ compile(src_contents, "<string>", "exec") # else bug is in hypothesmith
++
++ # Then try to apply get_complexity_number to the code...
++ get_code_complexity(src_contents, max_complexity)
+
+
+ if __name__ == "__main__":
diff --git a/dev-python/mccabe/mccabe-0.7.0.ebuild b/dev-python/mccabe/mccabe-0.7.0.ebuild
new file mode 100644
index 000000000000..59b61eaf1065
--- /dev/null
+++ b/dev-python/mccabe/mccabe-0.7.0.ebuild
@@ -0,0 +1,33 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+PYTHON_COMPAT=( pypy3 python3_{8..11} )
+DISTUTILS_USE_PEP517=setuptools
+inherit distutils-r1
+
+DESCRIPTION="flake8 plugin: McCabe complexity checker"
+HOMEPAGE="https://github.com/PyCQA/mccabe"
+SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
+
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+LICENSE="MIT"
+SLOT="0"
+
+RDEPEND="dev-python/flake8[${PYTHON_USEDEP}]"
+
+BDEPEND="test? (
+ dev-python/hypothesis[${PYTHON_USEDEP}]
+)"
+
+PATCHES=(
+ "${FILESDIR}/${P}-fix-tests-without-hypothesmith.patch"
+)
+
+distutils_enable_tests pytest
+
+python_prepare_all() {
+ sed -i -e '/pytest-runner/d' setup.py || die
+ distutils-r1_python_prepare_all
+}