Debian Codegraph @

hypothesis-python/tests/cover/test_detection.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, is_hypothesis_test
12 from hypothesis.stateful import RuleBasedStateMachine, rule
13 from hypothesis.strategies import integers
14
15
16 def test_functions_default_to_not_tests():
17 def foo():
18 pass
19
20 assert not is_hypothesis_test(foo)
21
22
23 def test_methods_default_to_not_tests():
24 class Foo:
25 def foo(self):
26 pass
27
28 assert not is_hypothesis_test(Foo().foo)
29
30
31 def test_detection_of_functions():
32 @given(integers())
33 def test(i):
34 pass
35
36 assert is_hypothesis_test(test)
37
38
39 def test_detection_of_methods():
40 class Foo:
41 @given(integers())
42 def test(self, i):
43 pass
44
45 assert is_hypothesis_test(Foo().test)
46
47
48 def test_detection_of_stateful_tests():
49 class Stuff(RuleBasedStateMachine):
50 @rule(x=integers())
51 def a_rule(self, x):
52 pass
53
54 assert is_hypothesis_test(Stuff.TestCase().runTest)