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..361b0771ee44ce --- /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)