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


Python ExampleDatabase.fetch方法代码示例

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

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

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

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


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