Skip to content

Commit

Permalink
Merge pull request #2248 from Zac-HD/unique-sampled-bugfix
Browse files Browse the repository at this point in the history
Fix UniqueSampledListStrategy bug
  • Loading branch information
Zac-HD committed Dec 1, 2019
2 parents 894c252 + 5fcda2c commit 8892559
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit 8892559

Please sign in to comment.