Debian Codegraph @

hypothesis-python/tests/snapshots/test_shrinking.py

raw
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 hypothesis import given, strategies as st
12
13 from tests.common.utils import run_test_for_falsifying_example
14 from tests.snapshots.conftest import SNAPSHOT_SETTINGS
15
16
17 def test_shrunk_list(snapshot):
18 @SNAPSHOT_SETTINGS
19 @given(xs=st.lists(st.integers(), min_size=1))
20 def inner(xs):
21 assert sum(xs) <= 1000
22
23 assert run_test_for_falsifying_example(inner) == snapshot
24
25
26 def test_shrunk_string(snapshot):
27 @SNAPSHOT_SETTINGS
28 @given(s=st.text(min_size=1))
29 def inner(s):
30 assert s == s.lower()
31
32 assert run_test_for_falsifying_example(inner) == snapshot
33
34
35 def test_shrunk_float(snapshot):
36 @SNAPSHOT_SETTINGS
37 @given(x=st.floats(min_value=0, max_value=1))
38 def inner(x):
39 assert x <= 0.5
40
41 assert run_test_for_falsifying_example(inner) == snapshot