Debian Codegraph @

hypothesis-python/tests/cover/test_uuids.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 uuid
12
13 import pytest
14
15 from hypothesis import strategies as st
16 from hypothesis.errors import InvalidArgument
17
18 from tests.common.debug import assert_no_examples, check_can_generate_examples, find_any
19
20
21 def test_no_nil_uuid_by_default():
22 assert_no_examples(st.uuids(), lambda x: x == uuid.UUID(int=0))
23
24
25 def test_can_generate_nil_uuid():
26 find_any(st.uuids(allow_nil=True), lambda x: x == uuid.UUID(int=0))
27
28
29 def test_can_only_allow_nil_uuid_with_none_version():
30 check_can_generate_examples(st.uuids(version=None, allow_nil=True))
31 with pytest.raises(InvalidArgument):
32 check_can_generate_examples(st.uuids(version=4, allow_nil=True))
33 with pytest.raises(InvalidArgument):
34 check_can_generate_examples(st.uuids(version=None, allow_nil="not a bool"))