示例#1
0
def test_render_list_with_empty_list_raw():
    from iredis.config import config

    config.raw = True
    raw = []
    out = renders.render_list(raw, None)
    assert out == b""
示例#2
0
def test_render_list_while_config_raw():
    from iredis.config import config

    config.raw = True
    raw = ["hello", "world", "foo"]
    out = renders.render_list([item.encode() for item in raw], raw)
    assert b"hello\nworld\nfoo" == out
示例#3
0
def test_render_list_with_nil_init_while_config_raw():
    from iredis.config import config

    config.raw = True
    raw = [b"hello", None, b"world"]
    out = renders.render_list(raw, None)
    assert out == b"hello\n\nworld"
示例#4
0
def test_render_list_with_empty_list():
    from iredis.config import config

    config.raw = False
    raw = []
    out = renders.render_list(raw, None)
    out = strip_formatted_text(out)
    assert out == "(empty list or set)"
示例#5
0
def test_render_list_with_nil_init():
    from iredis.config import config

    config.raw = False
    raw = [b"hello", None, b"world"]
    out = renders.render_list(raw, None)
    out = strip_formatted_text(out)
    assert out == '1) "hello"\n2) (nil)\n3) "world"'
示例#6
0
def test_render_list_index():
    from iredis.config import config

    config.raw = False
    raw = ["hello", "world", "foo"]
    out = renders.render_list([item.encode() for item in raw], raw)
    out = strip_formatted_text(out)
    assert isinstance(out, str)
    assert "3)" in out
    assert "1)" in out
    assert "4)" not in out
示例#7
0
def test_render_list_index_const_width():
    from iredis.config import config

    config.raw = False
    raw = ["hello"] * 100
    out = renders.render_list([item.encode() for item in raw], raw)
    out = strip_formatted_text(out)
    assert isinstance(out, str)
    assert "  1)" in out
    assert "\n100)" in out

    raw = ["hello"] * 1000
    out = renders.render_list([item.encode() for item in raw], raw)
    out = strip_formatted_text(out)
    assert "   1)" in out
    assert "\n 999)" in out
    assert "\n1000)" in out

    raw = ["hello"] * 10
    out = renders.render_list([item.encode() for item in raw], raw)
    out = strip_formatted_text(out)
    assert " 1)" in out
    assert "\n 9)" in out
    assert "\n10)" in out
示例#8
0
def test_render_nested_list():
    text = [[b"get", 2, [b"readonly", b"fast"], 1, 1, 1]]
    config.raw = False
    assert renders.render_list(text, None) == FormattedText(
        [
            ("", "1)"),
            ("", " "),
            ("", "1)"),
            ("", " "),
            ("class:string", '"get"'),
            ("", "\n"),
            ("", "   "),
            ("", "2)"),
            ("", " "),
            ("class:string", '"2"'),
            ("", "\n"),
            ("", "   "),
            ("", "3)"),
            ("", " "),
            ("", "1)"),
            ("", " "),
            ("class:string", '"readonly"'),
            ("", "\n"),
            ("", "      "),
            ("", "2)"),
            ("", " "),
            ("class:string", '"fast"'),
            ("", "\n"),
            ("", "   "),
            ("", "4)"),
            ("", " "),
            ("class:string", '"1"'),
            ("", "\n"),
            ("", "   "),
            ("", "5)"),
            ("", " "),
            ("class:string", '"1"'),
            ("", "\n"),
            ("", "   "),
            ("", "6)"),
            ("", " "),
            ("class:string", '"1"'),
        ]
    )