From 8e20a3185939d01723ba928c35393ced0bf55053 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 11 Oct 2022 12:45:08 +0300 Subject: [PATCH 1/2] WIP: hypothesis setup --- .github/workflows/hypothesis.yml | 43 +++++++++++++++++++ Tools/hypothesis/Makefile | 27 ++++++++++++ Tools/hypothesis/requirements.txt | 1 + Tools/hypothesis/tests/__init__.py | 0 .../tests/test_builtins/__init__.py | 0 .../tests/test_builtins/test_min.py | 15 +++++++ 6 files changed, 86 insertions(+) create mode 100644 .github/workflows/hypothesis.yml create mode 100644 Tools/hypothesis/Makefile create mode 100644 Tools/hypothesis/requirements.txt create mode 100644 Tools/hypothesis/tests/__init__.py create mode 100644 Tools/hypothesis/tests/test_builtins/__init__.py create mode 100644 Tools/hypothesis/tests/test_builtins/test_min.py diff --git a/.github/workflows/hypothesis.yml b/.github/workflows/hypothesis.yml new file mode 100644 index 00000000000000..9edf8ceed78fe7 --- /dev/null +++ b/.github/workflows/hypothesis.yml @@ -0,0 +1,43 @@ +name: hypothesis + +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * 5" + pull_request: + types: [labeled] + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + build_ubuntu: + name: 'Ubuntu' + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'test-with-hypothesis' }} + env: + OPENSSL_VER: 1.1.1q + PYTHONSTRICTEXTENSIONBUILD: 1 + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ubuntu-hypothesis-${{ hashFiles('Tools/hypothesis/requirements.txt') }} + restore-keys: | + ubuntu-hypothesis- + - name: 'Install Dependencies' + run: sudo ./.github/workflows/posix-deps-apt.sh && sudo apt-get install wamerican + - name: 'Configure CPython' + run: ./configure --with-pydebug + - name: 'Build CPython' + run: make -j4 + + - name: 'Install dependencies' + run: make -C Tools/hypothesis PYTHON=../../python venv + - name: Run hypothesis tests + run: make -C Tools/hypothesis PYTHON=../../python test diff --git a/Tools/hypothesis/Makefile b/Tools/hypothesis/Makefile new file mode 100644 index 00000000000000..8f642fb6180dfa --- /dev/null +++ b/Tools/hypothesis/Makefile @@ -0,0 +1,27 @@ +# +# Makefile for Python property-based-testing +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# + +# You can set these variables from the command line. +PYTHON = python3 +VENVDIR = ./venv + +.PHONY: venv test + +clean-venv: + rm -rf $(VENVDIR) + +venv: + @if [ -d $(VENVDIR) ] ; then \ + echo "venv already exists."; \ + echo "To recreate it, remove it first with \`make clean-venv'."; \ + else \ + $(PYTHON) -m venv $(VENVDIR); \ + $(VENVDIR)/bin/python3 -m pip install -U pip setuptools; \ + $(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \ + echo "The venv has been created in the $(VENVDIR) directory"; \ + fi + +test: + $(VENVDIR)/bin/python3 -m unittest discover ./tests diff --git a/Tools/hypothesis/requirements.txt b/Tools/hypothesis/requirements.txt new file mode 100644 index 00000000000000..bc5baeeb63cce9 --- /dev/null +++ b/Tools/hypothesis/requirements.txt @@ -0,0 +1 @@ +hypothesis>6,<7 diff --git a/Tools/hypothesis/tests/__init__.py b/Tools/hypothesis/tests/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/Tools/hypothesis/tests/test_builtins/__init__.py b/Tools/hypothesis/tests/test_builtins/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/Tools/hypothesis/tests/test_builtins/test_min.py b/Tools/hypothesis/tests/test_builtins/test_min.py new file mode 100644 index 00000000000000..5bcfb66e5ef13a --- /dev/null +++ b/Tools/hypothesis/tests/test_builtins/test_min.py @@ -0,0 +1,15 @@ +import unittest + +from hypothesis import given, strategies as st + + +class TestMin(unittest.TestCase): + @given( + st.one_of( + st.lists(st.integers()), st.tuples(st.integers()), + ).filter(lambda seq: len(seq) != 0) + ) + def test_min(self, seq): + lower = min(seq) + for item in seq: + self.assertLessEqual(lower, item) From 09f1a50672a71d8cae57517616469cab7b794a50 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 11 Oct 2022 14:19:44 +0300 Subject: [PATCH 2/2] Typo --- Tools/hypothesis/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/hypothesis/requirements.txt b/Tools/hypothesis/requirements.txt index bc5baeeb63cce9..361b0771ee44ce 100644 --- a/Tools/hypothesis/requirements.txt +++ b/Tools/hypothesis/requirements.txt @@ -1 +1 @@ -hypothesis>6,<7 +hypothesis>=6,<7