def test_stream_part_above_read_size(): stream = StreamChain(ascii_lowercase.encode()) assert stream.read(4) == b"abcd" assert stream.read(8) == b"efghijkl" assert stream.read(2) == b"mn" assert stream.read(8) == b"opqrstuv" assert stream.read(1) == b"w" assert stream.read(8) == b"xyz" assert stream.read(8) == b""
def test_chain_types(): stream = StreamChain( b"ab", bytearray(b"cd"), memoryview(b"ef"), BytesIO(b"gh"), [b"ij"], (b"kl", ), iter([b"mn"]), op_qr_generator(), ) assert stream.read(42) == b"ab" assert stream.read(42) == b"cd" assert stream.read(42) == b"ef" assert stream.read(42) == b"gh" assert stream.read(42) == b"ij" assert stream.read(42) == b"kl" assert stream.read(42) == b"mn" assert stream.read(42) == b"op" assert stream.read(42) == b"qr" assert stream.read(42) == b""
def __init__(self, *streams): iterator = IterWithRollback( iterparse(StreamChain(*streams), ("start", "end"))) self._handle = lambda h: _parse(iterator, h, (), None, 0)
def test_types_invalid(stream, err_message): stream = StreamChain(stream) with pytest.raises(TypeError) as excinfo: stream.read(42) assert err_message in str(excinfo.value)
def test_no_stream(): stream = StreamChain() assert stream.readable() is True assert stream.read(42) == b""
def test_types(stream): stream = StreamChain(stream) assert stream.read(42) == b"abcdef" assert stream.read(42) == b""
def test_invalid_read_sizes(size): stream = StreamChain(b"Hello, world!") with pytest.raises(NotImplementedError): stream.read(size)
def test_pass_read_size(streams): stream = StreamChain(*streams) assert stream.read(3) == b"***" assert stream.read(4) == b"4444" assert stream.read(8) == b"88888888" assert stream.read(2) == b"22"
def test_skip_empty_values(): stream = StreamChain(b"", b"", b"abc", b"", b"", b"def", b"", b"ghi", b"") assert stream.read(42) == b"abc" assert stream.read(42) == b"def" assert stream.read(42) == b"ghi" assert stream.read(42) == b""