Exemple #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", )
Exemple #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",)
Exemple #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
Exemple #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
Exemple #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()
Exemple #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
Exemple #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()
Exemple #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()
Exemple #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
Exemple #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()