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]
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]
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]
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)
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]
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]