Python hypothesis.strategies 模块,binary() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用hypothesis.strategies.binary()

项目:chalice    作者:aws    | 项目源码 | 文件源码
def test_can_encode_binary_body_with_header_charset(sample_app):
    response = app.Response(
        status_code=200,
        body=b'foobar',
        headers={'Content-Type': 'application/octet-stream; charset=binary'}
    )
    encoded_response = response.to_dict(sample_app.api.binary_types)
    assert encoded_response['body'] == 'Zm9vYmFy'
项目:chalice    作者:aws    | 项目源码 | 文件源码
def test_handles_binary_responses(body, content_type):
    r = Response(body=body, headers={'Content-Type': content_type})
    serialized = r.to_dict(BINARY_TYPES)
    # A binary response should always result in the
    # response being base64 encoded.
    assert serialized['isBase64Encoded']
    assert isinstance(serialized['body'], six.string_types)
    assert isinstance(base64.b64decode(serialized['body']), bytes)
项目:coding-practice    作者:imranariffin    | 项目源码 | 文件源码
def test_byte_to_bits(self, b):
        """byte_to_bits produces binary strings of length 8"""

        self.assertTrue(set(byte_to_bits(b)).issubset({"0", "1"}))
        self.assertEqual(len(byte_to_bits(b)), 8)
项目:client    作者:syncrypt    | 项目源码 | 文件源码
def file(draw, filename=st.lists(
        st.characters(blacklist_categories=('Cc',),
            blacklist_characters=('\0\n\r/\\|><')),
            min_size=1, average_size=20, max_size=80),
            content=st.binary(max_size=10000, average_size=100)):
    return {'filename': ''.join(draw(filename)),
            'content': draw(content)}
项目:txacme    作者:twisted    | 项目源码 | 文件源码
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))]