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


Python hypothesis.HealthCheck类代码示例

本文整理汇总了Python中hypothesis.HealthCheck的典型用法代码示例。如果您正苦于以下问题:Python HealthCheck类的具体用法?Python HealthCheck怎么用?Python HealthCheck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_failure_sequence_inducing

def test_failure_sequence_inducing(building, testing, rnd):
    buildit = iter(building)
    testit = iter(testing)

    def build(x):
        try:
            assume(not next(buildit))
        except StopIteration:
            pass
        return x

    @given(integers().map(build))
    @settings(
        verbosity=Verbosity.quiet, database=None,
        suppress_health_check=HealthCheck.all(), phases=no_shrink
    )
    def test(x):
        try:
            i = next(testit)
        except StopIteration:
            return
        if i == 1:
            return
        elif i == 2:
            reject()
        else:
            raise Nope()

    try:
        test()
    except (Nope, Unsatisfiable, Flaky):
        pass
    except UnsatisfiedAssumption:
        raise SatisfyMe()
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:34,代码来源:test_flakiness.py

示例2: test_the_slow_test_health_only_runs_if_health_checks_are_on

def test_the_slow_test_health_only_runs_if_health_checks_are_on():
    @given(st.integers())
    @settings(suppress_health_check=HealthCheck.all(), deadline=None)
    def a(x):
        time.sleep(1000)

    a()
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:7,代码来源:test_health_checks.py

示例3: test_contains_the_test_function_name_in_the_exception_string

def test_contains_the_test_function_name_in_the_exception_string():
    look_for_one = settings(
        max_examples=1, suppress_health_check=HealthCheck.all())

    @given(integers())
    @look_for_one
    def this_has_a_totally_unique_name(x):
        reject()

    with raises(Unsatisfiable) as e:
        this_has_a_totally_unique_name()
    assert this_has_a_totally_unique_name.__name__ in e.value.args[0]

    class Foo(object):

        @given(integers())
        @look_for_one
        def this_has_a_unique_name_and_lives_on_a_class(self, x):
            reject()

    with raises(Unsatisfiable) as e:
        Foo().this_has_a_unique_name_and_lives_on_a_class()
    assert (
        Foo.this_has_a_unique_name_and_lives_on_a_class.__name__
    ) in e.value.args[0]
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:25,代码来源:test_testdecorators.py

示例4: test_debug_data

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,代码行数:27,代码来源:test_conjecture_engine.py

示例5: test_database_clears_secondary_key

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,代码行数:34,代码来源:test_conjecture_engine.py

示例6: test_database_uses_values_from_secondary_key

