Debian Codegraph @

hypothesis-python/tests/nocover/test_cacheable.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 gc
12 import weakref
13
14 import pytest
15
16 from hypothesis import given, settings, strategies as st
17
18 from tests.common.utils import xfail_if_gil_disabled
19
20
21 @pytest.mark.parametrize(
22 "s",
23 [
24 st.floats(),
25 st.tuples(st.integers()),
26 st.tuples(),
27 st.one_of(st.integers(), st.text()),
28 ],
29 )
30 def test_is_cacheable(s):
31 assert s.is_cacheable
32
33
34 @pytest.mark.parametrize(
35 "s",
36 [
37 st.just([]),
38 st.tuples(st.integers(), st.just([])),
39 st.one_of(st.integers(), st.text(), st.just([])),
40 ],
41 )
42 def test_is_not_cacheable(s):
43 assert not s.is_cacheable
44
45
46 def test_non_cacheable_things_are_not_cached():
47 x = st.just([])
48 assert st.tuples(x) != st.tuples(x)
49
50
51 def test_cacheable_things_are_cached():
52 x = st.just(())
53 assert st.tuples(x) == st.tuples(x)
54
55
56 @xfail_if_gil_disabled
57 def test_local_types_are_garbage_collected_issue_493():
58 store = None
59
60 def run_locally():
61 class Test:
62 @settings(database=None)
63 @given(st.integers())
64 def test(self, i):
65 pass
66
67 nonlocal store
68 store = weakref.ref(Test)
69 Test().test()
70
71 run_locally()
72 del run_locally
73 assert store() is not None
74 gc.collect()
75 assert store() is None