Skip to content

Commit

Permalink
Fix Windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roganov committed Apr 18, 2018
1 parent 6d9a1cd commit 91e5dc3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import json
import zlib
from unittest import mock

import pytest
Expand Down Expand Up @@ -798,28 +799,33 @@ async def test_writer_write(buf, stream, writer):
b'--:--\r\n') == bytes(buf))


@pytest.mark.parametrize('encoding,encoded', [
('gzip', b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x0b\xc9\xccMU(\xc9W'
b'\x08J\xcdI\xacP\x04\x00$\xfb\x9eV\x0e\x00\x00\x00\r\n--:--'
b'\r\n'),
('deflate', b'\x0b\xc9\xccMU(\xc9W\x08J\xcdI\xacP\x04\x00\r\n--:--\r\n'),
pytest.param(
'br', b'\x1b\r\x00\x00\xa4B\xf0\xaa\x10I\xcaT\t.\x0b\xf7\x01\r\n--:--'
b'\r\n',
marks=skip_if_no_brotli,
),
def decompress(encoding, data):
if encoding == 'gzip':
obj = zlib.decompressobj(wbits=16 + zlib.MAX_WBITS)
return obj.decompress(data) + obj.flush()
elif encoding == 'deflate':
obj = zlib.decompressobj(wbits=-zlib.MAX_WBITS)
return obj.decompress(data) + obj.flush()
elif encoding == 'br':
import brotli
return brotli.decompress(data)


@pytest.mark.parametrize('encoding', [
'gzip',
'deflate',
pytest.param('br', marks=skip_if_no_brotli),
])
async def test_writer_serialize_with_content_encoding(buf, stream,
writer, encoding,
encoded):
writer, encoding):
writer.append('Time to Relax!', {CONTENT_ENCODING: encoding})
await writer.write(stream)
headers, message = bytes(buf).split(b'\r\n\r\n', 1)

assert (b'--:\r\nContent-Encoding: %s\r\n'
b'Content-Type: text/plain; charset=utf-8'
% encoding.encode('ascii') == headers)
assert message == encoded
assert decompress(encoding, message.split(b'\r\n')[0]) == b'Time to Relax!'


async def test_writer_serialize_with_content_encoding_identity(buf, stream,
Expand Down

0 comments on commit 91e5dc3

Please sign in to comment.