我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用hypothesis.strategies.binary()。
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'
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)
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)
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)}
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))]