Skip to content

Commit

Permalink
Merge branch 'master' into datatree-ir
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 4, 2024
2 parents 285bbf9 + afca97e commit 2c16f46
Show file tree
Hide file tree
Showing 113 changed files with 1,339 additions and 651 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,55 @@ jobs:
- name: Run tests
run: TASK=${{ matrix.task }} ./build.sh

# See https://pyodide.org/en/stable/development/building-and-testing-packages.html#testing-packages-against-pyodide
# and https://github.com/numpy/numpy/blob/9a650391651c8486d8cb8b27b0e75aed5d36033e/.github/workflows/emscripten.yml
test-pyodide:
runs-on: ubuntu-latest
env:
NODE_VERSION: 18
# Note that the versions below must be updated in sync; we've automated
# that with `update_pyodide_versions()` in our weekly cronjob.
PYODIDE_VERSION: 0.25.0
PYTHON_VERSION: 3.11.3
EMSCRIPTEN_VERSION: 3.1.46
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up Node
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set up Emscripten
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
actions-cache-folder: emsdk-cache
- name: Build
run: |
pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
cd hypothesis-python/
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
- name: Set up Pyodide venv and install dependencies
run: |
pip install --upgrade setuptools pip wheel
python hypothesis-python/setup.py bdist_wheel
pip download --dest=dist/ hypothesis-python/ pytest tzdata # fetch all the wheels
rm dist/packaging-*.whl # fails with `invalid metadata entry 'name'`
pyodide venv .venv-pyodide
source .venv-pyodide/bin/activate
pip install dist/*.whl
- name: Run tests
run: |
source .venv-pyodide/bin/activate
python -m pytest hypothesis-python/tests/cover
deploy:
if: "github.event_name == 'push' && github.repository == 'HypothesisWorks/hypothesis'"
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.runtimes
/hypothesis-python/branch-check
/pythonpython3.*
.pyodide-xbuildenv

# python

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ bytes from:

```python
class TestData:
def draw_bytes(self, n):
...
def draw_bytes(self, n): ...
```

(note: The Python code in this article isn't an exact copy of what's
Expand Down Expand Up @@ -237,8 +236,7 @@ distribution hint:

```python
class TestData:
def draw_bytes(self, n, distribution=None):
...
def draw_bytes(self, n, distribution=None): ...
```

Where a distribution function takes a Random object
Expand Down Expand Up @@ -328,14 +326,11 @@ looks like this:

```python
class TestData:
def start_interval(self):
...
def start_interval(self): ...

def stop_interval(self):
...
def stop_interval(self): ...

def draw_bytes(self, n):
...
def draw_bytes(self, n): ...

def draw(self, strategy):
self.start_interval()
Expand Down
25 changes: 25 additions & 0 deletions hypothesis-python/docs/_static/better-signatures.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* don't use italics for param names; looks bad with "|" for unions */
.rst-content dl .sig-param {
font-style: normal;
}

/* Take out pointless vertical whitespace in the signatures.
* See also https://github.com/readthedocs/sphinx_rtd_theme/pull/1450 */
.rst-content dl .sig dl,
.rst-content dl .sig dd {
margin-bottom: 0;
}

/* Make signature boxes full-width, with view-source and header links right-aligned. */
.rst-content dl .sig {
width: -webkit-fill-available;
}
.rst-content .viewcode-link {
display: inline-flex;
float: inline-end;
margin-right: 1.5em;
}
.rst-content .headerlink {
position: absolute;
right: 0.5em;
}
100 changes: 97 additions & 3 deletions hypothesis-python/docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,100 @@ Hypothesis 6.x

.. include:: ../RELEASE.rst

.. _v6.98.0:

-------------------
6.98.0 - 2024-02-05
-------------------

This release deprecates use of the global random number generator while drawing
from a strategy, because this makes test cases less diverse and prevents us
from reporting minimal counterexamples (:issue:`3810`).

