本文整理汇总了Python中hypothesis.internal.conjecture.engine.TestRunner类的典型用法代码示例。如果您正苦于以下问题:Python TestRunner类的具体用法?Python TestRunner怎么用?Python TestRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stops_after_max_examples_when_generating
def test_stops_after_max_examples_when_generating():
seen = []
def f(data):
seen.append(data.draw_bytes(1))
runner = TestRunner(f, settings=settings(max_examples=1, database=None))
runner.run()
assert len(seen) == 1
示例2: test_run_with_timeout_while_boring
def test_run_with_timeout_while_boring():
def f(data):
time.sleep(0.1)
runner = TestRunner(f, settings=settings(database=None, timeout=0.2,))
start = time.time()
runner.run()
assert time.time() <= start + 1
assert runner.last_data.status == Status.VALID
示例3: run_to_buffer
def run_to_buffer(f):
runner = TestRunner(f, settings=settings(
max_examples=5000, max_iterations=10000, max_shrinks=MAX_SHRINKS,
buffer_size=1024,
database=None,
))
runner.run()
assert runner.last_data.status == Status.INTERESTING
return hbytes(runner.last_data.buffer)
示例4: test_can_navigate_to_a_valid_example
def test_can_navigate_to_a_valid_example():
def f(data):
i = int_from_bytes(data.draw_bytes(2))
data.draw_bytes(i)
data.mark_interesting()
runner = TestRunner(f, settings=settings(max_examples=5000, max_iterations=10000, buffer_size=2, database=None))
runner.run()
assert runner.last_data.status == Status.INTERESTING
return hbytes(runner.last_data.buffer)
示例5: test_phases_can_disable_shrinking
def test_phases_can_disable_shrinking():
seen = set()
def f(data):
seen.add(hbytes(data.draw_bytes(32)))
data.mark_interesting()
runner = TestRunner(f, settings=settings(database=None, phases=(Phase.reuse, Phase.generate)))
runner.run()
assert len(seen) == 1
示例6: test_max_shrinks_can_disable_shrinking
def test_max_shrinks_can_disable_shrinking():
seen = set()
def f(data):
seen.add(hbytes(data.draw_bytes(32)))
data.mark_interesting()
runner = TestRunner(f, settings=settings(database=None, max_shrinks=0,))
runner.run()
assert len(seen) == 1
示例7: test_run_with_timeout_while_shrinking
def test_run_with_timeout_while_shrinking():
def f(data):
time.sleep(0.1)
x = data.draw_bytes(32)
if any(x):
data.mark_interesting()
runner = TestRunner(f, settings=settings(database=None, timeout=0.2,))
start = time.time()
runner.run()
assert time.time() <= start + 1
assert runner.last_data.status == Status.INTERESTING
示例8: test_detects_flakiness
def test_detects_flakiness():
failed_once = [False]
count = [0]
def tf(data):
data.draw_bytes(1)
count[0] += 1
if not failed_once[0]:
failed_once[0] = True
data.mark_interesting()
runner = TestRunner(tf)
runner.run()
assert count == [2]
示例9: test_can_load_data_from_a_corpus
def test_can_load_data_from_a_corpus():
key = b'hi there'
db = ExampleDatabase()
value = b'=\xc3\xe4l\x81\xe1\xc2H\xc9\xfb\x1a\xb6bM\xa8\x7f'
db.save(key, value)
def f(data):
if data.draw_bytes(len(value)) == value:
data.mark_interesting()
runner = TestRunner(
f, settings=settings(database=db), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
assert runner.last_data.buffer == value
assert len(list(db.fetch(key))) == 1
示例10: test_stops_after_max_examples_when_reading
def test_stops_after_max_examples_when_reading():
key = b"key"
db = ExampleDatabase(":memory:")
for i in range(10):
db.save(key, hbytes([i]))
seen = []
def f(data):
seen.append(data.draw_bytes(1))
runner = TestRunner(f, settings=settings(max_examples=1, database=db), database_key=key)
runner.run()
assert len(seen) == 1
示例11: x
def x(data):
rnd = Random(hbytes(data.draw_bytes(8)))
def g(d2):
while True:
b = d2.draw_bytes(1)[0]
result = data.draw_bytes(b)
if 255 in result:
d2.mark_interesting()
if 0 in result:
d2.mark_invalid()
runner = TestRunner(g, random=rnd)
runner.run()
if runner.last_data.status == Status.INTERESTING:
data.mark_interesting()
示例12: test_terminates_shrinks
def test_terminates_shrinks():
shrinks = [-1]
def tf(data):
x = hbytes(data.draw_bytes(100))
if sum(x) >= 500:
shrinks[0] += 1
data.mark_interesting()
runner = TestRunner(tf, settings=settings(max_examples=5000, max_iterations=10000, max_shrinks=10, database=None))
runner.run()
assert runner.last_data.status == Status.INTERESTING
# There's an extra non-shrinking check step to abort in the presence of
# flakiness
assert shrinks[0] == 11
示例13: test_stops_after_max_iterations_when_generating
def test_stops_after_max_iterations_when_generating():
key = b"key"
value = b"rubber baby buggy bumpers"
max_iterations = 100
db = ExampleDatabase(":memory:")
db.save(key, value)
seen = []
def f(data):
seen.append(data.draw_bytes(len(value)))
data.mark_invalid()
runner = TestRunner(
f, settings=settings(max_examples=1, max_iterations=max_iterations, database=db), database_key=key
)
runner.run()
assert len(seen) == max_iterations
assert value in seen
示例14: test_stops_after_max_iterations_when_reading
def test_stops_after_max_iterations_when_reading():
key = b'key'
max_iterations = 1
db = ExampleDatabase(':memory:')
for i in range(10):
db.save(key, hbytes([i]))
seen = []
def f(data):
seen.append(data.draw_bytes(1))
data.mark_invalid()
runner = TestRunner(f, settings=settings(
max_examples=1, max_iterations=max_iterations,
database=db,
), database_key=key)
runner.run()
assert len(seen) == max_iterations
示例15: test_saves_data_while_shrinking
def test_saves_data_while_shrinking():
key = b'hi there'
n = 5
db = ExampleDatabase(':memory:')
assert list(db.fetch(key)) == []
seen = set()
def f(data):
x = data.draw_bytes(512)
if sum(x) >= 5000 and len(seen) < n:
seen.add(hbytes(x))
if hbytes(x) in seen:
data.mark_interesting()
runner = TestRunner(
f, settings=settings(database=db), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
assert len(seen) == n
in_db = set(db.fetch(key))
assert in_db.issubset(seen)
assert in_db == seen