Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UniqueSampledListStrategy bug #2248

Merged
merged 1 commit into from Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,5 @@
RELEASE_TYPE: patch

This patch fixes a rare internal error in strategies for a list of
unique items sampled from a short non-unique sequence (:issue:`2247`).
The bug was discovered via :pypi:`hypothesis-jsonschema`.
Expand Up @@ -188,7 +188,7 @@ def do_draw(self, data):

remaining = LazySequenceCopy(self.element_strategy.elements)

while should_draw.more():
while remaining and should_draw.more():
i = len(remaining) - 1
j = cu.integer_range(data, 0, i)
if j != i:
Expand Down
5 changes: 5 additions & 0 deletions hypothesis-python/tests/cover/test_sampled_from.py
Expand Up @@ -92,3 +92,8 @@ def test_does_not_include_duplicates_even_when_duplicated_in_collection(ls):
@given(st.lists(st.sampled_from(hrange(100)), max_size=3, unique=True))
def test_max_size_is_respected_with_unique_sampled_from(ls):
assert len(ls) <= 3


@given(st.lists(st.sampled_from([0, 0.0]), unique=True, min_size=1))
def test_issue_2247_regression(ls):
assert len(ls) == 1