async def test_dispatcher_receive(): mock_reader = Mock(spec=asyncio.StreamReader) d = Dispatcher(None, mock_reader, None) d._reader = mock_reader stream = SBytes(b"\x85\x00\x00\x00\x00\x02\x01\x00\x02\xaa\xbb") mock_reader.readexactly = get_mock_coro(lambda x: stream.grab(x)) # mock_reader.returns = b'\01\84\00\00\08\00' data = await d._receive(lambda x: [1, 2, 0, 2, 2]) assert data[5] == b"\xaa\xbb"
def test_sbytes_at_end(): t = SBytes(b"12345") t.grab(1) t.grab(3) t.grab(1) assert t.at_end()
def test_sbytes_overflow(): with pytest.raises(InternalDriverError, match=r"cannot go beyond"): t = SBytes(b"12345") t.grab(1) t.grab(3) t.grab(2)
def test_sbytes_remaining(): t = SBytes(b"\x03\13\45") t.grab(2) assert t.remaining == b"%"