Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Nov 13, 2023
1 parent 39a26f1 commit 7f0b8d7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Issues = "https://github.com/python-jsonschema/referencing/issues/"
Funding = "https://github.com/sponsors/Julian"
Source = "https://github.com/python-jsonschema/referencing"

[project.optional-dependencies]
hypothesis = ["hypothesis"]

[project.entry-points.hypothesis]
_ = "referencing._hypothesis"

[tool.coverage.html]
show_contexts = true
skip_covered = false
Expand Down
33 changes: 33 additions & 0 deletions referencing/_hypothesis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
A plugin for making referencing objects usable within Hypothesis.
This module is meant to be used as an entry point, meaning it should
automatically be imported if both referencing and hypothesis are being used.
See https://hypothesis.readthedocs.io/en/latest/strategies.html#hypothesis-integration-via-setuptools-entry-points
and/or https://hatch.pypa.io/latest/config/metadata/#entry-points for further
details.
"""

from typing import Callable, TypeVar

from hypothesis import strategies

from referencing import Resource

contents = strategies.integers()

T = TypeVar("T")


def register(cls: type[T]):
def _register(strategy: Callable[[], T]):
strategies.register_type_strategy(cls, strategy)
return strategy

return _register


@register(Resource)
def resource():
return contents
12 changes: 12 additions & 0 deletions referencing/tests/test_hypothesis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Tests for (and via) referencing's Hypothesis support.
"""

from hypothesis import given, strategies

from referencing import Resource, Specification


@given(strategies.builds(Resource, specification=Specification.OPAQUE))
def test_opaque_resources_do_not_have_ids(resource):
print(resource)
1 change: 1 addition & 0 deletions test-requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
file:.#egg=referencing
hypothesis
pytest
pytest-subtests
5 changes: 5 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#
attrs==23.1.0
# via
# hypothesis
# pytest-subtests
# referencing
hypothesis==6.88.4
# via -r test-requirements.in
iniconfig==2.0.0
# via pytest
packaging==23.2
Expand All @@ -24,3 +27,5 @@ file:.#egg=referencing
# via -r test-requirements.in
rpds-py==0.12.0
# via referencing
sortedcontainers==2.4.0
# via hypothesis

0 comments on commit 7f0b8d7

Please sign in to comment.