Example #1
0
def test_parse_string_resources():
    assert openstep_plist.loads(
        "a=1;\n'b' = 2.4;\n'c' = \"hello world\";") == {
            "a": "1",
            "b": "2.4",
            "c": "hello world",
        }
Example #2
0
def test_parse_plist_data_invalid():
    with pytest.raises(openstep_plist.ParseError,
                       match="Expected terminating '>'"):
        openstep_plist.loads("<FF")

    msg = "Malformed data byte group at line 1: invalid hex digit: u?'Z'"
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("<Z")
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("<AZ")

    msg = "Malformed data byte group at line 1: uneven length"
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("<AAA")
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("<AAA>")
Example #3
0
def test_parse_plist_dict_invalid():
    msg = "Unexpected character after key at line 1: u?','"
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("{a,}")

    msg = "Missing ';' on line 1"
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("{b ")

    msg = "Missing ';' on line 2"
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("{b = zzz;\nc = xxx}")

    msg = "Expected terminating '}' for dictionary at line 3"
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads("{b = zzz;\nc = xxx;\nd = jjj;")
Example #4
0
def test_parse_plist_object_invalid():
    with pytest.raises(openstep_plist.ParseError,
                       match="Unexpected character"):
        openstep_plist.loads(";")
    with pytest.raises(openstep_plist.ParseError,
                       match="Unexpected EOF while parsing plist"):
        openstep_plist.loads("{a=")
    with pytest.raises(openstep_plist.ParseError,
                       match="Junk after plist at line 3"):
        openstep_plist.loads("{a=1;\nb=2;\n}...")
Example #5
0
def test_loads_dict_type():
    assert openstep_plist.loads("{z = (a, b); y = (c, d); a = 'hello world';}",
                                dict_type=OrderedDict) == (OrderedDict([
                                    ("z", ["a", "b"]), ("y", ["c", "d"]),
                                    ("a", "hello world")
                                ]))
Example #6
0
def test_loads_use_numbers(string, expected):
    assert openstep_plist.loads(string, use_numbers=True) == expected
Example #7
0
def test_load_from_bytes():
    if sys.version_info.major < 3:
        assert openstep_plist.loads(b"{a=1;}") == {"a": "1"}
    else:
        with pytest.raises(TypeError, match="Could not convert to unicode"):
            openstep_plist.loads(b"{a=1;}")
Example #8
0
def test_parse_plist_data(string, expected):
    assert openstep_plist.loads(string) == expected
Example #9
0
def test_parse_plist_dict_empty():
    assert openstep_plist.loads("") == {}
    assert openstep_plist.loads("{}") == {}
Example #10
0
def test_parse_plist_array_empty():
    assert openstep_plist.loads("()") == []
Example #11
0
def test_parse_plist_array_missing_paren(string, lineno):
    msg = r"Expected terminating '\)' for array at line %d" % lineno
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads(string)
Example #12
0
def test_parse_plist_array_missing_comma(string, lineno):
    msg = "Missing ',' for array at line %d" % lineno
    with pytest.raises(openstep_plist.ParseError, match=msg):
        openstep_plist.loads(string)
Example #13
0
def test_parse_plist_array():
    assert openstep_plist.loads("(1)") == ["1"]
    assert openstep_plist.loads("(1,)") == ["1"]
    assert openstep_plist.loads("(\t1  \r\n, 2.2, c,\n)") == ["1", "2.2", "c"]
    assert openstep_plist.loads("('1', '2')") == ["1", "2"]
    assert openstep_plist.loads("(\n1,\n\"'2'\"\n)") == ["1", "'2'"]