本文整理汇总了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)
示例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
示例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,
)
示例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
示例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)
示例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))
示例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"
示例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")
示例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)
示例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"
示例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'"
示例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
示例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 (),
)
示例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))]
示例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)