Debian Codegraph @

hypothesis-python/tests/nocover/test_sharing.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.debug import find_any, minimal
14
15 x = st.shared(st.integers())
16
17
18 @given(x, x)
19 def test_sharing_is_by_instance_by_default(a, b):
20 assert a == b
21
22
23 @given(st.shared(st.integers(), key="hi"), st.shared(st.integers(), key="hi"))
24 def test_different_instances_with_the_same_key_are_shared(a, b):
25 assert a == b
26
27
28 def test_different_instances_are_not_shared():
29 find_any(
30 st.tuples(st.shared(st.integers()), st.shared(st.integers())),
31 lambda x: x[0] != x[1],
32 )
33
34
35 def test_different_keys_are_not_shared():
36 find_any(
37 st.tuples(st.shared(st.integers(), key=1), st.shared(st.integers(), key=2)),
38 lambda x: x[0] != x[1],
39 )
40
41
42 def test_keys_and_default_are_not_shared():
43 find_any(
44 st.tuples(st.shared(st.integers(), key=1), st.shared(st.integers())),
45 lambda x: x[0] != x[1],
46 )
47
48
49 def test_can_simplify_shared_lists():
50 xs = minimal(
51 st.lists(st.shared(st.integers())), lambda x: len(x) >= 10 and x[0] != 0
52 )
53 assert xs == [1] * 10
54
55
56 def test_simplify_shared_linked_to_size():
57 xs = minimal(st.lists(st.shared(st.integers())), lambda t: sum(t) >= 1000)
58 assert sum(xs[:-1]) < 1000
59 assert (xs[0] - 1) * len(xs) < 1000