當前位置: 首頁>>代碼示例>>Python>>正文


Python strategies.dictionaries方法代碼示例

本文整理匯總了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} 
開發者ID:telepresenceio,項目名稱:telepresence,代碼行數:24,代碼來源:test_output_mask.py

示例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 
開發者ID:uber,項目名稱:bayesmark,代碼行數:20,代碼來源:xr_util_test.py

示例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 
開發者ID:uber,項目名稱:bayesmark,代碼行數:20,代碼來源:signatures_test.py

示例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,
    ) 
開發者ID:python-attrs,項目名稱:attrs,代碼行數:25,代碼來源:strategies.py

示例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 
開發者ID:olipratt,項目名稱:swagger-conformance,代碼行數:18,代碼來源:basestrategies.py

示例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)) 
開發者ID:KissPeter,項目名稱:APIFuzzer,代碼行數:4,代碼來源:unit_test_composer.py

示例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)) 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:5,代碼來源:custom_hypothesis_support.py

示例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) 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:5,代碼來源:custom_hypothesis_support.py

示例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)) 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:5,代碼來源:custom_hypothesis_support.py

示例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 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:7,代碼來源:custom_hypothesis_support.py

示例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 ())) 
開發者ID:PromyLOPh,項目名稱:crocoite,代碼行數:5,代碼來源:test_warc.py

示例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) 
開發者ID:PromyLOPh,項目名稱:crocoite,代碼行數:7,代碼來源:test_browser.py

示例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)) 
開發者ID:hchasestevens,項目名稱:hypothesis-protobuf,代碼行數:35,代碼來源:module_conversion.py

示例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) 
開發者ID:tommikaikkonen,項目名稱:prettyprinter,代碼行數:15,代碼來源:test_prettyprinter.py

示例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) 
開發者ID:tommikaikkonen,項目名稱:prettyprinter,代碼行數:13,代碼來源:test_prettyprinter.py


注:本文中的hypothesis.strategies.dictionaries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。