Skip to content

Commit

Permalink
Merge pull request #4273 from tybug/fix-docs
Browse files Browse the repository at this point in the history
Fix code blocks in changelog
  • Loading branch information
tybug authored Feb 24, 2025
2 parents 844dad8 + 751f06b commit 0144533
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 9 additions & 4 deletions hypothesis-python/docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ Improve the clarity of printing counterexamples in :doc:`stateful testing <state

For example, we now print:

.. code-block: python
.. code-block:: python
a_0 = state.add_to_bundle(a=0)
state.unrelated(value=0)
instead of

.. code-block: python
.. code-block:: python
a_0 = state.add_to_bundle(a=0)
state.unrelated(value=a_0)
Expand Down Expand Up @@ -1893,14 +1893,17 @@ This patch supports assigning ``settings = settings(...)`` as a class attribute
on a subclass of a ``.TestCase`` attribute of a :class:`~hypothesis.stateful.RuleBasedStateMachine`.
Previously, this did nothing at all.

.. code-block: python
.. code-block:: python
# works as of this release
class TestMyStatefulMachine(MyStatefulMachine.TestCase):
settings = settings(max_examples=10000)
# the old way still works, but it's more verbose.
MyStateMachine.TestCase.settings = settings(max_examples=10000)
class TestMyStatefulMachine(MyStatefulMachine.TestCase):
pass
Expand All @@ -1916,12 +1919,14 @@ This release makes it an error to assign ``settings = settings(...)``
as a class attribute on a :class:`~hypothesis.stateful.RuleBasedStateMachine`.
This has never had any effect, and it should be used as a decorator instead:

.. code-block: python
.. code-block:: python
class BadMachine(RuleBasedStateMachine):
"""This doesn't do anything, and is now an error!"""
settings = settings(derandomize=True)
@settings(derandomize=True)
class GoodMachine(RuleBasedStateMachine):
"""This is the right way to do it :-)"""
Expand Down
4 changes: 2 additions & 2 deletions tooling/src/hypothesistooling/releasemanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

import re
from datetime import datetime
from datetime import datetime, timezone

import hypothesistooling as tools

Expand All @@ -30,7 +30,7 @@ def release_date_string():
through a release."""
global __RELEASE_DATE_STRING
if __RELEASE_DATE_STRING is None:
__RELEASE_DATE_STRING = datetime.utcnow().strftime("%Y-%m-%d")
__RELEASE_DATE_STRING = datetime.now(timezone.utc).strftime("%Y-%m-%d")
return __RELEASE_DATE_STRING


Expand Down
13 changes: 13 additions & 0 deletions whole_repo_tests/test_rst_is_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# obtain one at https://mozilla.org/MPL/2.0/.

import os
import re
from pathlib import Path

import hypothesistooling as tools
from hypothesistooling.projects import hypothesispython as hp
Expand All @@ -32,6 +34,17 @@ def test_passes_rst_lint():
pip_tool("rst-lint", *(f for f in ALL_RST if not is_sphinx(f)))


def test_rst_code_blocks():
# has bitten us before https://github.com/HypothesisWorks/hypothesis/pull/4273
pattern = re.compile(r"^\.\.\s+code-block:\s+", re.MULTILINE)
for f in ALL_RST:
matches = pattern.search(Path(f).read_text())
assert not matches, (
f"incorrect code block syntax in {f}. Use `.. code-block::` "
"instead of `.. code-block:`"
)


def disabled_test_passes_flake8():
# TODO: get these whitespace checks without flake8?
pip_tool("flake8", "--select=W191,W291,W292,W293,W391", *ALL_RST)

0 comments on commit 0144533

Please sign in to comment.