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


Python ConjectureRunner.cached_test_function方法代码示例

本文整理汇总了Python中hypothesis.internal.conjecture.engine.ConjectureRunner.cached_test_function方法的典型用法代码示例。如果您正苦于以下问题:Python ConjectureRunner.cached_test_function方法的具体用法?Python ConjectureRunner.cached_test_function怎么用?Python ConjectureRunner.cached_test_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hypothesis.internal.conjecture.engine.ConjectureRunner的用法示例。


在下文中一共展示了ConjectureRunner.cached_test_function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_database_clears_secondary_key

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_database_clears_secondary_key():
    key = b"key"
    database = InMemoryExampleDatabase()

    def f(data):
        if data.draw_bits(8) == 10:
            data.mark_interesting()
        else:
            data.mark_invalid()

    runner = ConjectureRunner(
        f,
        settings=settings(
            max_examples=1,
            buffer_size=1024,
            database=database,
            suppress_health_check=HealthCheck.all(),
        ),
        database_key=key,
    )

    for i in range(10):
        database.save(runner.secondary_key, hbytes([i]))

    runner.cached_test_function([10])
    assert runner.interesting_examples

    assert len(set(database.fetch(key))) == 1
    assert len(set(database.fetch(runner.secondary_key))) == 10

    runner.clear_secondary_key()

    assert len(set(database.fetch(key))) == 1
    assert len(set(database.fetch(runner.secondary_key))) == 0
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:36,代码来源:test_conjecture_engine.py

