def test_multi_bulk_with_invalid_encoding_and_partial_reply(data): reader = PyReader(encoding="unknown") for chunk in data: reader.feed(chunk) assert reader.gets() is False reader.feed(b"\r\n") with pytest.raises(LookupError): reader.gets() reader.feed(b":1\r\n") assert reader.gets() == 1
def test_multi_bulk_with_invalid_encoding_and_partial_reply(data): reader = PyReader(encoding="unknown") for chunk in data: reader.feed(chunk) assert reader.gets() is False reader.feed(b"\r\n") with pytest.raises(LookupError): reader.gets() reader.feed(b':1\r\n') assert reader.gets() == 1
def test_error_string_with_custom_class(exc, arg): reader = PyReader(replyError=arg) reader.feed(b"-error\r\n") error = reader.gets() assert isinstance(error, exc) assert error.args == ("error", )
def test_error_string_with_custom_class(exc, arg): reader = PyReader(replyError=arg) reader.feed(b"-error\r\n") error = reader.gets() assert isinstance(error, exc) assert error.args == ("error",)
def test_protocol_error_with_custom_class(exc, arg): reader = PyReader(protocolError=arg) reader.feed(b"x") with pytest.raises(exc): reader.gets()
def test_simple_string_with_encoding(encoding, expected): snowman = b"\xe2\x98\x83" reader = PyReader(encoding=encoding) reader.feed(b"+" + snowman + b"\r\n") assert reader.gets() == expected
def test_bulk_string_with_invalid_encoding(): reader = PyReader(encoding="unknown") reader.feed(b"$5\r\nhello\r\n") with pytest.raises(LookupError): reader.gets()