If you see this new warning, you can get a quick fix by using
:func:`~hypothesis.strategies.randoms`; or use more idiomatic strategies
:func:`~hypothesis.strategies.sampled_from`, :func:`~hypothesis.strategies.floats`,
:func:`~hypothesis.strategies.integers`, and so on.

Note that the same problem applies to e.g. ``numpy.random``, but
for performance reasons we only check the stdlib :mod:`random` module -
ignoring even other sources passed to :func:`~hypothesis.register_random`.

.. _v6.97.6:

-------------------
6.97.6 - 2024-02-04
-------------------

This patch updates our vendored `list of top-level domains <https://www.iana.org/domains/root/db>`__,
which is used by the provisional :func:`~hypothesis.provisional.domains` strategy.

.. _v6.97.5:

-------------------
6.97.5 - 2024-02-03
-------------------

This patch adds some :doc:`observability information <observability>`
about how many times predicates in :func:`~hypothesis.assume` or
:func:`~hypothesis.stateful.precondition` were satisfied, so that
downstream tools can warn you if some were *never* satisfied by
any test case.

.. _v6.97.4:

-------------------
6.97.4 - 2024-01-31
-------------------

This patch improves formatting and adds some cross-references to our docs.

.. _v6.97.3:

-------------------
6.97.3 - 2024-01-30
-------------------

Internal test refactoring.

.. _v6.97.2:

-------------------
6.97.2 - 2024-01-30
-------------------

This patch slightly changes how we replay examples from
:doc:`the database <database>`: if the behavior of the saved example has
changed, we now keep running the test case instead of aborting at the size
of the saved example. While we know it's not the *same* example, we might
as well continue running the test!

Because we now finish running a few more examples for affected tests, this
might be a slight slowdown - but correspondingly more likely to find a bug.

We've also applied similar tricks to the :ref:`target phase <phases>`, where
they are a pure performance improvement for affected tests.

.. _v6.97.1:

-------------------
6.97.1 - 2024-01-27
-------------------

Improves the performance of the :func:`~hypothesis.extra.numpy.arrays`
strategy when generating unique values.

.. _v6.97.0:

-------------------
6.97.0 - 2024-01-25
-------------------

Changes the distribution of :func:`~hypothesis.strategies.sampled_from` when
sampling from a :class:`~python:enum.Flag`. Previously, no-flags-set values would
never be generated, and all-flags-set values would be unlikely for large enums.
With this change, the distribution is more uniform in the number of flags set.

.. _v6.96.4:

-------------------
Expand Down Expand Up @@ -7223,7 +7317,7 @@ This release makes it an explicit error to call
as there are no possible values that can be generated (:issue:`1859`).

:func:`floats(min_value=0.0, max_value=-0.0) <hypothesis.strategies.floats>`
is now deprecated. While `0. == -0.` and we could thus generate either if
is now deprecated. While ``0. == -0.`` and we could thus generate either if
comparing by value, violating the sequence ordering of floats is a special
case we don't want or need.

Expand Down Expand Up @@ -7555,7 +7649,7 @@ one. These shapes are rare and have some odd behavior, but are particularly
important to test for just that reason!

In a related bigfix, :func:`~hypothesis.extra.numpy.arrays` now supports generating
zero-dimensional arrays with `dtype=object` and a strategy for iterable elements.
zero-dimensional arrays with ``dtype=object`` and a strategy for iterable elements.
Previously, the array element would incorrectly be set to the first item in the
generated iterable.

Expand Down Expand Up @@ -8020,7 +8114,7 @@ This release has no user visible changes but updates our URLs to use HTTPS.
-------------------

Hypothesis can now automatically generate values for Django models with a
`URLfield`, thanks to a new provisional strategy for URLs (:issue:`1388`).
`~django.db.models.URLField`, thanks to a new provisional strategy for URLs (:issue:`1388`).

.. _v3.86.6:

