本文整理汇总了Python中hypothesis.internal.conjecture.engine.ConjectureRunner.generate_novel_prefix方法的典型用法代码示例。如果您正苦于以下问题:Python ConjectureRunner.generate_novel_prefix方法的具体用法?Python ConjectureRunner.generate_novel_prefix怎么用?Python ConjectureRunner.generate_novel_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.internal.conjecture.engine.ConjectureRunner
的用法示例。
在下文中一共展示了ConjectureRunner.generate_novel_prefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exhaustive_enumeration_of_partial_buffer
# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import generate_novel_prefix [as 别名]
def test_exhaustive_enumeration_of_partial_buffer():
seen = set()
def f(data):
k = data.draw_bytes(2)
assert k[1] == 0
assert k not in seen
seen.add(k)
seen_prefixes = set()
runner = ConjectureRunner(
f, settings=settings(database=None, max_examples=256, buffer_size=2),
random=Random(0),
)
with pytest.raises(RunIsComplete):
runner.cached_test_function(b'')
for _ in hrange(256):
p = runner.generate_novel_prefix()
assert p not in seen_prefixes
seen_prefixes.add(p)
data = ConjectureData.for_buffer(hbytes(p + hbytes(2)))
runner.test_function(data)
assert data.status == Status.VALID
node = 0
for b in data.buffer:
node = runner.tree[node][b]
assert node in runner.dead
assert len(seen) == 256
示例2: test_exhaustive_enumeration
# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import generate_novel_prefix [as 别名]
def test_exhaustive_enumeration(prefix, bits, seed):
seen = set()
def f(data):
if prefix:
data.write(hbytes(prefix))
assert len(data.buffer) == len(prefix)
k = data.draw_bits(bits)
assert k not in seen
seen.add(k)
size = 2 ** bits
seen_prefixes = set()
runner = ConjectureRunner(
f, settings=settings(database=None, max_examples=size),
random=Random(seed),
)
with pytest.raises(RunIsComplete):
runner.cached_test_function(b'')
for _ in hrange(size):
p = runner.generate_novel_prefix()
assert p not in seen_prefixes
seen_prefixes.add(p)
data = ConjectureData.for_buffer(
hbytes(p + hbytes(2 + len(prefix))))
runner.test_function(data)
assert data.status == Status.VALID
node = 0
for b in data.buffer:
node = runner.tree[node][b]
assert node in runner.dead
assert len(seen) == size
示例3: test_branch_ending_in_write
# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import generate_novel_prefix [as 别名]
def test_branch_ending_in_write():
seen = set()
def tf(data):
count = 0
while data.draw_bits(1):
count += 1
if count > 1:
data.draw_bits(1, forced=0)
b = hbytes(data.buffer)
assert b not in seen
seen.add(b)
with deterministic_PRNG():
runner = ConjectureRunner(tf, settings=TEST_SETTINGS)
for _ in hrange(100):
prefix = runner.generate_novel_prefix()
attempt = prefix + hbytes(2)
data = runner.cached_test_function(attempt)
assert data.status == Status.VALID
assert attempt.startswith(data.buffer)