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


Python strategies.binary方法代码示例

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


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

示例1: requestResponsePair

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def requestResponsePair ():
    def f (creq, cresp, hasPostData, reqBody, respBody):
        i = RequestResponsePair ()
        i.fromRequestWillBeSent (creq)
        i.request.hasPostData = hasPostData
        if hasPostData:
            i.request.body = reqBody

        if cresp is not None:
            i.fromResponseReceived (cresp)
            if respBody is not None:
                i.response.body = respBody
        return i

    bodySt = st.one_of (
            st.none (),
            st.builds (UnicodeBody, st.text ()),
            st.builds (Base64Body.fromBytes, st.binary ())
            )
    return st.builds (lambda reqresp, hasPostData, reqBody, respBody:
            f (reqresp[0], reqresp[1], hasPostData, reqBody, respBody),
            chromeReqResp (), st.booleans (), bodySt, bodySt) 
开发者ID:PromyLOPh,项目名称:crocoite,代码行数:24,代码来源:test_browser.py

示例2: test_signing_root

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_signing_root(data, sedes_and_values):
    unsigned_sedes, unsigned_values = sedes_and_values
    unsigned_value = data.draw(unsigned_values)
    unsigned_hashable_value = to_hashable_value(unsigned_value, unsigned_sedes)

    class SignedValueClass(SignedHashableContainer):
        fields = unsigned_hashable_value._meta.fields + (("signature", bytes96),)

    signature = data.draw(st.binary(min_size=96, max_size=96))
    kwargs = {
        field_name: unsigned_hashable_value[field_name]
        for field_name in SignedValueClass._meta.field_names
        if field_name != "signature"
    }
    hashable_value = SignedValueClass.create(**kwargs, signature=signature)

    assert hashable_value.signing_root == unsigned_hashable_value.hash_tree_root 
开发者ID:ethereum,项目名称:py-ssz,代码行数:19,代码来源:test_hashable_structures.py

