Skip to content

Commit

Permalink
Move tests for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed May 1, 2022
1 parent a943e05 commit 3b95e56
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
5 changes: 2 additions & 3 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
RELEASE_TYPE: minor

This release updates :func:`hypothesis.strategies.uuids` by introducing an
``allow_nil`` argument, defaulting to ``False``. If ``allow_nil=True``,
nil UUID would be generated more often
This release adds an ``allow_nil`` argument to :func:`~hypothesis.strategies.uuids`,
which you can use to... generate the nil UUID. Thanks to Shlok Gandhi for the patch!
32 changes: 32 additions & 0 deletions hypothesis-python/tests/cover/test_uuids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is part of Hypothesis, which may be found at
# https://github.com/HypothesisWorks/hypothesis/
#
# Copyright the Hypothesis Authors.
# Individual contributors are listed in AUTHORS.rst and the git log.
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.

import uuid

import pytest

from hypothesis import strategies as st
from hypothesis.errors import InvalidArgument

from tests.common.debug import assert_no_examples, find_any


def test_no_nil_uuid_by_default():
assert_no_examples(st.uuids(), lambda x: x == uuid.UUID(int=0))


def test_can_generate_nil_uuid():
find_any(st.uuids(allow_nil=True), lambda x: x == uuid.UUID(int=0))


def test_can_only_allow_nil_uuid_with_none_version():
st.uuids(version=None, allow_nil=True).example()
with pytest.raises(InvalidArgument):
st.uuids(version=4, allow_nil=True).example()
18 changes: 1 addition & 17 deletions hypothesis-python/tests/nocover/test_uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.

import uuid

import pytest

from hypothesis import given, strategies as st
from hypothesis.errors import InvalidArgument

from tests.common.debug import assert_no_examples, minimal
from tests.common.debug import minimal


@given(st.lists(st.uuids()))
Expand All @@ -35,17 +33,3 @@ def inner(uuid):
assert version == uuid.version

inner()


def test_no_nil_uuid():
assert_no_examples(st.uuids(), lambda x: x == uuid.UUID(int=0))


def test_nil_uuid():
st.uuids(allow_nil=True), lambda x: x == uuid.UUID(int=0)


def test_can_only_allow_nil_uuid_with_none_version():
st.uuids(version=None, allow_nil=True).example()
with pytest.raises(InvalidArgument):
st.uuids(version=4, allow_nil=True).example()

0 comments on commit 3b95e56

Please sign in to comment.