Low-level tools¶
Building blocks for custom generators that need finer control over how the
engine draws, and so how it shrinks, than composite()
and the standard generators give. Most tests never need them.
- class hegel.Collection¶
A low-level helper for custom collection generators: the engine decides how many elements to draw, within
[min_size, max_size](max_size=Nonefor no fixed limit), so the shrinker can remove elements cleanly. Callmore()before drawing each element:collection = hegel.Collection(tc, min_size, max_size) result = [] while collection.more(): result.append(tc.draw_silent(elements))
- hegel.generators.weighted_booleans(p: float) Generator[bool]¶
Generate
Truewith probabilityp, andFalseotherwise, shrinking towardFalse.poutside[0, 1]is anInvalidArgument.
- TestCase.draw_and_print(generator: Generator[T], printer: PrettyPrinter) T¶
Draw a value, printing its representation through
printer. This is how a printable generator’sdo_draw_and_printdraws its components, so they print as part of its own value:generatormust be printable, or this raisesNotPrintable. When the enclosing generator is itself being drawn silently, so isgenerator.
- TestCase.start_span(label: int) None¶
Open a span labelled
labelgrouping the draws until the matchingstop_span(). Spans tell the shrinker which choices belong together;draw()anddraw_silent()open one per draw, so only a low-level custom generator needs this. Nesting so deep that Python’s recursion limit (sys.getrecursionlimit()) is in sight abandons the test case as too large, rather than failing it with aRecursionError.
- TestCase.stop_span(discard: bool = False) None¶
Close the span opened by the matching
start_span(). Withdiscard=Truethe shrinker treats the span’s draws as thrown away (a filtered-out attempt, say).