示例3: simple_attrs_with_metadata

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [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

示例4: test_content_disposition_directly

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_content_disposition_directly(s):
    """Test rfc6266.parse_headers directly with binary data."""
    try:
        cd = rfc6266.parse_headers(s)
        cd.filename()
    except (SyntaxError, UnicodeDecodeError, rfc6266.Error):
        pass 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:9,代码来源:test_http_hypothesis.py

示例5: _bytes_strategy

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def _bytes_strategy(
    abi_type: BasicType, min_size: Optional[int] = None, max_size: Optional[int] = None
) -> SearchStrategy:
    size = abi_type.sub
    if not size:
        return st.binary(min_size=min_size or 1, max_size=max_size or 64)
    if size < 1 or size > 32:
        raise ValueError(f"Invalid type: {abi_type.to_type_str()}")
    if min_size is not None or max_size is not None:
        raise TypeError("Cannot specify size for fixed length bytes strategy")
    return st.binary(min_size=size, max_size=size) 
开发者ID:eth-brownie,项目名称:brownie,代码行数:13,代码来源:strategies.py

示例6: init_default_strategies

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def init_default_strategies() -> None:
    """Register all default "format" strategies."""
    register_string_format("binary", st.binary())
    register_string_format("byte", st.binary().map(lambda x: b64encode(x).decode()))

    def make_basic_auth_str(item: Tuple[str, str]) -> str:
        return _basic_auth_str(*item)

    register_string_format("_basic_auth", st.tuples(st.text(), st.text()).map(make_basic_auth_str))  # type: ignore
    register_string_format("_bearer_auth", st.text().map("Bearer {}".format)) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:12,代码来源:_hypothesis.py

示例7: line_delimited_data

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def line_delimited_data(draw, max_line_size, min_lines=1):
    n = draw(max_line_size)
    data = st.binary(min_size=1, max_size=n).filter(lambda d: b"\n" not in d)
    lines = draw(
        st.lists(data, min_size=min_lines).filter(
            lambda l: sum(map(len, l)) + len(l) <= n
        )
    )
    return b"\n".join(lines) + b"\n" 
开发者ID:pypa,项目名称:linehaul,代码行数:11,代码来源:strategies.py

示例8: test_bytes_serialization_decode_many

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_bytes_serialization_decode_many(binary, message_normalizer):
        result = message_normalizer(binary, should_repr_strings=False)
        assert result == binary.decode("utf-8", "replace") 
开发者ID:getsentry,项目名称:sentry-python,代码行数:5,代码来源:test_serializer.py

示例9: test_bytes_serialization_repr_many

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_bytes_serialization_repr_many(binary, message_normalizer):
        result = message_normalizer(binary, should_repr_strings=True)
        assert result == repr(binary) 
开发者ID:getsentry,项目名称:sentry-python,代码行数:5,代码来源:test_serializer.py

示例10: test_bytes_serialization_decode

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_bytes_serialization_decode(message_normalizer):
    binary = b"abc123\x80\xf0\x9f\x8d\x95"
    result = message_normalizer(binary, should_repr_strings=False)
    assert result == u"abc123\ufffd\U0001f355" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:6,代码来源:test_serializer.py

示例11: test_bytes_serialization_repr

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_bytes_serialization_repr(message_normalizer):
    binary = b"abc123\x80\xf0\x9f\x8d\x95"
    result = message_normalizer(binary, should_repr_strings=True)
    assert result == r"b'abc123\x80\xf0\x9f\x8d\x95'" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:6,代码来源:test_serializer.py

示例12: test_bytes_idval

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def test_bytes_idval(self) -> None:
        """unittest for the expected behavior to obtain ids for parametrized
        bytes values:
        - python2: non-ascii strings are considered bytes and formatted using
        "binary escape", where any byte < 127 is escaped into its hex form.
        - python3: bytes objects are always escaped using "binary escape".
        """
        values = [
            (b"", ""),
            (b"\xc3\xb4\xff\xe4", "\\xc3\\xb4\\xff\\xe4"),
            (b"ascii", "ascii"),
            ("αρά".encode(), "\\xce\\xb1\\xcf\\x81\\xce\\xac"),
        ]
        for val, expected in values:
            assert _idval(val, "a", 6, idfn=None, nodeid=None, config=None) == expected 
开发者ID:pytest-dev,项目名称:pytest,代码行数:17,代码来源:metafunc.py

示例13: event

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def event ():
    return st.one_of (
            st.builds (ControllerStart, jsonObject ()),
            st.builds (Script.fromStr, st.text (), st.one_of(st.none (), st.text ())),
            st.builds (ScreenshotEvent, urls (), st.integers (), st.binary ()),
            st.builds (DomSnapshotEvent, urls (), st.builds (lambda x: x.encode ('utf-8'), st.text ()), viewport()),
            requestResponsePair (),
            ) 
开发者ID:PromyLOPh,项目名称:crocoite,代码行数:10,代码来源:test_warc.py

示例14: pem_objects

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def pem_objects(draw):
    """
    Strategy for generating ``pem`` objects.
    """
    key = RSAPrivateKey((
        b'-----BEGIN RSA PRIVATE KEY-----\n' +
        encodebytes(draw(s.binary(min_size=1))) +
        b'-----END RSA PRIVATE KEY-----\n'))
    return [key] + [
        Certificate((
            b'-----BEGIN CERTIFICATE-----\n' +
            encodebytes(cert) +
            b'-----END CERTIFICATE-----\n'))
        for cert in draw(s.lists(s.binary(min_size=1), min_size=1))] 
开发者ID:twisted,项目名称:txacme,代码行数:16,代码来源:strategies.py

示例15: chunk_st

# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import binary [as 别名]
def chunk_st():
    return st.binary(min_size=32, max_size=32) 
开发者ID:ethereum,项目名称:py-ssz,代码行数:4,代码来源:chunk_strategies.py


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