本文整理汇总了Python中hypothesis.strategies.dictionaries方法的典型用法代码示例。如果您正苦于以下问题:Python strategies.dictionaries方法的具体用法?Python strategies.dictionaries怎么用?Python strategies.dictionaries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.strategies
的用法示例。
在下文中一共展示了strategies.dictionaries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_dictionary_with_fixed_tokens
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def generate_dictionary_with_fixed_tokens(draw):
"""
Builds random nested dictionary structure which is then used as JSON to
mask two fixed "token" keys.
Structure is based on TEST_JSON sample fixture defined above.
"""
base = draw(
st.fixed_dictionaries({'token': st.text(printable, min_size=10)})
)
optional = draw(
st.nothing() | st.dictionaries(
st.text(ascii_letters, min_size=1),
st.floats() | st.integers() | st.text(printable) | st.booleans()
| st.nothing(),
min_size=10,
max_size=50
)
)
return {**base, **optional}
示例2: ds_vars_dims_mixed
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def ds_vars_dims_mixed():
def build_it(vars_to_dims_):
all_dims = list(set(sum((list(dd) for dd in vars_to_dims_.values()), [])))
ds = fixed_datasets(vars_to_dims_)
dims = subset_lists(all_dims)
vars_ = sampled_from(list(vars_to_dims_.keys()))
vars_dict = dictionaries(vars_, dims, dict_class=OrderedDict)
vars_dict = vars_dict.map(OrderedDict.items).map(list)
return tuples(ds, vars_dict, just(all_dims))
vars_to_dims_st = vars_to_dims_dicts(min_vars=0, min_dims=0)
S = vars_to_dims_st.flatmap(build_it)
return S
示例3: sig_pair
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def sig_pair():
def separate(D):
signatures, signatures_ref = {}, {}
for kk in D:
if len(D[kk]) == 1:
v_ref, = D[kk]
signatures_ref[kk] = np.asarray(v_ref)
elif len(D[kk]) == 2:
v, v_ref = D[kk]
signatures[kk] = np.asarray(v)
signatures_ref[kk] = np.asarray(v_ref)
else:
assert False
return signatures, signatures_ref
sig_dict = dictionaries(text(), tuples(bsigs()) | tuples(bsigs(), bsigs()))
S = sig_dict.map(separate)
return S
示例4: simple_attrs_with_metadata
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def simple_attrs_with_metadata(draw):
"""
Create a simple attribute with arbitrary metadata.
"""
c_attr = draw(simple_attrs)
keys = st.booleans() | st.binary() | st.integers() | st.text()
vals = st.booleans() | st.binary() | st.integers() | st.text()
metadata = draw(
st.dictionaries(keys=keys, values=vals, min_size=1, max_size=3)
)
return attr.ib(
default=c_attr._default,
validator=c_attr._validator,
repr=c_attr.repr,
eq=c_attr.eq,
order=c_attr.order,
hash=c_attr.hash,
init=c_attr.init,
metadata=metadata,
type=None,
converter=c_attr.converter,
)
示例5: merge_dicts_max_size_strategy
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def merge_dicts_max_size_strategy(dict1, dict2, max_size):
"""Combine dict strategies into one to produce a dict up to a max size.
Assumes both dicts have distinct keys.
:param max_size: Maximum number of keys in dicts generated by the strategy.
:type max_size: int
"""
# This is grim, but combine both dictionaries after creating a copy of the
# second containing a reduced number of keys if that would take us over the
# max size.
result = hy_st.builds(
lambda x, y: dict((list(x.items()) + list(y.items()))[:max_size]),
dict1,
dict2)
return result
示例6: dict_str
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def dict_str(draw):
return draw(st.dictionaries(st.text(min_size=1), st.text(min_size=1), min_size=1))
示例7: homogeneous_dictionary
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def homogeneous_dictionary(**kwargs):
"""Return a strategy which generates a dictionary of uniform key:value type."""
return index_types.flatmap(lambda s: hs.dictionaries(s(), s(), **kwargs))
示例8: random_dictionary
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def random_dictionary(**kwargs):
"""Return a strategy which generates a random list."""
return hs.dictionaries(primitive_values, primitive_values, **kwargs)
示例9: random_dict_variable_homogeneous_value
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def random_dict_variable_homogeneous_value(**kwargs):
"""Return a strategy which generates a random dictionary of variable name and value"""
return primitive_types.flatmap(lambda s: hs.dictionaries(valid_identifier(), s(), **kwargs))
示例10: dict_node
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def dict_node(draw, key=const_node(), value=const_node(), **kwargs):
items = draw(hs.dictionaries(key, value, **kwargs)).items()
node = astroid.Dict()
node.postinit(items)
return node
示例11: jsonObject
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def jsonObject ():
""" JSON-encodable objects """
return st.dictionaries (st.text (), st.one_of (st.integers (), st.text ()))
示例12: chromeHeaders
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def chromeHeaders ():
# token as defined by https://tools.ietf.org/html/rfc7230#section-3.2.6
token = st.sampled_from('abcdefghijklmnopqrstuvwxyz0123456789!#$%&\'*+-.^_`|~')
# XXX: the value should be asciiText without leading/trailing spaces
return st.dictionaries (token, token)
示例13: field_to_strategy
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def field_to_strategy(field, env):
"""Generate strategy for field."""
if SCALAR_MAPPINGS.get(field.type) is not None:
return apply_modifier(
strategy=SCALAR_MAPPINGS[field.type],
field=field
)
if field.type is FieldDescriptor.TYPE_ENUM:
return apply_modifier(
strategy=find_strategy_in_env(field.enum_type, env),
field=field
)
if field.type is FieldDescriptor.TYPE_MESSAGE:
field_options = field.message_type.GetOptions()
if field_options.deprecated:
return st.none()
if field_options.map_entry:
k, v = field.message_type.fields
return st.dictionaries(
field_to_strategy(k, env).filter(non_null),
field_to_strategy(v, env).filter(non_null)
)
return apply_modifier(
strategy=find_strategy_in_env(field.message_type, env),
field=field
)
raise Exception("Unhandled field {}.".format(field))
示例14: containers
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def containers(primitives):
def extend(base):
return st.one_of(
st.lists(base, max_size=50),
st.lists(base, max_size=50).map(tuple),
st.dictionaries(
keys=hashable_containers(primitives),
values=base,
max_size=10
),
)
return st.recursive(primitives, extend, max_leaves=50)
示例15: nested_dictionaries
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import dictionaries [as 别名]
def nested_dictionaries():
simple_strings_alphabet = 'abcdefghijklmnopqrstuvwxyz\'"\r\n '
simple_text = st.text(alphabet=simple_strings_alphabet, min_size=5)
def extend(base):
return st.one_of(
st.lists(base, min_size=5),
st.dictionaries(keys=simple_text, values=base, min_size=1)
)
return st.recursive(simple_text, extend, max_leaves=50)