當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。