Skip to content
forked from python/cpython
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: hypothesis setup #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/hypothesis.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions Tools/hypothesis/Makefile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Tools/hypothesis/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hypothesis>=6,<7
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions Tools/hypothesis/tests/test_builtins/test_min.py
Original file line number Diff line number Diff line change
@@ -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)