Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@hypothesis.settings(
max_examples=50,
suppress_health_check=[hypothesis.HealthCheck.too_slow])
@hypothesis.given(put_strategy)
def single_operation_test(client, put_operation, get_operation,
put_params):
"""PUT an colour in hex, then GET it again as an int."""
put_params['int_id'] = 1
result = client.request(put_operation, put_params)
assert result.status in put_operation.response_codes, \
"{} not in {}".format(result.status,
put_operation.response_codes)
result = client.request(get_operation, {"int_id": 1})
assert result.status in get_operation.response_codes, \
"{} not in {}".format(result.status,
get_operation.response_codes)
def save(self, key, value):
self.underlying.save(key, value)
def delete(self, key, value):
self.underlying.delete(key, value)
def close(self):
self.underlying.close()
def extensionconfigkey(extension):
return "extensions." + extension
settings.register_profile(
"default", settings(timeout=300, stateful_step_count=50, max_examples=10)
)
settings.register_profile(
"fast",
settings(
timeout=10,
stateful_step_count=20,
max_examples=5,
min_satisfying_examples=1,
max_shrinks=0,
),
)
settings.register_profile(
"continuous",
settings(
@settings(deadline=400)
def test_correctness_randomized(self, variables, values):
values = Multiset(values)
for subst in commutative_sequence_variable_partition_iter(values, variables):
assert len(variables) == len(subst)
result_union = Multiset()
for var in variables:
assert len(subst[var.name]) >= var.minimum
result_union.update(subst[var.name] * var.count)
assert result_union == values
@hp.settings(max_examples=MAX_EXAMPLES)
def test_concat_multiple(nums):
nums_py = [ x + 1 for x in nums ]
nums_py1 = nums_py + nums_py
nums_py2 = nums_py1 + nums_py
nums_pl = aio.map(lambda x: x + 1, nums)
nums_pl1 = aio.concat([nums_pl, nums_pl])
nums_pl2 = aio.concat([nums_pl1, nums_pl])
assert sorted(nums_py1) == sorted(list(nums_pl1))
assert sorted(nums_py2) == sorted(list(nums_pl2))
@settings(phases=(Phase.explicit,))
@given(st.integers())
def test_only_runs_explicit_examples(i):
assert i == 11
@settings(deadline=None)
@given(fake_randoms())
def test_a_negated_tag_is_also_interesting(rnd):
selector = TargetSelector(rnd)
selector.add(FakeConjectureData(tags=frozenset({0})))
selector.add(FakeConjectureData(tags=frozenset({0})))
selector.add(FakeConjectureData(tags=frozenset()))
_, data = selector.select()
assert not data.tags
@given(integers(), settings=hs.Settings(max_shrinks=0))
def foo(x):
if x > 11:
failing[0] += 1
assert False
@settings(max_examples=1, deadline=None)
@given(random=st.randoms())
@pytest.mark.parametrize(("votes_count"), [(0), (9)])
def test_aggregate_votes(votes_count, random, privkeys, pubkeys):
bit_count = 10
pre_bitfield = get_empty_bitfield(bit_count)
pre_sigs = ()
domain = compute_domain(SignatureDomain.DOMAIN_BEACON_ATTESTER)
random_votes = random.sample(range(bit_count), votes_count)
message_hash = b"\x12" * 32
# Get votes: (committee_index, sig, public_key)
votes = [
(
committee_index,
bls.sign(message_hash, privkeys[committee_index], domain),
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_set_multi_assign(variables_list, value):
"""Test environment setting visitors"""
for variable_name in variables_list:
assume(not iskeyword(variable_name))
variables_list.append(repr(value))
program = (" = ").join(variables_list)
module, inferer = cs._parse_text(program)
for target_node in module.nodes_of_class(astroid.AssignName):
value_type = target_node.parent.value.inf_type.getValue()
target_type_var = target_node.frame().type_environment.lookup_in_env(target_node.name)
assert inferer.type_constraints.resolve(target_type_var).getValue() == value_type
def test_garbage_collects_the_database():
key = b'hi there'
n = 200
db = InMemoryExampleDatabase()
local_settings = settings(
database=db, max_shrinks=n, timeout=unlimited)
runner = ConjectureRunner(
slow_shrinker(), settings=local_settings, database_key=key)
runner.run()
assert runner.interesting_examples
assert len(non_covering_examples(db)) == n + 1
runner = ConjectureRunner(
lambda data: data.draw_bytes(4),
settings=local_settings, database_key=key)
runner.run()
assert 0 < len(non_covering_examples(db)) < n