From 28ecf82c8a51cadd04a8eb5cf7425a80a153ecb7 Mon Sep 17 00:00:00 2001 From: Kit Yan Choi Date: Fri, 6 Sep 2019 14:33:53 +0200 Subject: [PATCH 1/3] TST: Add the first test using hypothesis This adds the first test that uses hypothesis and hence brings in hypothesis as an additional test dependency. cf. EuroScipy 2019 Sprint --- INSTALL.rst.txt | 5 +++++ numpy/core/tests/test_arrayprint.py | 13 +++++++++++++ shippable.yml | 2 ++ test_requirements.txt | 1 + tox.ini | 1 + 5 files changed, 22 insertions(+) diff --git a/INSTALL.rst.txt b/INSTALL.rst.txt index bd2f4f92cd55..865d09497249 100644 --- a/INSTALL.rst.txt +++ b/INSTALL.rst.txt @@ -33,8 +33,13 @@ Building NumPy requires the following installed software: This is required for testing numpy, but not for using it. +4) hypothesis__ (optional) + + This is required for testing numpy, but not for using it. + Python__ http://www.python.org pytest__ http://pytest.readthedocs.io +hypothesis__ https://hypothesis.readthedocs.io .. note:: diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 702e68e769f0..f23e912e8851 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -12,6 +12,10 @@ ) import textwrap +import hypothesis +import hypothesis.extra.numpy + + class TestArrayRepr(object): def test_nan_inf(self): x = np.array([np.nan, np.inf]) @@ -399,6 +403,15 @@ def test_wide_element(self): "[ 'xxxxx']" ) + @hypothesis.given(hypothesis.extra.numpy.from_dtype(np.dtype("U"))) + def test_any_text(self, text): + a = np.array([text, text, text]) + assert_equal(a[0], text) + assert_equal( + np.array2string(a, max_line_width=len(repr(text)) * 2 + 3), + "[{0!r} {0!r}\n {0!r}]".format(text) + ) + @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts") def test_refcount(self): # make sure we do not hold references to the array due to a recursive diff --git a/shippable.yml b/shippable.yml index 7d134a20ed19..8fe8c149a3fb 100644 --- a/shippable.yml +++ b/shippable.yml @@ -34,6 +34,8 @@ build: - pip install cython --cache-dir=/root/.cache/pip/wheels/$SHIPPABLE_PYTHON_VERSION # install pytz for datetime testing - pip install pytz + # install hypothesis for tests that require it + - pip install hypothesis # install pytest-xdist to leverage a second core # for unit tests - pip install pytest-xdist diff --git a/test_requirements.txt b/test_requirements.txt index cb3e5f758393..b835c0245992 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,4 +1,5 @@ cython==0.29.13 +hypothesis==4.35.0 pytest==5.1.2 pytz==2019.2 pytest-cov==2.7.1 diff --git a/tox.ini b/tox.ini index 3223b9e1b0fa..9f79a299823f 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ envlist = [testenv] deps= + hypothesis pytest changedir={envdir} commands={envpython} {toxinidir}/runtests.py --mode=full {posargs:} From 28887ac29f8764144e3c51d4ddd4a7ac1c77277f Mon Sep 17 00:00:00 2001 From: Kit Choi Date: Mon, 9 Sep 2019 19:46:48 +0100 Subject: [PATCH 2/3] Make test input reproducible --- numpy/core/tests/test_arrayprint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index f23e912e8851..0dbd8fc78029 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -403,6 +403,7 @@ def test_wide_element(self): "[ 'xxxxx']" ) + @hypothesis.seed(43) @hypothesis.given(hypothesis.extra.numpy.from_dtype(np.dtype("U"))) def test_any_text(self, text): a = np.array([text, text, text]) From 4aa0f72e9782d3d18fa3b7e7653621a4631afcc3 Mon Sep 17 00:00:00 2001 From: Kit Choi Date: Mon, 9 Dec 2019 19:57:17 +0000 Subject: [PATCH 3/3] Bump version of hypothesis --- test_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_requirements.txt b/test_requirements.txt index aa945c2a5b94..e912bafc15ce 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,5 +1,5 @@ cython==0.29.14 -hypothesis==4.35.0 +hypothesis==4.53.1 pytest==5.3.1 pytz==2019.3 pytest-cov==2.8.1