Skip to content

Commit c3943fa

Browse files
authored
Merge pull request #4418 from tybug/docs-cleanup
Improve `@example` docs
2 parents 8b0a35b + 5ea4b68 commit c3943fa

File tree

11 files changed

+391
-332
lines changed

11 files changed

+391
-332
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RELEASE_TYPE: patch
2+
3+
Improve documentation of |@example|.

hypothesis-python/docs/changelog.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6925,8 +6925,7 @@ This release consists of some internal refactoring to the shrinker in preparatio
69256925
5.18.0 - 2020-06-22
69266926
-------------------
69276927

6928-
This release teaches Hypothesis to :ref:`shorten tracebacks <v3.79.2>` for
6929-
:ref:`explicit examples <providing-explicit-examples>`, as we already do
6928+
This release teaches Hypothesis to :ref:`shorten tracebacks <v3.79.2>` for |@example|, as we already do
69306929
for generated examples, so that you can focus on your code rather than ours.
69316930

69326931
If you have multiple failing explicit examples, they will now all be reported.
@@ -10874,7 +10873,7 @@ and adds a CI check so we don't add new ones.
1087410873
This patch fixes two bugs (:issue:`944` and :issue:`1521`), where messages
1087510874
about :func:`@seed <hypothesis.seed>` did not check the current verbosity
1087610875
setting, and the wrong settings were active while executing
10877-
:ref:`explicit examples <providing-explicit-examples>`.
10876+
explicit examples from |@example|.
1087810877

1087910878
.. _v3.71.5:
1088010879

hypothesis-python/docs/conf.py

Lines changed: 2 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def setup(app):
116116

117117

118118
language = "en"
119-
exclude_patterns = ["_build"]
119+
exclude_patterns = ["_build", "prolog.rst"]
120120
pygments_style = "sphinx"
121121
todo_include_todos = False
122122

@@ -166,168 +166,7 @@ def setup(app):
166166

167167
autodoc_mock_imports = ["numpy", "pandas", "redis", "django", "pytz"]
168168