def test_database_uses_values_from_secondary_key():
    key = b'key'
    database = InMemoryExampleDatabase()

    def f(data):
        if data.draw_bits(8) >= 5:
            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.test_function(ConjectureData.for_buffer(hbytes([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 set(
        map(int_from_bytes, database.fetch(runner.secondary_key))
    ) == set(range(6, 11))

    v, = runner.interesting_examples.values()

    assert list(v.buffer) == [5]
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:34,代码来源:test_conjecture_engine.py

示例7: test_returning_non_none_does_not_fail_if_health_check_disabled

def test_returning_non_none_does_not_fail_if_health_check_disabled():
    @given(st.integers())
    @settings(suppress_health_check=HealthCheck.all())
    def a(x):
        return 1

    a()
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:7,代码来源:test_health_checks.py

示例8: test_notes_hard_to_satisfy

def test_notes_hard_to_satisfy():
    @given(st.integers())
    @settings(suppress_health_check=HealthCheck.all())
    def test(i):
        assume(i == 0)

    stats = call_for_statistics(test)
    assert 'satisfied assumptions' in stats.exit_reason
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:8,代码来源:test_statistical_events.py

示例9: test_raises_unsatisfiable_if_all_false

def test_raises_unsatisfiable_if_all_false():
    @given(integers())
    @settings(max_examples=50, suppress_health_check=HealthCheck.all())
    def test_assume_false(x):
        reject()

    with pytest.raises(Unsatisfiable):
        test_assume_false()
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:8,代码来源:test_given_error_conditions.py

示例10: test_default_health_check_can_weaken_specific

def test_default_health_check_can_weaken_specific():
    import random

    @settings(suppress_health_check=HealthCheck.all())
    @given(st.lists(st.integers(), min_size=1))
    def test(x):
        random.choice(x)

    test()
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:9,代码来源:test_health_checks.py

示例11: test_always_reduces_integers_to_smallest_suitable_sizes

def test_always_reduces_integers_to_smallest_suitable_sizes(problem):
    n, blob = problem
    blob = hbytes(blob)
    try:
        d = ConjectureData.for_buffer(blob)
        k = d.draw(st.integers())
        stop = blob[len(d.buffer)]
    except (StopTest, IndexError):
        reject()

    assume(k > n)
    assume(stop > 0)

    def f(data):
        k = data.draw(st.integers())
        data.output = repr(k)
        if data.draw_bits(8) == stop and k >= n:
            data.mark_interesting()

    runner = ConjectureRunner(f, random=Random(0), settings=settings(
        suppress_health_check=HealthCheck.all(), timeout=unlimited,
        phases=(Phase.shrink,), database=None, verbosity=Verbosity.debug
    ), database_key=None)

    runner.test_function(ConjectureData.for_buffer(blob))

    assert runner.interesting_examples

    v, = runner.interesting_examples.values()

    shrinker = runner.new_shrinker(v, lambda x: x.status == Status.INTERESTING)

    shrinker.clear_passes()
    shrinker.add_new_pass('minimize_individual_blocks')

    shrinker.shrink()

    v = shrinker.shrink_target

    m = ConjectureData.for_buffer(v.buffer).draw(st.integers())
    assert m == n

    # Upper bound on the length needed is calculated as follows:
    # * We have an initial byte at the beginning to decide the length of the
    #   integer.
    # * We have a terminal byte as the stop value.
    # * The rest is the integer payload. This should be n. Including the sign
    #   bit, n needs (1 + n.bit_length()) / 8 bytes (rounded up). But we only
    #   have power of two sizes, so it may be up to a factor of two more than
    #   that.
    bits_needed = 1 + n.bit_length()
    actual_bits_needed = min(
        [s for s in WideRangeIntStrategy.sizes if s >= bits_needed])
    bytes_needed = actual_bits_needed // 8
    # 3 extra bytes: two for the sampler, one for the capping value.
    assert len(v.buffer) == 3 + bytes_needed
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:56,代码来源:test_integers.py

示例12: run_to_buffer

def run_to_buffer(f):
    with deterministic_PRNG():
        runner = ConjectureRunner(f, settings=settings(
            max_examples=5000, buffer_size=1024,
            database=None, suppress_health_check=HealthCheck.all(),
        ))
        runner.run()
        assert runner.interesting_examples
        last_data, = runner.interesting_examples.values()
        return hbytes(last_data.buffer)
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:10,代码来源:test_conjecture_engine.py

示例13: accept

 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.test_function(ConjectureData.for_buffer(start))
         assert runner.interesting_examples
         last_data, = runner.interesting_examples.values()
         return runner.new_shrinker(
             last_data, lambda d: d.status == Status.INTERESTING
         )
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:12,代码来源:test_conjecture_engine.py

示例14: test_exit_because_max_iterations

def test_exit_because_max_iterations():

    def f(data):
        data.draw_bits(64)
        data.mark_invalid()

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

    runner.run()

    assert runner.call_count <= 1000
    assert runner.exit_reason == ExitReason.max_iterations
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:15,代码来源:test_conjecture_engine.py

示例15: test_large_initial_write

def test_large_initial_write():
    big = hbytes(b'\xff') * 512

    def f(data):
        data.write(big)
        data.draw_bits(63)

    with deterministic_PRNG():
        runner = ConjectureRunner(f, settings=settings(
            max_examples=5000, buffer_size=1024,
            database=None, suppress_health_check=HealthCheck.all(),
        ))
        runner.run()

    assert runner.exit_reason == ExitReason.finished
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:15,代码来源:test_conjecture_engine.py


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