Debian Codegraph @

hypothesis-python/tests/cover/test_falsifying_example_output.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 pytest
12
13 from hypothesis import Phase, example, given, settings, strategies as st
14
15 OUTPUT_WITH_BREAK = """
16 Falsifying explicit example: test(
17 x={0!r},
18 y={0!r},
19 )
20 """
21
22
23 @pytest.mark.parametrize("n", [10, 100])
24 def test_inserts_line_breaks_only_at_appropriate_lengths(n):
25 @example("0" * n, "0" * n)
26 @given(st.text(), st.text())
27 def test(x, y):
28 assert x < y
29
30 with pytest.raises(AssertionError) as err:
31 test()
32
33 assert OUTPUT_WITH_BREAK.format("0" * n).strip() == "\n".join(err.value.__notes__)
34
35
36 @given(kw=st.none())
37 def generate_phase(*args, kw):
38 assert args != (1, 2, 3)
39
40
41 @given(kw=st.none())
42 @example(kw=None)
43 @settings(phases=[Phase.explicit])
44 def explicit_phase(*args, kw):
45 assert args != (1, 2, 3)
46
47
48 @pytest.mark.parametrize(
49 "fn",
50 [generate_phase, explicit_phase],
51 ids=lambda fn: fn.__name__,
52 )
53 def test_vararg_output(fn):
54 with pytest.raises(AssertionError) as err:
55 fn(1, 2, 3)
56
57 assert "1,\n 2,\n 3,\n" in "\n".join(err.value.__notes__)