Esempio n. 1
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"
Esempio n. 2
0
    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"'
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    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"
Esempio n. 6
0
    def test_simple(self):
        w = Writer()
        assert w.write("abc") == 3
        assert w.getvalue() == "abc"

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