Exemplo n.º 1
0
    def test_json(self):
        j = decoder.DECODER(TEST_JSON)
        assert j == json.loads(TEST_JSON)

        s = writer.dumps(j)
        j2 = decoder.DECODER(s)
        assert j2 == j

        s2 = writer.dumps(j2)
        assert s == s2

        assert s == EXPECTED

        s3 = writer.dumps(j2, indent=2)

        print('---')
        print(s3)
        print('---')

        assert s3 == EXPECTED2
        j3 = decoder.DECODER(s3)
        assert j2 == j3
Exemplo n.º 2
0
 def test_bytes_json(self):
     expected = writer.dumps('"b', use_bytes=True)
     assert b'"\\"b"' == expected
     assert b'true' == writer.dumps(True, use_bytes=True)
     assert b'[]' == writer.dumps([], use_bytes=True)
     assert b'{}' == writer.dumps({}, use_bytes=True)
     assert b"''" != writer.dumps(b"", use_bytes=True)  # FIX
     assert b'""' != writer.dumps(b"", use_bytes=True)
Exemplo n.º 3
0
    def test_indent3(self):
        items = [1, [2, [3, 4], 5], 6]

        s = writer.dumps(items, indent=2)

        assert s == EXPECTED3
Exemplo n.º 4
0
    def test_indent2(self):
        items = [1]

        s = writer.dumps(items, indent=2)
        assert s == '[\n  1\n]\n'