本文整理汇总了Python中hypothesis.internal.conjecture.engine.TestRunner.run方法的典型用法代码示例。如果您正苦于以下问题:Python TestRunner.run方法的具体用法?Python TestRunner.run怎么用?Python TestRunner.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.internal.conjecture.engine.TestRunner
的用法示例。
在下文中一共展示了TestRunner.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_garbage_collects_the_database
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
def test_garbage_collects_the_database():
key = b'hi there'
n = 200
db = ExampleDatabase(':memory:')
assert list(db.fetch(key)) == []
seen = set()
go = True
def f(data):
x = hbytes(data.draw_bytes(512))
if not go:
return
if sum(x) >= 5000 and len(seen) < n:
seen.add(x)
if x in seen:
data.mark_interesting()
runner = TestRunner(
f, settings=settings(database=db, max_shrinks=2 * n), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
assert len(seen) == n
assert set(db.fetch(key)) == seen
go = False
runner = TestRunner(
f, settings=settings(database=db, max_shrinks=2 * n), database_key=key)
runner.run()
assert 0 < len(set(db.fetch(key))) < n
示例2: run_to_buffer
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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)
示例3: test_stops_after_max_examples_when_generating
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例4: test_run_with_timeout_while_boring
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例5: test_can_navigate_to_a_valid_example
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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)
示例6: test_max_shrinks_can_disable_shrinking
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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_phases_can_disable_shrinking
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例8: test_run_with_timeout_while_shrinking
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例9: test_detects_flakiness
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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]
示例10: test_can_load_data_from_a_corpus
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例11: test_stops_after_max_examples_when_reading
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例12: x
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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()
示例13: test_terminates_shrinks
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例14: test_stops_after_max_iterations_when_generating
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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
示例15: test_stops_after_max_iterations_when_reading
# 需要导入模块: from hypothesis.internal.conjecture.engine import TestRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 别名]
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