| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
from hypothesis import HealthCheck, Verbosity, given, reject, settings, strategies as st |
| 14 |
from hypothesis.errors import Unsatisfiable |
| 15 |
|
| 16 |
from tests.common.debug import minimal |
| 17 |
from tests.common.utils import no_shrink |
| 18 |
|
| 19 |
|
| 20 |
@pytest.mark.parametrize("strat", [st.text(min_size=5)]) |
| 21 |
@settings(phases=no_shrink, deadline=None, suppress_health_check=list(HealthCheck)) |
| 22 |
@given(st.data()) |
| 23 |
def test_explore_arbitrary_function(strat, data): |
| 24 |
cache = {} |
| 25 |
|
| 26 |
def predicate(x): |
| 27 |
try: |
| 28 |
return cache[x] |
| 29 |
except KeyError: |
| 30 |
return cache.setdefault(x, data.draw(st.booleans(), label=repr(x))) |
| 31 |
|
| 32 |
try: |
| 33 |
minimal( |
| 34 |
strat, |
| 35 |
predicate, |
| 36 |
settings=settings( |
| 37 |
max_examples=10, database=None, verbosity=Verbosity.quiet |
| 38 |
), |
| 39 |
) |
| 40 |
except Unsatisfiable: |
| 41 |
reject() |