| 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 time |
| 12 |
|
| 13 |
from hypothesis.strategies._internal import SearchStrategy |
| 14 |
|
| 15 |
|
| 16 |
class _Slow(SearchStrategy): |
| 17 |
def do_draw(self, data): |
| 18 |
time.sleep(1.01) |
| 19 |
data.draw_bytes(2, 2) |
| 20 |
|
| 21 |
|
| 22 |
SLOW = _Slow() |
| 23 |
|
| 24 |
|
| 25 |
class HardToShrink(SearchStrategy): |
| 26 |
def __init__(self): |
| 27 |
super().__init__() |
| 28 |
self.__last = None |
| 29 |
self.accepted = set() |
| 30 |
|
| 31 |
def do_draw(self, data): |
| 32 |
x = bytes(data.draw_integer(0, 255) for _ in range(100)) |
| 33 |
if x in self.accepted: |
| 34 |
return True |
| 35 |
ls = self.__last |
| 36 |
if ls is None: |
| 37 |
if all(x): |
| 38 |
self.__last = x |
| 39 |
self.accepted.add(x) |
| 40 |
return True |
| 41 |
else: |
| 42 |
return False |
| 43 |
diffs = [i for i in range(len(x)) if x[i] != ls[i]] |
| 44 |
if len(diffs) == 1: |
| 45 |
i = diffs[0] |
| 46 |
if x[i] + 1 == ls[i]: |
| 47 |
self.__last = x |
| 48 |
self.accepted.add(x) |
| 49 |
return True |
| 50 |
return False |