本文整理汇总了Python中hypothesis.database.ExampleDatabase.fetch方法的典型用法代码示例。如果您正苦于以下问题:Python ExampleDatabase.fetch方法的具体用法?Python ExampleDatabase.fetch怎么用?Python ExampleDatabase.fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.database.ExampleDatabase
的用法示例。
在下文中一共展示了ExampleDatabase.fetch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_garbage_collects_the_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import fetch [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: test_saves_data_while_shrinking
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import fetch [as 别名]
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 = ConjectureRunner(
f, settings=settings(database=db), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
assert len(seen) == n
in_db = set(
v
for vs in db.data.values()
for v in vs
)
assert in_db.issubset(seen)
assert in_db == seen
示例3: test_can_load_data_from_a_corpus
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import fetch [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 = ConjectureRunner(
f, settings=settings(database=db), database_key=key)
runner.run()
last_data, = runner.interesting_examples.values()
assert last_data.buffer == value
assert len(list(db.fetch(key))) == 1
示例4: test_can_load_data_from_a_corpus
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import fetch [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