Skip to content

Commit

Permalink
Observe clearer status_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Mar 24, 2024
1 parent 2fda65f commit 067fc76
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions hypothesis-python/src/hypothesis/extra/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,12 @@ def do_draw(self, data):
while elements.more():
i = data.draw_integer(0, self.array_size - 1)
if i in assigned:
elements.reject()
elements.reject("chose an array index we've already used")
continue
val = data.draw(self.elements_strategy)
if self.unique:
if val in seen:
elements.reject()
elements.reject("chose an element we've already used")
continue
else:
seen.add(val)
Expand Down
6 changes: 3 additions & 3 deletions hypothesis-python/src/hypothesis/internal/conjecture/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,13 +2273,13 @@ def _pop_ir_tree_node(self, ir_type: IRTypeName, kwargs: IRKWargsType) -> IRNode
# (in fact, it is possible that giving up early here results in more time
# for useful shrinks to run).
if node.ir_type != ir_type:
self.mark_invalid()
self.mark_invalid(f"(internal) want a {ir_type} but have a {node.ir_type}")

# if a node has different kwargs (and so is misaligned), but has a value
# that is allowed by the expected kwargs, then we can coerce this node
# into an aligned one by using its value. It's unclear how useful this is.
if not ir_value_permitted(node.value, node.ir_type, kwargs):
self.mark_invalid()
self.mark_invalid(f"(internal) got a {ir_type} but outside the valid range")

return node

Expand Down Expand Up @@ -2348,7 +2348,7 @@ def draw(
strategy.validate()

if strategy.is_empty:
self.mark_invalid("strategy is empty")
self.mark_invalid(f"empty strategy {self!r}")

if self.depth >= MAX_DEPTH:
self.mark_invalid("max depth exceeded")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,15 @@ def generate_new_examples(self):

self.test_function(data)

if (
data.status == Status.OVERRUN
and max_length < BUFFER_SIZE
and "invalid because" not in data.events
):
data.events["invalid because"] = (
"reduced max size for early examples (avoids flaky health checks)"
)

self.generate_mutations_from(data)

# Although the optimisations are logically a distinct phase, we
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def do_draw(self, data):
machine = data.draw(self_strategy)
bundle = machine.bundle(self.name)
if not bundle:
data.mark_invalid()
data.mark_invalid(f"Cannot draw from empty bundle {self.name!r}")
# Shrink towards the right rather than the left. This makes it easier
# to delete data generated earlier, as when the error is towards the
# end there can be a lot of hard to remove padding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def do_draw(self, data):

# If we happened to end up with a disallowed imaginary time, reject it.
if (not self.allow_imaginary) and datetime_does_not_exist(result):
data.mark_invalid("nonexistent datetime")
data.mark_invalid(f"{result} does not exist (usually a DST transition)")
return result

def draw_naive_datetime_and_combine(self, data, tz):
Expand Down

0 comments on commit 067fc76

Please sign in to comment.