Beispiel #1
0
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",)
Beispiel #2
0
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", )
Beispiel #3
0
def test_fail_with_wrong_error_class(init):
    with pytest.raises(TypeError):
        PyReader(**init)
Beispiel #4
0
def reader():
    return PyReader()
Beispiel #5
0
def test_protocol_error_with_custom_class(exc, arg):
    reader = PyReader(protocolError=arg)
    reader.feed(b"x")
    with pytest.raises(exc):
        reader.gets()
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
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()
Beispiel #9
0
def reader(loop):
    reader = StreamReader(loop=loop)
    reader.set_parser(
        PyReader(protocolError=ProtocolError, replyError=ReplyError)
    )
    return reader
Beispiel #10
0
def test_protocol_error_with_custom_class(exc, arg):
    reader = PyReader(protocolError=arg)
    reader.feed(b"x")
    with pytest.raises(exc):
        reader.gets()
Beispiel #11
0
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
Beispiel #12
0
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
Beispiel #13
0
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()