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


Python ConjectureRunner.run方法代码示例

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


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

示例1: test_can_cover_without_a_database_key

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_can_cover_without_a_database_key():
    def tagged(data):
        data.add_tag(0)

    runner = ConjectureRunner(tagged, settings=settings(), database_key=None)
    runner.run()
    assert len(runner.covering_examples) == 1
开发者ID:rboulton,项目名称:hypothesis,代码行数:9,代码来源:test_conjecture_engine.py

示例2: test_can_delete_intervals

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_can_delete_intervals(monkeypatch):
    def generate_new_examples(self):
        self.test_function(
            ConjectureData.for_buffer(hbytes([255] * 10 + [1, 3])))

    monkeypatch.setattr(
        ConjectureRunner, 'generate_new_examples', generate_new_examples)
    monkeypatch.setattr(
        Shrinker, 'shrink', fixate(Shrinker.adaptive_example_deletion)
    )

    def f(data):
        while True:
            n = data.draw_bits(8)
            if n == 255:
                continue
            elif n == 1:
                break
            else:
                data.mark_invalid()
        if data.draw_bits(8) == 3:
            data.mark_interesting()
    runner = ConjectureRunner(f, settings=settings(database=None))
    runner.run()
    x, = runner.interesting_examples.values()
    assert x.buffer == hbytes([1, 3])
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:28,代码来源:test_conjecture_engine.py

示例3: test_will_shrink_covering_examples

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_will_shrink_covering_examples():
    best = [None]
    replaced = []

    def tagged(data):
        b = hbytes(data.draw_bytes(4))
        if any(b):
            data.add_tag('nonzero')
            if best[0] is None:
                best[0] = b
            elif b < best[0]:
                replaced.append(best[0])
                best[0] = b

    db = InMemoryExampleDatabase()
    runner = ConjectureRunner(tagged, settings=settings(
        max_examples=100, max_iterations=10000, max_shrinks=0,
        buffer_size=1024,
        database=db,
    ), database_key=b'stuff')
    runner.run()
    saved = set(all_values(db))
    assert best[0] in saved
    for r in replaced:
        assert r not in saved
开发者ID:rboulton,项目名称:hypothesis,代码行数:27,代码来源:test_conjecture_engine.py

