Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@hs.composite
def ifexp_node(draw, test=const_node(hs.booleans()),
expr=const_node(), orelse=const_node()):
# TODO: Add an option for whether expr and orelse strategies produce the same type.
test = draw(test)
expr = draw(expr)
node = astroid.IfExp()
node.postinit(test, expr, expr)
return node
@hs.composite
def simple_homogeneous_set_node(draw, **kwargs):
t = draw(primitive_types)
homogeneous_set = draw(set_node(const_node(t()), **kwargs))
assume(homogeneous_set.elts != set())
return homogeneous_set
@st.composite
def sequence_vars(draw):
num_vars = draw(st.integers(min_value=1, max_value=4))
variables = []
for i in range(num_vars):
name = 'var{:d}'.format(i)
count = draw(st.integers(min_value=1, max_value=4))
minimum = draw(st.integers(min_value=0, max_value=2))
variables.append(VariableWithCount(name, count, minimum, None))
return variables
@st.composite
def distinct_integers(draw):
used = draw(st.shared(st.builds(set), key='distinct_integers.used'))
i = draw(st.integers(0, 2 ** 64 - 1).filter(lambda x: x not in used))
used.add(i)
return i
@composite
def leap_sec_day_mjd(draw):
i = draw(sampled_from(sorted(leap_sec_days)))
f = draw(floats(0, 1, allow_nan=False))
return (i, f)
@composite
def connections(draw, players_from=text(lower), min_size=3, max_size=8):
""" A strategy for making a set of connections between players. """
num_players = draw(integers(min_size, max_size))
players = draw(
lists(
players_from,
min_size=num_players,
max_size=num_players,
unique=True,
)
)
preferences = {}
for player in players:
@st.composite
def problem(draw):
b = hbytes(draw(st.binary(min_size=1, max_size=8)))
m = int_from_bytes(b) * 256
assume(m > 0)
marker = draw(st.binary(max_size=8))
bound = draw(st.integers(0, m - 1))
return (b, marker, bound)
@st.composite
def variables(draw):
domain = draw(st.sampled_from(
Domain.REALS,
Domain.INTEGERS,
Domain.BINARY,
))
lower_bound = draw(st.one_of(st.none(), st.floats()))
upper_bound = draw(st.one_of(st.none(), st.floats(min_value=lower_bound)))
return Variable(lower_bound, upper_bound, domain)
@st.composite
def column_strategy(draw):
name = draw(st.none() | st.text())
dtype = draw(npst.scalar_dtypes().filter(supported_by_pandas))
pass_dtype = not draw(st.booleans())
if pass_dtype:
pass_elements = not draw(st.booleans())
else:
pass_elements = True
if pass_elements:
elements = npst.from_dtype(dtype)
else:
elements = None
unique = draw(st.booleans())
fill = st.nothing() if draw(st.booleans()) else None
@composite
def incidentTypesText(draw: Callable) -> str:
return draw(text(min_size=1))