示例2: test_exhaustive_enumeration_of_partial_buffer

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [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
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:31,代码来源:test_conjecture_engine.py

示例3: test_debug_data

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_debug_data(capsys):
    buf = [0, 1, 2]

    def f(data):
        for x in hbytes(buf):
            if data.draw_bits(8) != x:
                data.mark_invalid()
            data.start_example(1)
            data.stop_example()
        data.mark_interesting()

    runner = ConjectureRunner(
        f,
        settings=settings(
            max_examples=5000,
            buffer_size=1024,
            database=None,
            suppress_health_check=HealthCheck.all(),
            verbosity=Verbosity.debug,
        ),
    )
    runner.cached_test_function(buf)
    runner.run()

    out, _ = capsys.readouterr()
    assert re.match(u"\\d+ bytes \\[.*\\] -> ", out)
    assert "INTERESTING" in out
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:29,代码来源:test_conjecture_engine.py

示例4: test_exhaustive_enumeration

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [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
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:36,代码来源:test_conjecture_engine.py

示例5: test_overruns_if_prefix

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_overruns_if_prefix():
    runner = ConjectureRunner(
        lambda data: [data.draw_bits(1) for _ in range(2)],
        settings=TEST_SETTINGS,
        random=Random(0),
    )
    runner.cached_test_function(b"\0\0")
    assert runner.tree.rewrite(b"\0")[1] == Status.OVERRUN
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:10,代码来源:test_conjecture_data_tree.py

示例6: test_detects_too_small_block_starts

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_detects_too_small_block_starts():
    call_count = [0]

    def f(data):
        assert call_count[0] == 0
        call_count[0] += 1
        data.draw_bytes(8)
        data.mark_interesting()

    runner = ConjectureRunner(f, settings=settings(database=None))
    r = runner.cached_test_function(hbytes(8))
    assert r.status == Status.INTERESTING
    assert call_count[0] == 1
    r2 = runner.cached_test_function(hbytes([255] * 7))
    assert r2.status == Status.OVERRUN
    assert call_count[0] == 1
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:18,代码来源:test_conjecture_engine.py

示例7: test_avoids_zig_zag_trap

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_avoids_zig_zag_trap(p):
    b, marker, lower_bound = p

    random.seed(0)

    b = hbytes(b)
    marker = hbytes(marker)

    n_bits = 8 * (len(b) + 1)

    def test_function(data):
        m = data.draw_bits(n_bits)
        if m < lower_bound:
            data.mark_invalid()
        n = data.draw_bits(n_bits)
        if data.draw_bytes(len(marker)) != marker:
            data.mark_invalid()
        if abs(m - n) == 1:
            data.mark_interesting()

    runner = ConjectureRunner(
        test_function,
        database_key=None,
        settings=settings(base_settings, phases=(Phase.generate, Phase.shrink)),
    )

    runner.cached_test_function(b + hbytes([0]) + b + hbytes([1]) + marker)

    assert runner.interesting_examples

    runner.run()

    v, = runner.interesting_examples.values()

    data = ConjectureData.for_buffer(v.buffer)

    m = data.draw_bits(n_bits)
    n = data.draw_bits(n_bits)
    assert m == lower_bound
    if m == 0:
        assert n == 1
    else:
        assert n == m - 1

    budget = 2 * n_bits * ceil(log(n_bits, 2)) + 2

    assert runner.shrinks <= budget
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:49,代码来源:test_zig_zagging.py

示例8: accept

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
 def accept(f):
     with deterministic_PRNG():
         runner = ConjectureRunner(
             f,
             settings=settings(
                 max_examples=5000,
                 buffer_size=1024,
                 database=None,
                 suppress_health_check=HealthCheck.all(),
             ),
         )
         runner.cached_test_function(start)
         assert runner.interesting_examples
         last_data, = runner.interesting_examples.values()
         return runner.new_shrinker(
             last_data, lambda d: d.status == Status.INTERESTING
         )
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:19,代码来源:test_conjecture_engine.py

示例9: test_cached_test_function_does_not_reinvoke_on_prefix

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_cached_test_function_does_not_reinvoke_on_prefix():
    call_count = [0]

    def test_function(data):
        call_count[0] += 1
        data.draw_bits(8)
        data.write(hbytes([7]))
        data.draw_bits(8)

    with deterministic_PRNG():
        runner = ConjectureRunner(test_function, settings=TEST_SETTINGS)

        data = runner.cached_test_function(hbytes(3))
        assert data.status == Status.VALID
        for n in [2, 1, 0]:
            prefix_data = runner.cached_test_function(hbytes(n))
            assert prefix_data is Overrun
        assert call_count[0] == 1
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:20,代码来源:test_conjecture_engine.py

示例10: test_will_evict_entries_from_the_cache

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_will_evict_entries_from_the_cache(monkeypatch):
    monkeypatch.setattr(engine_module, "CACHE_SIZE", 5)
    count = [0]

    def tf(data):
        data.draw_bytes(1)
        count[0] += 1

    runner = ConjectureRunner(tf, settings=TEST_SETTINGS)

    for _ in range(3):
        for n in range(10):
            runner.cached_test_function([n])

    # Because we exceeded the cache size, our previous
    # calls will have been evicted, so each call to
    # cached_test_function will have to reexecute.
    assert count[0] == 30
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:20,代码来源:test_conjecture_engine.py

示例11: test_novel_prefixes_are_novel

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_novel_prefixes_are_novel():
    def tf(data):
        for _ in range(4):
            data.write(b"\0")
            data.draw_bits(2)

    runner = ConjectureRunner(tf, settings=TEST_SETTINGS, random=Random(0))
    for _ in range(100):
        prefix = runner.tree.generate_novel_prefix(runner.random)
        example = prefix + hbytes(8 - len(prefix))
        assert runner.tree.rewrite(example)[1] is None
        result = runner.cached_test_function(example)
        assert runner.tree.rewrite(example)[0] == result.buffer
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:15,代码来源:test_conjecture_data_tree.py

示例12: test_fully_exhaust_base

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_fully_exhaust_base(monkeypatch):
    """In this test we generate all possible values for the first byte but
    never get to the point where we exhaust the root of the tree."""
    seed_random(0)

    seen = set()

    def f(data):
        key = (data.draw_bits(2), data.draw_bits(2))
        assert key not in seen
        seen.add(key)

    runner = ConjectureRunner(f, settings=settings(
        max_examples=10000, phases=no_shrink, buffer_size=1024, database=None,
    ))

    for c in hrange(4):
        runner.cached_test_function([0, c])

    assert 1 in runner.dead

    runner.run()
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:24,代码来源:test_conjecture_engine.py

示例13: accept

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
 def accept(tf):
     runner = ConjectureRunner(tf, settings=TEST_SETTINGS, random=Random(0))
     runner.exit_with = lambda reason: None
     ran_examples = []
     for e in examples:
         e = hbytes(e)
         data = runner.cached_test_function(e)
         ran_examples.append((e, data))
     for e, d in ran_examples:
         rewritten, status = runner.tree.rewrite(e)
         assert status == d.status
         assert rewritten == d.buffer
     return runner
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:15,代码来源:test_conjecture_data_tree.py

示例14: test_cached_with_masked_byte_agrees_with_results

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_cached_with_masked_byte_agrees_with_results(byte_a, byte_b):
    def f(data):
        data.draw_bits(2)

    runner = ConjectureRunner(f)

    cached_a = runner.cached_test_function(hbytes([byte_a]))
    cached_b = runner.cached_test_function(hbytes([byte_b]))

    data_b = ConjectureData.for_buffer(hbytes([byte_b]))
    runner.test_function(data_b)

    # If the cache found an old result, then it should match the real result.
    # If it did not, then it must be because A and B were different.
    assert (cached_a is cached_b) == (cached_a.buffer == data_b.buffer)
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:17,代码来源:test_conjecture_engine.py

示例15: test_cached_test_function_returns_right_value

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import cached_test_function [as 别名]
def test_cached_test_function_returns_right_value():
    count = [0]

    def tf(data):
        count[0] += 1
        data.draw_bits(2)
        data.mark_interesting()

    with deterministic_PRNG():
        runner = ConjectureRunner(tf, settings=TEST_SETTINGS)
        for _ in hrange(2):
            for b in (b"\0", b"\1"):
                d = runner.cached_test_function(b)
                assert d.status == Status.INTERESTING
                assert d.buffer == b
        assert count[0] == 2
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:18,代码来源:test_conjecture_engine.py


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