169-
rst_prolog = """
170-
.. |given| replace:: :func:`~hypothesis.given`
171-
.. |@given| replace:: :func:`@given <hypothesis.given>`
172-
.. |@example| replace:: :func:`@example <hypothesis.example>`
173-
.. |@example.xfail| replace:: :func:`@example(...).xfail() <hypothesis.example.xfail>`
174-
.. |@settings| replace:: :func:`@settings <hypothesis.settings>`
175-
.. |settings| replace:: :func:`settings <hypothesis.settings>`
176-
.. |@composite| replace:: :func:`@composite <hypothesis.strategies.composite>`
177-
.. |assume| replace:: :func:`~hypothesis.assume`
178-
.. |target| replace:: :func:`~hypothesis.target`
179-
.. |event| replace:: :func:`~hypothesis.event`
180-
.. |note| replace:: :func:`~hypothesis.note`
181-
182-
.. |max_examples| replace:: :obj:`~hypothesis.settings.max_examples`
183-
.. |settings.max_examples| replace:: :obj:`settings.max_examples <hypothesis.settings.max_examples>`
184-
.. |settings.database| replace:: :obj:`settings.database <hypothesis.settings.database>`
185-
.. |settings.deadline| replace:: :obj:`settings.deadline <hypothesis.settings.deadline>`
186-
.. |settings.derandomize| replace:: :obj:`settings.derandomize <hypothesis.settings.derandomize>`
187-
.. |settings.phases| replace:: :obj:`settings.phases <hypothesis.settings.phases>`
188-
.. |settings.print_blob| replace:: :obj:`settings.print_blob <hypothesis.settings.print_blob>`
189-
.. |settings.report_multiple_bugs| replace:: :obj:`settings.report_multiple_bugs <hypothesis.settings.report_multiple_bugs>`
190-
.. |settings.verbosity| replace:: :obj:`settings.verbosity <hypothesis.settings.verbosity>`
191-
.. |settings.suppress_health_check| replace:: \
192-
:obj:`settings.suppress_health_check <hypothesis.settings.suppress_health_check>`
193-
.. |settings.stateful_step_count| replace:: :obj:`settings.stateful_step_count <hypothesis.settings.stateful_step_count>`
194-
.. |settings.backend| replace:: :obj:`settings.backend <hypothesis.settings.backend>`
195-
196-
.. |~settings.max_examples| replace:: :obj:`~hypothesis.settings.max_examples`
197-
.. |~settings.database| replace:: :obj:`~hypothesis.settings.database`
198-
.. |~settings.deadline| replace:: :obj:`~hypothesis.settings.deadline`
199-
.. |~settings.derandomize| replace:: :obj:`~hypothesis.settings.derandomize`
200-
.. |~settings.phases| replace:: :obj:`~hypothesis.settings.phases`
201-
.. |~settings.print_blob| replace:: :obj:`~hypothesis.settings.print_blob`
202-
.. |~settings.report_multiple_bugs| replace:: :obj:`~hypothesis.settings.report_multiple_bugs`
203-
.. |~settings.verbosity| replace:: :obj:`~hypothesis.settings.verbosity`
204-
.. |~settings.suppress_health_check| replace:: :obj:`~hypothesis.settings.suppress_health_check`
205-
.. |~settings.stateful_step_count| replace:: :obj:`~hypothesis.settings.stateful_step_count`
206-
.. |~settings.backend| replace:: :obj:`~hypothesis.settings.backend`
207-
208-
.. |HealthCheck.data_too_large| replace:: :obj:`HealthCheck.data_too_large <hypothesis.HealthCheck.data_too_large>`
209-
.. |HealthCheck.filter_too_much| replace:: :obj:`HealthCheck.filter_too_much <hypothesis.HealthCheck.filter_too_much>`
210-
.. |HealthCheck.too_slow| replace:: :obj:`HealthCheck.too_slow <hypothesis.HealthCheck.too_slow>`
211-
.. |HealthCheck.function_scoped_fixture| replace:: \
212-
:obj:`HealthCheck.function_scoped_fixture <hypothesis.HealthCheck.function_scoped_fixture>`
213-
.. |HealthCheck.differing_executors| replace:: \
214-
:obj:`HealthCheck.differing_executors <hypothesis.HealthCheck.differing_executors>`
215-
.. |HealthCheck| replace:: :obj:`~hypothesis.HealthCheck`
216-
217-
.. |Phase| replace:: :obj:`Phase <hypothesis.Phase>`
218-
.. |Phase.explicit| replace:: :obj:`Phase.explicit <hypothesis.Phase.explicit>`
219-
.. |Phase.reuse| replace:: :obj:`Phase.reuse <hypothesis.Phase.reuse>`
220-
.. |Phase.generate| replace:: :obj:`Phase.generate <hypothesis.Phase.generate>`
221-
.. |Phase.target| replace:: :obj:`Phase.target <hypothesis.Phase.target>`
222-
.. |Phase.shrink| replace:: :obj:`Phase.shrink <hypothesis.Phase.shrink>`
223-
.. |Phase.explain| replace:: :obj:`Phase.explain <hypothesis.Phase.explain>`
224-
225-
.. |Verbosity| replace:: :obj:`~hypothesis.Verbosity`
226-
.. |Verbosity.verbose| replace:: :obj:`Verbosity.verbose <hypothesis.Verbosity.verbose>`
227-
.. |Verbosity.debug| replace:: :obj:`Verbosity.debug <hypothesis.Verbosity.debug>`
228-
.. |Verbosity.normal| replace:: :obj:`Verbosity.normal <hypothesis.Verbosity.normal>`
229-
.. |Verbosity.quiet| replace:: :obj:`Verbosity.quiet <hypothesis.Verbosity.quiet>`
230-
231-
.. |InvalidArgument| replace:: :obj:`InvalidArgument <hypothesis.errors.InvalidArgument>`
232-
.. |DidNotReproduce| replace:: :obj:`DidNotReproduce <hypothesis.errors.DidNotReproduce>`
233-
234-
.. |st.lists| replace:: :func:`~hypothesis.strategies.lists`
235-
.. |st.integers| replace:: :func:`~hypothesis.strategies.integers`
236-
.. |st.floats| replace:: :func:`~hypothesis.strategies.floats`
237-
.. |st.booleans| replace:: :func:`~hypothesis.strategies.booleans`
238-
.. |st.none| replace:: :func:`~hypothesis.strategies.none`
239-
.. |st.composite| replace:: :func:`@composite <hypothesis.strategies.composite>`
240-
.. |st.data| replace:: :func:`~hypothesis.strategies.data`
241-
.. |st.one_of| replace:: :func:`~hypothesis.strategies.one_of`
242-
.. |st.text| replace:: :func:`~hypothesis.strategies.text`
243-
.. |st.characters| replace:: :func:`~hypothesis.strategies.characters`
244-
.. |st.tuples| replace:: :func:`~hypothesis.strategies.tuples`
245-
.. |st.sets| replace:: :func:`~hypothesis.strategies.sets`
246-
.. |st.dictionaries| replace:: :func:`~hypothesis.strategies.dictionaries`
247-
.. |st.fixed_dictionaries| replace:: :func:`~hypothesis.strategies.fixed_dictionaries`
248-
.. |st.datetimes| replace:: :func:`~hypothesis.strategies.datetimes`
249-
.. |st.builds| replace:: :func:`~hypothesis.strategies.builds`
250-
.. |st.recursive| replace:: :func:`~hypothesis.strategies.recursive`
251-
.. |st.deferred| replace:: :func:`~hypothesis.strategies.deferred`
252-
.. |st.from_type| replace:: :func:`~hypothesis.strategies.from_type`
253-
.. |st.sampled_from| replace:: :func:`~hypothesis.strategies.sampled_from`
254-
.. |st.uuids| replace:: :func:`~hypothesis.strategies.uuids`
255-
.. |st.ip_addresses| replace:: :func:`~hypothesis.strategies.ip_addresses`
256-
.. |st.register_type_strategy| replace:: :func:`~hypothesis.strategies.register_type_strategy`
257-
.. |st.just| replace:: :func:`~hypothesis.strategies.just`
258-
.. |st.domains| replace:: :func:`~hypothesis.provisional.domains`
259-
.. |st.urls| replace:: :func:`~hypothesis.provisional.urls`
260-
261-
.. |django.from_form| replace:: :func:`~hypothesis.extra.django.from_form`
262-
.. |django.from_model| replace:: :func:`~hypothesis.extra.django.from_model`
263-
.. |django.from_field| replace:: :func:`~hypothesis.extra.django.from_field`
264-
265-
.. |settings.register_profile| replace:: :func:`~hypothesis.settings.register_profile`
266-
.. |settings.get_profile| replace:: :func:`~hypothesis.settings.get_profile`
267-
.. |settings.load_profile| replace:: :func:`~hypothesis.settings.load_profile`
268-
269-
.. |SearchStrategy| replace:: :class:`~hypothesis.strategies.SearchStrategy`
270-
.. |.filter| replace:: :func:`.filter() <hypothesis.strategies.SearchStrategy.filter>`
271-
.. |.filter()| replace:: :func:`.filter() <hypothesis.strategies.SearchStrategy.filter>`
272-
.. |.flatmap| replace:: :func:`.flatmap() <hypothesis.strategies.SearchStrategy.flatmap>`
273-
.. |.flatmap()| replace:: :func:`.flatmap() <hypothesis.strategies.SearchStrategy.flatmap>`
274-
.. |.map| replace:: :func:`.map() <hypothesis.strategies.SearchStrategy.map>`
275-
.. |.map()| replace:: :func:`.map() <hypothesis.strategies.SearchStrategy.map>`
276-
.. |.example()| replace:: :func:`.example() <hypothesis.strategies.SearchStrategy.example>`
277-
278-
.. |PrimitiveProvider| replace:: :class:`~hypothesis.internal.conjecture.providers.PrimitiveProvider`
279-
.. |PrimitiveProvider.realize| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.realize`
280-
.. |PrimitiveProvider.draw_integer| replace:: \
281-
:func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.draw_integer`
282-
.. |PrimitiveProvider.draw_boolean| replace:: \
283-
:func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.draw_boolean`
284-
.. |PrimitiveProvider.draw_float| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.draw_float`
285-
.. |PrimitiveProvider.draw_string| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.draw_string`
286-
.. |PrimitiveProvider.draw_bytes| replace:: :func:`~hypothesis.internal.conjecture.providers.PrimitiveProvider.draw_bytes`
287-
288-
.. |AVAILABLE_PROVIDERS| replace:: :data:`~hypothesis.internal.conjecture.providers.AVAILABLE_PROVIDERS`
289-
.. |TESTCASE_CALLBACKS| replace:: :data:`~hypothesis.internal.observability.TESTCASE_CALLBACKS`
290-
.. |BUFFER_SIZE| replace:: :data:`~hypothesis.internal.conjecture.engine.BUFFER_SIZE`
291-
.. |MAX_SHRINKS| replace:: :data:`~hypothesis.internal.conjecture.engine.MAX_SHRINKS`
292-
.. |MAX_SHRINKING_SECONDS| replace:: :data:`~hypothesis.internal.conjecture.engine.MAX_SHRINKING_SECONDS`
293-
.. |BackendCannotProceed| replace:: :exc:`~hypothesis.errors.BackendCannotProceed`
294-
295-
.. |@rule| replace:: :func:`@rule <hypothesis.stateful.rule>`
296-
.. |RuleBasedStateMachine| replace:: :class:`~hypothesis.stateful.RuleBasedStateMachine`
297-
298-
.. |@reproduce_failure| replace:: :func:`@reproduce_failure <hypothesis.reproduce_failure>`
299-
.. |@seed| replace:: :func:`@seed <hypothesis.seed>`
300-
301-
.. |ExampleDatabase| replace:: :class:`~hypothesis.database.ExampleDatabase`
302-
.. |ExampleDatabase.save| replace:: :func:`~hypothesis.database.ExampleDatabase.save`
303-
.. |ExampleDatabase.delete| replace:: :func:`~hypothesis.database.ExampleDatabase.delete`
304-
.. |ExampleDatabase.fetch| replace:: :func:`~hypothesis.database.ExampleDatabase.fetch`
305-
.. |ExampleDatabase.move| replace:: :func:`~hypothesis.database.ExampleDatabase.move`
306-
.. |ExampleDatabase.add_listener| replace:: :func:`~hypothesis.database.ExampleDatabase.add_listener`
307-
.. |ExampleDatabase.remove_listener| replace:: :func:`~hypothesis.database.ExampleDatabase.remove_listener`
308-
.. |ExampleDatabase.clear_listeners| replace:: :func:`~hypothesis.database.ExampleDatabase.clear_listeners`
309-
.. |ExampleDatabase._start_listening| replace:: :func:`~hypothesis.database.ExampleDatabase._start_listening`
310-
.. |ExampleDatabase._stop_listening| replace:: :func:`~hypothesis.database.ExampleDatabase._stop_listening`
311-
.. |ExampleDatabase._broadcast_change| replace:: :func:`~hypothesis.database.ExampleDatabase._broadcast_change`
312-
313-
.. |DirectoryBasedExampleDatabase| replace:: :class:`~hypothesis.database.DirectoryBasedExampleDatabase`
314-
.. |InMemoryExampleDatabase| replace:: :class:`~hypothesis.database.InMemoryExampleDatabase`
315-
.. |ReadOnlyDatabase| replace:: :class:`~hypothesis.database.ReadOnlyDatabase`
316-
.. |MultiplexedDatabase| replace:: :class:`~hypothesis.database.MultiplexedDatabase`
317-
.. |GitHubArtifactDatabase| replace:: :class:`~hypothesis.database.GitHubArtifactDatabase`
318-
.. |BackgroundWriteDatabase| replace:: :class:`~hypothesis.database.BackgroundWriteDatabase`
319-
.. |RedisExampleDatabase| replace:: :class:`~hypothesis.extra.redis.RedisExampleDatabase`
320-
321-
.. |is_hypothesis_test| replace:: :func:`~hypothesis.is_hypothesis_test`
322-
323-
.. |str| replace:: :obj:`python:str`
324-
.. |int| replace:: :obj:`python:int`
325-
.. |bool| replace:: :obj:`python:bool`
326-
.. |bytes| replace:: :obj:`python:bytes`
327-
.. |float| replace:: :obj:`python:float`
328-
.. |assert| replace:: :keyword:`python:assert`
329-
.. |dataclasses| replace:: :mod:`python:dataclasses`
330-
"""
169+
rst_prolog = (Path(__file__).parent / "prolog.rst").read_text()
331170

