Skip to content

Commit

Permalink
Rearrange strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 26, 2021
1 parent 0ee3b2e commit 6f01856
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 475 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch moves some internal code, so that future work can avoid
creating import cycles. There is no user-visible change.
Expand Up @@ -22,8 +22,10 @@
from hypothesis.strategies._internal.strategies import (
MappedSearchStrategy,
SearchStrategy,
check_strategy,
filter_not_satisfied,
)
from hypothesis.strategies._internal.utils import cacheable, defines_strategy


class TupleStrategy(SearchStrategy):
Expand Down Expand Up @@ -60,6 +62,23 @@ def calc_is_empty(self, recur):
return any(recur(e) for e in self.element_strategies)


@cacheable
@defines_strategy()
def tuples(*args: SearchStrategy) -> SearchStrategy[tuple]:
"""Return a strategy which generates a tuple of the same length as args by
generating the value at index i from args[i].
e.g. tuples(integers(), integers()) would generate a tuple of length
two with both values an integer.
Examples from this strategy shrink by shrinking their component parts.
"""
for arg in args:
check_strategy(arg)

return TupleStrategy(args)


class ListStrategy(SearchStrategy):
"""A strategy for lists which takes a strategy for its elements and the
allowed lengths, and generates lists with the correct size and contents."""
Expand Down

0 comments on commit 6f01856

Please sign in to comment.