Debian Codegraph @

hypothesis-python/tests/cover/test_runner_strategy.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 unittest import TestCase
12
13 import pytest
14
15 from hypothesis import find, given, strategies as st
16 from hypothesis.errors import InvalidArgument
17 from hypothesis.stateful import RuleBasedStateMachine, rule
18
19
20 def test_cannot_use_without_a_runner():
21 @given(st.runner())
22 def f(x):
23 pass
24
25 with pytest.raises(InvalidArgument):
26 f()
27
28
29 def test_cannot_use_in_find_without_default():
30 with pytest.raises(InvalidArgument):
31 find(st.runner(), lambda x: True)
32
33
34 def test_is_default_in_find():
35 t = object()
36 assert find(st.runner(default=t), lambda x: True) == t
37
38
39 @given(st.runner(default=1))
40 def test_is_default_without_self(runner):
41 assert runner == 1
42
43
44 class TestStuff(TestCase):
45 @given(st.runner())
46 def test_runner_is_self(self, runner):
47 assert runner is self
48
49 @given(st.runner(default=3))
50 def test_runner_is_self_even_with_default(self, runner):
51 assert runner is self
52
53
54 class RunnerStateMachine(RuleBasedStateMachine):
55 @rule(runner=st.runner())
56 def step(self, runner):
57 assert runner is self
58
59
60 TestState = RunnerStateMachine.TestCase