Skip to content

Commit

Permalink
Fix strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Apr 5, 2023
1 parent 7a62d3c commit 785b9d5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/strategies/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math
from functools import partial
from operator import not_
from typing import Any

from hypothesis import strategies as _st

Expand All @@ -26,27 +27,33 @@
str.title, str.capitalize,
str.casefold, str.swapcase])

sortables_with_keys = {
ordered_values_with_keys = {
_st.integers(): finite_numbers_keys,
_st.floats(allow_nan=False): maybe_infinite_numbers_keys,
_st.floats(allow_nan=False,
allow_infinity=False): finite_numbers_keys,
_st.booleans(): _st.just(not_) | finite_numbers_keys,
_st.text(): strings_keys
}
values_keys = {**sortables_with_keys,
_st.from_type(object): _st.sampled_from([id, lambda _: 0])}
unordered_values = _st.sampled_from([None, Ellipsis, NotImplemented])


def to_zero(_: Any) -> int:
return 0


values_keys = {**ordered_values_with_keys,
unordered_values: _st.sampled_from([id, to_zero])}
base_values_with_keys_strategies = _st.sampled_from(list(values_keys.items()))
values_with_keys_strategies = (
_st.sampled_from([(sortables, _st.none())
for sortables in sortables_with_keys.keys()])
for sortables in ordered_values_with_keys.keys()])
| _st.recursive(base_values_with_keys_strategies,
to_values_tuples_with_keys,
max_leaves=10)
)
values_with_keys = (
(_st.sampled_from(list(sortables_with_keys.keys()))
(_st.sampled_from(list(ordered_values_with_keys.keys()))
.flatmap(lambda values: _st.tuples(values, _st.none())))
| values_with_keys_strategies.flatmap(to_values_with_keys)
)
Expand Down

0 comments on commit 785b9d5

Please sign in to comment.