示例#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",)
示例#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", )
示例#3
0
def test_fail_with_wrong_error_class(init):
    with pytest.raises(TypeError):
        PyReader(**init)
示例#4
0
def reader():
    return PyReader()
示例#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()
示例#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
示例#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
示例#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()
示例#9
0
def reader(loop):
    reader = StreamReader(loop=loop)
    reader.set_parser(
        PyReader(protocolError=ProtocolError, replyError=ReplyError)
    )
    return reader
示例#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()
示例#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
示例#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
示例#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()