示例#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_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
示例#4
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
示例#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_bulk_string_with_invalid_encoding():
    reader = PyReader(encoding="unknown")
    reader.feed(b"$5\r\nhello\r\n")
    with pytest.raises(LookupError):
        reader.gets()
示例#8
0
def test_protocol_error_with_custom_class(exc, arg):
    reader = PyReader(protocolError=arg)
    reader.feed(b"x")
    with pytest.raises(exc):
        reader.gets()
示例#9
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
示例#10
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()