Debian Codegraph @

hypothesis-python/tests/snapshots/test_combinators.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 enum import Flag, auto
12
13 from hypothesis import given, strategies as st
14
15 from tests.common.utils import run_test_for_falsifying_example
16 from tests.snapshots.conftest import SNAPSHOT_SETTINGS
17
18
19 class Direction(Flag):
20 NORTH = auto()
21 SOUTH = auto()
22 EAST = auto()
23 WEST = auto()
24
25
26 def test_data_draw(snapshot):
27 @SNAPSHOT_SETTINGS
28 @given(data=st.data())
29 def inner(data):
30 data.draw(st.integers())
31 data.draw(st.text(max_size=3))
32 raise AssertionError
33
34 assert run_test_for_falsifying_example(inner) == snapshot
35
36
37 def test_sampled_from_enum_flag(snapshot):
38 class Color(Flag):
39 RED = auto()
40 GREEN = auto()
41 BLUE = auto()
42
43 @SNAPSHOT_SETTINGS
44 @given(c=st.sampled_from(Color))
45 def inner(c):
46 assert not (c & Color.RED)
47
48 assert run_test_for_falsifying_example(inner) == snapshot
49
50
51 def test_sampled_from_module_level_enum_flag(snapshot):
52 @SNAPSHOT_SETTINGS
53 @given(d=st.sampled_from(Direction))
54 def inner(d):
55 assert not (d & Direction.NORTH)
56
57 assert run_test_for_falsifying_example(inner) == snapshot