MCPcopy Create free account
hub / github.com/HypothesisWorks/hypothesis / assert_all_examples

Function assert_all_examples

hypothesis/tests/common/debug.py:111–132  ·  view source on GitHub ↗

Asserts that all examples of the given strategy match the predicate. :param strategy: Hypothesis strategy to check :param predicate: (callable) Predicate that takes example and returns bool

(strategy, predicate, settings=None)

Source from the content-addressed store, hash-verified

109
110
111def assert_all_examples(strategy, predicate, settings=None):
112 """Asserts that all examples of the given strategy match the predicate.
113
114 :param strategy: Hypothesis strategy to check
115 :param predicate: (callable) Predicate that takes example and returns bool
116 """
117 if context := _current_build_context.value:
118 with local_settings(Settings(parent=settings)):
119 for _ in range(20):
120 s = context.data.draw(strategy)
121 msg = f"Found {s!r} using strategy {strategy} which does not match"
122 assert predicate(s), msg
123
124 else:
125
126 @given(strategy)
127 @Settings(parent=settings, database=None)
128 def assert_examples(s):
129 msg = f"Found {s!r} using strategy {strategy} which does not match"
130 assert predicate(s), msg
131
132 assert_examples()
133
134
135def assert_simple_property(strategy, predicate, settings=None):

Calls 4

local_settingsFunction · 0.90
assert_examplesFunction · 0.85
predicateFunction · 0.50
drawMethod · 0.45