当前位置: 首页>>代码示例>>Python>>正文


Python strategies.sets方法代码示例

本文整理汇总了Python中hypothesis.strategies.sets方法的典型用法代码示例。如果您正苦于以下问题:Python strategies.sets方法的具体用法?Python strategies.sets怎么用?Python strategies.sets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hypothesis.strategies的用法示例。


在下文中一共展示了strategies.sets方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _build_node

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def _build_node(applications):
    # All the manifestations in `applications`.
    app_manifestations = set(
        app.volume.manifestation for app in applications if app.volume
    )
    # A set that contains all of those, plus an arbitrary set of
    # manifestations.
    dataset_ids = frozenset(
        app.volume.manifestation.dataset_id
        for app in applications if app.volume
    )
    manifestations = (
        st.sets(MANIFESTATIONS.filter(
            lambda m: m.dataset_id not in dataset_ids))
        .map(pset)
        .map(lambda ms: ms.union(app_manifestations))
        .map(lambda ms: dict((m.dataset.dataset_id, m) for m in ms)))
    return st.builds(
        Node, uuid=st.uuids(),
        applications=st.just({a.name: a for a in applications}),
        manifestations=manifestations) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:23,代码来源:test_persistence.py

示例2: test_change

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def test_change(self, C, data):
        """
        Changes work.
        """
        # Take the first attribute, and change it.
        assume(fields(C))  # Skip classes with no attributes.
        field_names = [a.name for a in fields(C)]
        original = C()
        chosen_names = data.draw(st.sets(st.sampled_from(field_names)))
        change_dict = {name: data.draw(st.integers()) for name in chosen_names}

        with pytest.deprecated_call():
            changed = assoc(original, **change_dict)

        for k, v in change_dict.items():
            assert getattr(changed, k) == v 
开发者ID:python-attrs,项目名称:attrs,代码行数:18,代码来源:test_funcs.py

示例3: merge_optional_dict_strategy

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def merge_optional_dict_strategy(required_fields, optional_fields):
    """Combine dicts of strings mapping to required and optional strategies.

    :param required_fields: Mapping containing required fields.
    :type required_fields: dict(str)
    :param optional_fields: Mapping containing optional fields.
    :type optional_fields: dict(str)
    """
    # Create a strategy for a set of keys from the optional dict strategy, then
    # a strategy to build those back into a dictionary.
    # Finally, merge the strategy of selected optionals with the required one.
    opt_keys = hy_st.sets(hy_st.sampled_from(list(optional_fields.keys())))
    selected_optionals = hy_st.builds(
        lambda dictionary, keys: {key: dictionary[key] for key in keys},
        hy_st.fixed_dictionaries(optional_fields),
        opt_keys)
    result = merge_dicts_strategy(hy_st.fixed_dictionaries(required_fields),
                                  selected_optionals)
    return result 
开发者ID:olipratt,项目名称:swagger-conformance,代码行数:21,代码来源:basestrategies.py

示例4: enums_of_primitives

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def enums_of_primitives(draw):
    """Generate enum classes with primitive values."""
    names = draw(st.sets(st.text(min_size=1), min_size=1))
    n = len(names)
    vals = draw(
        st.one_of(
            st.sets(
                st.one_of(
                    st.integers(),
                    st.floats(allow_nan=False),
                    st.text(min_size=1),
                ),
                min_size=n,
                max_size=n,
            )
        )
    )
    return Enum("HypEnum", list(zip(names, vals))) 
开发者ID:Tinche,项目名称:cattrs,代码行数:20,代码来源:__init__.py

示例5: set_node

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def set_node(draw, elt=const_node(), **kwargs):
    """Return a Set node with elements drawn from elt.
    """
    node = astroid.Set()
    node.postinit(draw(hs.sets(elt, **kwargs)))
    return node 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:custom_hypothesis_support.py

示例6: graphs

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def graphs(
    draw,
    keys=ascii_uppercase,
    allow_self_links=True,
    directed=True,
    force_path=True,
    edge_cost=False,
):
    result = {c: set() for c in keys}
    for i, c in enumerate(keys):
        # The inner strategy for keys (node identifiers) is a sampled_from,
        # rejecting the current node iff allow_self_links is False.
        # Cost will always be 1, or 1-10 inclusive if edge_cost is True.
        # Then we choose a set of neighbors for node c, and update the graph:
        key_strat = st.sampled_from(keys).filter(lambda k: allow_self_links or k != c)
        cost_strat = st.integers(1, 10) if edge_cost else st.just(1)
        neighbors = draw(
            st.sets(st.tuples(key_strat, cost_strat), min_size=1, max_size=4)
        )

        result[c].update(neighbors)
        if not directed:
            for k in neighbors:
                result[k].add((c, 1))
        if force_path:
            # Ensure that there *is* always a path between any pair of nodes,
            # by linking each node to the next in order.  We therefore have a
            # directed ring, plus some number of cross-links.
            result[c].add((keys[i - 1], 1))
            if not directed:
                result[keys[i - 1]].add((c, 1))
    return result 
