def test_dictionary(self, dictionary, expected_no_indent, expected_indent):
        w = Writer()
        assert w.write(dictionary) == len(expected_no_indent)
        assert w.getvalue() == expected_no_indent

        w = Writer(indent="  ")
        assert w.write(dictionary) == len(expected_indent)
        assert w.getvalue() == expected_indent
    def test_quoted_string_no_unicode_escape(self):
        w = Writer(unicode_escape=False)
        w.write("\u0410") == 3
        assert w.getvalue() == '"\u0410"'

        w = Writer(unicode_escape=False)
        assert w.write("\U0001F4A9") == (4 if is_narrow_unicode() else 3)
        assert w.getvalue() == '"\U0001F4A9"'
    def test_array(self, array, expected_no_indent, expected_indent):
        w = Writer()
        assert w.write(array) == len(expected_no_indent)
        assert w.getvalue() == expected_no_indent

        w = Writer(indent=2)
        assert w.write(array) == len(expected_indent)
        assert w.getvalue() == expected_indent
    def test_bool(self):
        w = Writer()
        assert w.write(True) == 1
        assert w.getvalue() == "1"

        w = Writer()
        assert w.write(False) == 1
        assert w.getvalue() == "0"
    def test_float_precision(self):
        w = Writer(float_precision=3)
        w.write(0.0001)
        assert w.getvalue() == "0"

        w = Writer(float_precision=0)
        w.write(0.999)
        assert w.getvalue() == "1"
    def test_simple(self):
        w = Writer()
        assert w.write("abc") == 3
        assert w.getvalue() == "abc"

        f = StringIO()
        w.dump(f)
        assert f.getvalue() == "abc"
 def test_float(self, flt, expected):
     w = Writer()
     w.write(flt)
     assert w.getvalue() == expected
 def test_int(self, integer, expected):
     w = Writer()
     w.write(integer)
     assert w.getvalue() == expected
 def test_quoted_string(self, string, expected):
     w = Writer()
     w.write(string)
     assert w.getvalue() == expected
Beispiel #10
0
 def test_unquoted_string(self):
     w = Writer()
     assert w.write(".appVersion") == 11
     assert w.getvalue() == ".appVersion"
Beispiel #11
0
 def test_None(self):
     w = Writer()
     w.write(None)
     assert w.getvalue() == '"(nil)"'
Beispiel #12
0
 def test_type_error(self):
     obj = object()
     w = Writer()
     with pytest.raises(TypeError, match="not PLIST serializable"):
         w.write(obj)
Beispiel #13
0
 def test_data(self, data, expected):
     w = Writer()
     assert w.write(data) == len(expected)
     assert w.getvalue() == expected