Ejemplo n.º 1
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"'
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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"
Ejemplo n.º 5
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"
Ejemplo 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"
Ejemplo n.º 7
0
 def test_float(self, flt, expected):
     w = Writer()
     w.write(flt)
     assert w.getvalue() == expected
Ejemplo n.º 8
0
 def test_int(self, integer, expected):
     w = Writer()
     w.write(integer)
     assert w.getvalue() == expected
Ejemplo n.º 9
0
 def test_quoted_string(self, string, expected):
     w = Writer()
     w.write(string)
     assert w.getvalue() == expected
Ejemplo n.º 10
0
 def test_unquoted_string(self):
     w = Writer()
     assert w.write(".appVersion") == 11
     assert w.getvalue() == ".appVersion"
Ejemplo n.º 11
0
 def test_None(self):
     w = Writer()
     w.write(None)
     assert w.getvalue() == '"(nil)"'
Ejemplo n.º 12
0
 def test_data(self, data, expected):
     w = Writer()
     assert w.write(data) == len(expected)
     assert w.getvalue() == expected