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