本文整理汇总了Python中hypothesis.HealthCheck.all方法的典型用法代码示例。如果您正苦于以下问题:Python HealthCheck.all方法的具体用法?Python HealthCheck.all怎么用?Python HealthCheck.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.HealthCheck
的用法示例。
在下文中一共展示了HealthCheck.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_failure_sequence_inducing
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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()
示例2: test_the_slow_test_health_only_runs_if_health_checks_are_on
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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()
示例3: test_contains_the_test_function_name_in_the_exception_string
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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]
示例4: test_debug_data
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [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
示例5: test_database_clears_secondary_key
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [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
示例6: test_database_uses_values_from_secondary_key
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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]
示例7: test_returning_non_none_does_not_fail_if_health_check_disabled
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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()
示例8: test_notes_hard_to_satisfy
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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
示例9: test_raises_unsatisfiable_if_all_false
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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()
示例10: test_default_health_check_can_weaken_specific
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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()
示例11: test_always_reduces_integers_to_smallest_suitable_sizes
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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
示例12: run_to_buffer
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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)
示例13: accept
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [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.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
)
示例14: test_exit_because_max_iterations
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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
示例15: test_large_initial_write
# 需要导入模块: from hypothesis import HealthCheck [as 别名]
# 或者: from hypothesis.HealthCheck import all [as 别名]
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