当前位置: 首页>>代码示例>>Python>>正文


Python ExampleDatabase.save方法代码示例

本文整理汇总了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
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:17,代码来源:test_conjecture_engine.py

示例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
开发者ID:alexwlchan,项目名称:hypothesis,代码行数:17,代码来源:test_conjecture_engine.py

示例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
开发者ID:alexwlchan,项目名称:hypothesis,代码行数:17,代码来源:test_conjecture_engine.py

示例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
开发者ID:rboulton,项目名称:hypothesis,代码行数:22,代码来源:test_conjecture_engine.py

示例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
开发者ID:alexwlchan,项目名称:hypothesis,代码行数:22,代码来源:test_conjecture_engine.py


注:本文中的hypothesis.database.ExampleDatabase.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。