开发者ID:Zac-HD,项目名称:escape-from-automanual-testing,代码行数:34,代码来源:tough-bonus-problems.py

示例7: test_sets_and_objects_differ

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def test_sets_and_objects_differ(self):
        """
        Sets can be hashed and 1 element sets have a different hash than the
        hash of the single element.
        """
        self.assertThat(
            generation_hash(5),
            Not(Equals(generation_hash(frozenset([5]))))
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:11,代码来源:test_persistence.py

示例8: test_lists_and_objects_differ

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def test_lists_and_objects_differ(self):
        """
        Lists can be hashed, and have a different hash value than scalars with
        the same value or sets with the same values.
        """
        self.assertThat(
            generation_hash(913),
            Not(Equals(generation_hash([913])))
        )
        self.assertThat(
            generation_hash(frozenset([913])),
            Not(Equals(generation_hash([913])))
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:15,代码来源:test_persistence.py

示例9: test_empty_sets_can_be_hashed

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def test_empty_sets_can_be_hashed(self):
        """
        Empty sets can be hashed and result in different hashes than empty
        strings or the string 'NULLSET'.
        """
        self.assertThat(
            generation_hash(frozenset()),
            Not(Equals(generation_hash('')))
        )
        self.assertThat(
            generation_hash(frozenset()),
            Not(Equals(generation_hash(b'NULLSET')))
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:15,代码来源:test_persistence.py

示例10: mut_sets_of_primitives

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def mut_sets_of_primitives(draw):
    """A strategy that generates mutable sets of primitives."""
    prim_strat, t = draw(primitive_strategies)
    set_t = draw(set_types.map(lambda set_t: set_t[t]) | set_types)
    return draw(st.sets(prim_strat)), set_t 
开发者ID:Tinche,项目名称:cattrs,代码行数:7,代码来源:__init__.py

示例11: frozen_sets_of_primitives

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def frozen_sets_of_primitives(draw):
    """A strategy that generates frozen sets of primitives."""
    prim_strat, t = draw(primitive_strategies)
    set_t = draw(st.just(Set) | st.just(Set[t]))
    return frozenset(draw(st.sets(prim_strat))), set_t 
开发者ID:Tinche,项目名称:cattrs,代码行数:7,代码来源:__init__.py

示例12: test_request_examples_without_huffman

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import sets [as 别名]
def test_request_examples_without_huffman(self):
        """
        This section shows several consecutive header sets, corresponding to
        HTTP requests, on the same connection.
        """
        e = Encoder()
        first_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com'),
        ]
        # We should have :authority in first_header_table since we index it
        first_header_table = [(':authority', 'www.example.com')]
        first_result = b'\x82\x86\x84\x41\x0fwww.example.com'

        assert e.encode(first_header_set, huffman=False) == first_result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8'))
            for n, v in first_header_table
        ]

        second_header_set = [
            (':method', 'GET',),
            (':scheme', 'http',),
            (':path', '/',),
            (':authority', 'www.example.com',),
            ('cache-control', 'no-cache'),
        ]
        second_header_table = [
            ('cache-control', 'no-cache'),
            (':authority', 'www.example.com')
        ]
        second_result = b'\x82\x86\x84\xbeX\x08no-cache'

        assert e.encode(second_header_set, huffman=False) == second_result
        assert list(e.header_table.dynamic_entries) == [
            (n.encode('utf-8'), v.encode('utf-8'))
            for n, v in second_header_table
        ]

        third_header_set = [
            (':method', 'GET',),
            (':scheme', 'https',),
            (':path', '/index.html',),
            (':authority', 'www.example.com',),
            ('custom-key', 'custom-value'),
        ]
        third_result = (
            b'\x82\x87\x85\xbf@\ncustom-key\x0ccustom-value'
        )

        assert e.encode(third_header_set, huffman=False) == third_result
        # Don't check the header table here, it's just too complex to be
        # reliable. Check its length though.
        assert len(e.header_table.dynamic_entries) == 3 
开发者ID:python-hyper,项目名称:hpack,代码行数:58,代码来源:test_hpack.py


注:本文中的hypothesis.strategies.sets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。