Exemple #1
0
def test_any_name_params_value_recode(name, value, param1, p1value, param2, p2value1, p2value2):
    assume(param1 != param2)
    raw = "%s;%s=%s;%s=%s,%s:%s" % (name, param1, quote_escape_param(p1value),
                                    param2, quote_escape_param(p2value1), quote_escape_param(p2value2), value)
    assert ContentLine.parse(raw).serialize() == raw
    cl = ContentLine(name, {param1: [p1value], param2: [p2value1, p2value2]}, value)
    assert ContentLine.parse(cl.serialize()) == cl
    assert string_to_container(raw) == [cl]
Exemple #2
0
def test_any_text_value_recode(value):
    esc = TextConv.serialize(value)
    assert TextConv.parse(esc) == value
    cl = ContentLine("TEST", value=esc)
    assert ContentLine.parse(cl.serialize()) == cl
    assert string_to_container(cl.serialize()) == [cl]
    vals = [esc, esc, "test", esc]
    cl2 = ContentLine("TEST", value=TextConv.join_value_list(vals))
    assert list(TextConv.split_value_list(cl2.value)) == vals
    assert ContentLine.parse(cl.serialize()) == cl
    assert string_to_container(cl.serialize()) == [cl]
Exemple #3
0
def test_trailing_escape_value_list():
    cl1 = ContentLine.parse("TEST:this is,a list \\, with a\\\\,trailing escape\\")
    with pytest.raises(ValueError) as excinfo:
        list(TextConv.split_value_list(cl1.value))
    assert "not end with an escape sequence" in str(excinfo.value)

    cl2 = ContentLine.parse("TEST:this is,a list \\, with a\\\\,trailing escape")
    assert list(TextConv.split_value_list(cl2.value)) == \
           ["this is", "a list \\, with a\\\\", "trailing escape"]
    assert [TextConv.parse(v) for v in TextConv.split_value_list(cl2.value)] == \
           ["this is", "a list , with a\\", "trailing escape"]
Exemple #4
0
def test_example_text_recode(inp_esc, out_uesc):
    par_esc = ContentLine.parse(inp_esc)
    par_uesc = attr.evolve(par_esc, value=TextConv.parse(par_esc.value))
    out_esc = attr.evolve(out_uesc, value=TextConv.serialize(out_uesc.value))
    assert par_uesc == out_uesc
    ser_esc = out_esc.serialize()
    assert inp_esc == ser_esc
    assert string_to_container(inp_esc) == [par_esc]
Exemple #5
0
def test_example_recode(inp, out):
    par = ContentLine.parse(inp)
    assert par == out
    ser = out.serialize()
    if inp[0].isupper():
        assert inp == ser
    else:
        assert inp.upper() == ser.upper()
    par_ser = par.serialize()
    if inp[0].isupper():
        assert inp == par_ser
    else:
        assert inp.upper() == par_ser.upper()
    assert string_to_container(inp) == [out]
Exemple #6
0
def test_value_characters():
    chars = "abcABC0123456789"  "-=_+!$%&*()[]{}<>'@#~/?|`¬€¨ÄÄää´ÁÁááßæÆ \t\\n😜🇪🇺👩🏾‍💻👨🏻‍👩🏻‍👧🏻‍👦🏻xyzXYZ"
    special_chars = ";:,\"^"
    inp = "TEST;P1={chars};P2={chars},{chars},\"{chars}\",{chars}:{chars}:{chars}{special}".format(
        chars=chars, special=special_chars)
    out = ContentLine("TEST", {"P1": [chars], "P2": [chars, chars, QuotedParamValue(chars), chars]},
                      chars + ":" + chars + special_chars)
    par = ContentLine.parse(inp)
    assert par == out
    ser = out.serialize()
    assert inp == ser
    par_ser = par.serialize()
    assert inp == par_ser
    assert string_to_container(inp) == [out]
Exemple #7
0
def test_param_quoting():
    inp = 'TEST;P1="A";P2=B;P3=C,"D",E,"F":"VAL"'
    out = ContentLine("TEST", {
        "P1": [QuotedParamValue("A")],
        "P2": ["B"],
        "P3": ["C", QuotedParamValue("D"), "E", QuotedParamValue("F")],
    }, '"VAL"')
    par = ContentLine.parse(inp)
    assert par == out
    ser = out.serialize()
    assert inp == ser
    par_ser = par.serialize()
    assert inp == par_ser
    assert string_to_container(inp) == [out]

    for param in out.params.keys():
        for o_val, p_val in zip(out[param], par[param]):
            assert type(o_val) == type(p_val)
Exemple #8
0
def test_unfold():
    val1 = "DESCRIPTION:This is a long description that exists on a long line."
    val2 = "DESCRIPTION:This is a lo\n ng description\n  that exists on a long line."
    assert "".join(unfold_lines(val2.splitlines())) == val1
    assert string_to_container(val1) == string_to_container(val2) == [ContentLine.parse(val1)]
    pytest.raises(ValueError, ContentLine.parse, val2)
Exemple #9
0
def test_any_param_value_recode(param, value):
    raw = "TEST;%s=%s:VALUE" % (param, quote_escape_param(value))
    assert ContentLine.parse(raw).serialize() == raw
    cl = ContentLine("TEST", {param: [value]}, "VALUE")
    assert ContentLine.parse(cl.serialize()) == cl
    assert string_to_container(raw) == [cl]
Exemple #10
0
def test_any_name_value_recode(name, value):
    raw = "%s:%s" % (name, value)
    assert ContentLine.parse(raw).serialize() == raw
    cl = ContentLine(name, value=value)
    assert ContentLine.parse(cl.serialize()) == cl
    assert string_to_container(raw) == [cl]
Exemple #11
0
def test_trailing_escape_param():
    with pytest.raises(ValueError) as excinfo:
        ContentLine.parse("TEST;PARAM=this ^^ is a ^'param^',with a ^trailing escape^:value")
    assert "not end with an escape sequence" in str(excinfo.value)
    assert ContentLine.parse("TEST;PARAM=this ^^ is a ^'param^',with a ^trailing escape:value").params["PARAM"] == \
           ["this ^ is a \"param\"", "with a ^trailing escape"]