示例4: test_saves_data_while_shrinking

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [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

示例5: test_run_nothing

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_run_nothing():
    def f(data):
        assert False

    runner = ConjectureRunner(f, settings=settings(phases=()))
    runner.run()
    assert runner.call_count == 0
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:9,代码来源:test_conjecture_engine.py

示例6: test_terminates_shrinks

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_terminates_shrinks(n, monkeypatch):
    from hypothesis.internal.conjecture import engine

    db = InMemoryExampleDatabase()

    def generate_new_examples(self):
        def draw_bytes(data, n):
            return hbytes([255] * n)

        self.test_function(self.new_conjecture_data(draw_bytes))

    monkeypatch.setattr(
        ConjectureRunner, "generate_new_examples", generate_new_examples
    )
    monkeypatch.setattr(engine, "MAX_SHRINKS", n)

    runner = ConjectureRunner(
        slow_shrinker(),
        settings=settings(max_examples=5000, database=db),
        random=Random(0),
        database_key=b"key",
    )
    runner.run()
    last_data, = runner.interesting_examples.values()
    assert last_data.status == Status.INTERESTING
    assert runner.shrinks == n
    in_db = set(db.data[runner.secondary_key])
    assert len(in_db) == n
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:30,代码来源:test_conjecture_engine.py

示例7: test_saves_data_while_shrinking

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_saves_data_while_shrinking(monkeypatch):
    key = b'hi there'
    n = 5
    db = InMemoryExampleDatabase()
    assert list(db.fetch(key)) == []
    seen = set()

    monkeypatch.setattr(
        ConjectureRunner, 'generate_new_examples',
        lambda runner: runner.test_function(
            ConjectureData.for_buffer([255] * 10)))

    def f(data):
        x = data.draw_bytes(10)
        if sum(x) >= 2000 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.interesting_examples
    assert len(seen) == n
    in_db = non_covering_examples(db)
    assert in_db.issubset(seen)
    assert in_db == seen
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:28,代码来源:test_conjecture_engine.py

示例8: run_to_data

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def run_to_data(f):
    with deterministic_PRNG():
        runner = ConjectureRunner(f, settings=TEST_SETTINGS)
        runner.run()
        assert runner.interesting_examples
        last_data, = runner.interesting_examples.values()
        return last_data
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:9,代码来源:test_conjecture_engine.py

示例9: test_clears_out_its_database_on_shrinking

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_clears_out_its_database_on_shrinking(
    initial_attempt, skip_target, monkeypatch
):
    def generate_new_examples(self):
        self.test_function(
            ConjectureData.for_buffer(hbytes([initial_attempt])))

    monkeypatch.setattr(
        ConjectureRunner, 'generate_new_examples', generate_new_examples)

    key = b'key'
    db = InMemoryExampleDatabase()

    def f(data):
        if data.draw_bits(8) >= 127:
            data.mark_interesting()

    runner = ConjectureRunner(
        f, settings=settings(database=db, max_examples=256), database_key=key,
        random=Random(0),
    )

    for n in hrange(256):
        if n != 127 or not skip_target:
            db.save(runner.secondary_key, hbytes([n]))
    runner.run()
    assert len(runner.interesting_examples) == 1
    for b in db.fetch(runner.secondary_key):
        assert b[0] >= 127
    assert len(list(db.fetch(runner.database_key))) == 1
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:32,代码来源:test_conjecture_engine.py

示例10: test_debug_data

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [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

示例11: test_garbage_collects_the_database

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_garbage_collects_the_database():
    key = b'hi there'
    n = 200
    db = ExampleDatabase(':memory:')

    local_settings = settings(
        database=db, max_shrinks=n, timeout=unlimited)

    runner = ConjectureRunner(
        slow_shrinker(), settings=local_settings, database_key=key)
    runner.run()
    assert runner.last_data.status == Status.INTERESTING

    def in_db():
        return set(
            v
            for vs in db.data.values()
            for v in vs
        )

    assert len(in_db()) == n + 1
    runner = ConjectureRunner(
        lambda data: data.draw_bytes(4),
        settings=local_settings, database_key=key)
    runner.run()
    assert 0 < len(in_db()) < n
开发者ID:rboulton,项目名称:hypothesis,代码行数:28,代码来源:test_conjecture_engine.py

示例12: run_benchmark_for_sizes

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def run_benchmark_for_sizes(benchmark, n_runs):
    click.echo('Calculating data for %s' % (benchmark.name,))
    total_sizes = []

    with click.progressbar(range(n_runs)) as runs:
        for _ in runs:
            sizes = []
            valid_seed = random.getrandbits(64).to_bytes(8, 'big')
            interesting_seed = random.getrandbits(64).to_bytes(8, 'big')

            def test_function(data):
                try:
                    try:
                        value = data.draw(benchmark.strategy)
                    except UnsatisfiedAssumption:
                        data.mark_invalid()
                    if not data.frozen:
                        if not benchmark.valid(valid_seed, data, value):
                            data.mark_invalid()
                        if benchmark.interesting(
                            interesting_seed, data, value
                        ):
                            data.mark_interesting()
                finally:
                    sizes.append(len(data.buffer))
            engine = ConjectureRunner(
                test_function, settings=BENCHMARK_SETTINGS, random=random
            )
            engine.run()
            assert len(sizes) > 0
            total_sizes.append(sum(sizes))
    return total_sizes
开发者ID:rboulton,项目名称:hypothesis,代码行数:34,代码来源:benchmarks.py

示例13: test_exhaust_space

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_exhaust_space():
    with deterministic_PRNG():
        runner = ConjectureRunner(
            lambda data: data.draw_bits(1), settings=TEST_SETTINGS
        )
        runner.run()
        assert runner.tree.is_exhausted
        assert runner.valid_examples == 2
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:10,代码来源:test_conjecture_engine.py

示例14: test_note_events

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_note_events(event):
    def f(data):
        data.note_event(event)
        data.draw_bytes(1)

    runner = ConjectureRunner(f)
    runner.run()
    assert runner.event_call_counts[str(event)] == runner.call_count > 0
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:10,代码来源:test_conjecture_engine.py

示例15: test_stops_after_max_examples_when_generating

# 需要导入模块: from hypothesis.internal.conjecture.engine import ConjectureRunner [as 别名]
# 或者: from hypothesis.internal.conjecture.engine.ConjectureRunner import run [as 别名]
def test_stops_after_max_examples_when_generating():
    seen = []

    def f(data):
        seen.append(data.draw_bytes(1))

    runner = ConjectureRunner(f, settings=settings(max_examples=1, database=None))
    runner.run()
    assert len(seen) == 1
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:11,代码来源:test_conjecture_engine.py


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