Expand Down
10 changes: 9 additions & 1 deletion hypothesis-python/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# obtain one at https://mozilla.org/MPL/2.0/.

import datetime
import re
import sys
import types
from pathlib import Path
Expand All @@ -18,9 +19,15 @@
root = Path(__file__).parent.parent
sys.path.append(str(root / "src"))

needs_sphinx = re.search(
r"sphinx==([0-9\.]+)", root.joinpath("../requirements/tools.txt").read_text()
).group(1)
default_role = "py:obj"
nitpicky = True

autodoc_member_order = "bysource"
autodoc_typehints = "none"
maximum_signature_line_length = 60 # either one line, or one param per line

extensions = [
"sphinx.ext.autodoc",
Expand Down Expand Up @@ -113,6 +120,7 @@ def setup(app):
"attrs": ("https://www.attrs.org/en/stable/", None),
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
"IPython": ("https://ipython.readthedocs.io/en/stable/", None),
"lark": ("https://lark-parser.readthedocs.io/en/stable/", None),
}

autodoc_mock_imports = ["numpy", "pandas", "redis", "django", "pytz"]
Expand Down Expand Up @@ -148,7 +156,7 @@ def setup(app):

html_static_path = ["_static"]

html_css_files = ["wrap-in-tables.css"]
html_css_files = ["better-signatures.css", "wrap-in-tables.css"]

htmlhelp_basename = "Hypothesisdoc"

Expand Down
9 changes: 3 additions & 6 deletions hypothesis-python/docs/details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ transformation before applying :func:`@given <hypothesis.given>`.
@given(x=integers())
@pytest.mark.trio
async def test(x):
...
async def test(x): ...
# Illustrative code, inside the pytest-trio plugin
Expand Down Expand Up @@ -677,8 +676,7 @@ supported use-case, again on a best-effort provisional basis. For example:

.. code:: python
def foo_strategy() -> SearchStrategy[Foo]:
...
def foo_strategy() -> SearchStrategy[Foo]: ...
.. class:: hypothesis.strategies.SearchStrategy

Expand Down Expand Up @@ -752,8 +750,7 @@ converting bytestrings into your objects by hand?
.. code:: python
@given(st.text())
def test_foo(s):
...
def test_foo(s): ...
# This is a traditional fuzz target - call it with a bytestring,
Expand Down
6 changes: 2 additions & 4 deletions hypothesis-python/docs/reproducing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ same examples each time they are executed, thanks to ``@seed()``:
@seed(1234)
@given(x=...)
def test(x):
...
def test(x): ...
@seed(6789)
class MyModel(RuleBasedStateMachine):
...
class MyModel(RuleBasedStateMachine): ...
The seed will not be printed if you could simply use ``@example`` instead.

Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ specific tests.
Optionally, you may define the environment variable to load a profile for you.
This is the suggested pattern for running your tests on CI.
The code below should run in a `conftest.py` or any setup/initialization section of your test suite.
The code below should run in a ``conftest.py`` or any setup/initialization section of your test suite.
If this variable is not defined the Hypothesis defined defaults will be loaded.

.. code-block:: pycon
Expand Down
4 changes: 2 additions & 2 deletions hypothesis-python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def local_file(name):
"dpcontracts": ["dpcontracts>=0.4"],
"redis": ["redis>=3.0.0"],
# zoneinfo is an odd one: every dependency is conditional, because they're
# only necessary on old versions of Python or Windows systems.
# only necessary on old versions of Python or Windows systems or emscripten.
"zoneinfo": [
"tzdata>=2023.4 ; sys_platform == 'win32'",
"tzdata>=2023.4 ; sys_platform == 'win32' or sys_platform == 'emscripten'",
"backports.zoneinfo>=0.2.1 ; python_version<'3.9'",
],
# We only support Django versions with upstream support - see
Expand Down
Loading

0 comments on commit 2c16f46

Please sign in to comment.