| 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 |
from random import Random |
| 12 |
|
| 13 |
from hypothesis import Phase, find, settings, strategies as st |
| 14 |
|
| 15 |
from tests.common.utils import Why, xfail_on_crosshair |
| 16 |
|
| 17 |
|
| 18 |
@xfail_on_crosshair(Why.symbolic_outside_context) |
| 19 |
def test_find_uses_provided_random(): |
| 20 |
prev = None |
| 21 |
|
| 22 |
for _ in range(3): |
| 23 |
seen = None |
| 24 |
|
| 25 |
def test(v): |
| 26 |
if len(v) > 5: |
| 27 |
nonlocal seen |
| 28 |
if seen is not None: |
| 29 |
return v == seen |
| 30 |
else: |
| 31 |
seen = v |
| 32 |
return True |
| 33 |
|
| 34 |
result = find( |
| 35 |
st.text(), |
| 36 |
test, |
| 37 |
random=Random(13), |
| 38 |
settings=settings(phases=[Phase.generate], max_examples=1000), |
| 39 |
) |
| 40 |
if prev is None: |
| 41 |
prev = result |
| 42 |
else: |
| 43 |
assert prev == result |