Debian Codegraph @

hypothesis-python/tests/common/__init__.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 import sys
12 from collections import namedtuple
13
14 from hypothesis.strategies import (
15 binary,
16 booleans,
17 builds,
18 complex_numbers,
19 decimals,
20 dictionaries,
21 fixed_dictionaries,
22 floats,
23 fractions,
24 frozensets,
25 integers,
26 just,
27 lists,
28 none,
29 one_of,
30 randoms,
31 recursive,
32 sampled_from,
33 sets,
34 text,
35 tuples,
36 )
37
38 from tests.common.debug import TIME_INCREMENT
39
40 __all__ = ["TIME_INCREMENT", "standard_types"]
41
42 OrderedPair = namedtuple("OrderedPair", ("left", "right"))
43 ABC = namedtuple("ABC", ("a", "b", "c"))
44
45
46 def abc(x, y, z):
47 return builds(ABC, x, y, z)
48
49
50 standard_types = [
51 lists(none(), max_size=0),
52 tuples(),
53 sets(none(), max_size=0),
54 frozensets(none(), max_size=0),
55 fixed_dictionaries({}),
56 abc(booleans(), booleans(), booleans()),
57 abc(booleans(), booleans(), integers()),
58 fixed_dictionaries({"a": integers(), "b": booleans()}),
59 dictionaries(booleans(), integers()),
60 dictionaries(text(), booleans()),
61 one_of(integers(), tuples(booleans())),
62 sampled_from(range(10)),
63 one_of(just("a"), just("b"), just("c")),
64 sampled_from(("a", "b", "c")),
65 integers(),
66 integers(min_value=3),
67 integers(min_value=(-(2**32)), max_value=(2**64)),
68 floats(),
69 floats(min_value=-2.0, max_value=3.0),
70 floats(),
71 floats(min_value=-2.0),
72 floats(),
73 floats(max_value=-0.0),
74 floats(),
75 floats(min_value=0.0),
76 floats(min_value=3.14, max_value=3.14),
77 text(),
78 binary(),
79 booleans(),
80 tuples(booleans(), booleans()),
81 frozensets(integers()),
82 sets(frozensets(booleans())),
83 complex_numbers(),
84 fractions(),
85 decimals(),
86 lists(lists(booleans())),
87 lists(floats(0.0, 0.0)),
88 integers().flatmap(
89 lambda right: integers(min_value=0).map(
90 lambda length: OrderedPair(right - length, right)
91 )
92 ),
93 integers().flatmap(lambda v: lists(just(v))),
94 integers().filter(lambda x: abs(x) > 100),
95 floats(min_value=-sys.float_info.max, max_value=sys.float_info.max),
96 none(),
97 randoms(use_true_random=True),
98 booleans().flatmap(lambda x: booleans() if x else complex_numbers()),
99 recursive(base=booleans(), extend=lambda x: lists(x, max_size=3), max_leaves=10),
100 ]