Debian Codegraph @

hypothesis-python/tests/quality/test_deferred_strategies.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 strategies as st
12
13 from tests.common.debug import minimal
14
15
16 def test_large_branching_tree():
17 tree = st.deferred(lambda: st.integers() | st.tuples(tree, tree, tree, tree, tree))
18 assert minimal(tree) == 0
19 assert minimal(tree, lambda x: isinstance(x, tuple)) == (0,) * 5
20
21
22 def test_non_trivial_json():
23 json = st.deferred(lambda: st.none() | st.floats() | st.text() | lists | objects)
24
25 lists = st.lists(json)
26 objects = st.dictionaries(st.text(), json)
27
28 assert minimal(json) is None
29 assert minimal(json, lambda x: isinstance(x, list) and x) == [None]
30 assert minimal(
31 json, lambda x: isinstance(x, dict) and isinstance(x.get(""), list)
32 ) == {"": []}
33
34
35 def test_self_recursive_lists():
36 x = st.deferred(lambda: st.lists(x))
37 assert minimal(x) == []
38 assert minimal(x, bool) == [[]]
39 assert minimal(x, lambda x: len(x) > 1) == [[], []]