332171
codeautolink_autodoc_inject = False
333172
codeautolink_global_preface = """

hypothesis-python/docs/extensions.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ standard library. Strategies for other things are also welcome; anything with
126126
external dependencies just goes in ``hypothesis.extra``.
127127

128128
Tools such as assertion helpers may also need to check whether the current
129-
test is using Hypothesis:
130-
131-
.. autofunction:: hypothesis.currently_in_test_context
132-
129+
test is using Hypothesis. For that, see |currently_in_test_context|.
133130

134131
.. _entry-points:
135132

@@ -139,9 +136,9 @@ Hypothesis integration via entry points
139136

140137
If you would like to ship Hypothesis strategies for a custom type - either as
141138
part of the upstream library, or as a third-party extension, there's a catch:
142-
:func:`~hypothesis.strategies.from_type` only works after the corresponding
143-
call to :func:`~hypothesis.strategies.register_type_strategy`, and you'll have
144-
the same problem with :func:`~hypothesis.register_random`. This means that
139+
|st.from_type| only works after the corresponding
140+
call to |st.register_type_strategy|, and you'll have
141+
the same problem with |register_random|. This means that
145142
either
146143

147144
- you have to try importing Hypothesis to register the strategy when *your*
@@ -251,9 +248,9 @@ Hypothesis includes the following backends:
251248
hypothesis
252249
The default backend.
253250
hypothesis-urandom
254-
The same as the default backend, but uses ``/dev/urandom`` to back the randomness
255-
behind its PRNG. The only reason to use this backend over the default is if you are also
256-
using `Antithesis <https://antithesis.com/>`_, in which case this enables Antithesis
251+
The same as the default backend, but uses ``/dev/urandom`` as its source of randomness,
252+
instead of the standard PRNG in |random.Random|. The only reason to use this backend over the default ``backend="hypothesis"`` is if you are also
253+
using `Antithesis <https://antithesis.com/>`_, in which case this allows Antithesis
257254
mutation of ``/dev/urandom`` to control the values generated by Hypothesis.
258255

259256
``/dev/urandom`` is not available on Windows, so we emit a warning and fall back to the
@@ -264,7 +261,7 @@ crosshair
264261

265262
Requires ``pip install hypothesis[crosshair]``.
266263

267-
You can change the backend for a test with the ``backend`` setting. For instance, after
264+
You can change the backend for a test with the |settings.backend| setting. For instance, after
268265
``pip install hypothesis[crosshair]``, you can use :pypi:`crosshair <crosshair-tool>` to
269266
generate examples with SMT via the :pypi:`hypothesis-crosshair` backend:
270267

hypothesis-python/docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hypothesis is the property-based testing library for Python. With Hypothesis, yo
5858
5959
You should start with the :doc:`tutorial <tutorial/index>`, or the more condensed :doc:`quickstart <quickstart>`.
6060

61-
.. rst-class:: clearfix row
61+
.. rst-class:: row
6262

6363
.. rst-class:: column column2 top-left
6464

@@ -90,7 +90,7 @@ Commentary oriented towards deepening your understanding of Hypothesis.
9090

9191
Technical API reference.
9292

93-
.. rst-class:: clearfix row
93+
.. rst-class:: row
9494

9595
.. toctree::
9696
:maxdepth: 1

0 commit comments

Comments
 (0)