예제 #1
0
    def test_tuple_to_array(self):
        json = (1, 2, 3)

        assert_equals(pyjson.stringify(json), "[1, 2, 3]")

        json = (1, (1, 2), ())

        assert_equals(pyjson.stringify(json), "[1, [1, 2], []]")
예제 #2
0
    def test_special_chars(self):
        json = ["a\nb\t"]
        assert_equals(pyjson.stringify(json),
            '["a\\nb\\t"]')

        json = ['a"bc"']
        assert_equals(pyjson.stringify(json),
            '''["a\\"bc\\""]''')

        json = ['a\"bc\"']
        assert_equals(pyjson.stringify(json),
            '''["a\\\"bc\\\""]''')

        assert_equals(pyjson.stringify([u"àbcdêfghígklmñopqrstu"]),
            '["\\u00e0bcd\\u00eafgh\\u00edgklm\\u00f1opqrstu"]')
예제 #3
0
    def test_complex_json(self):
        my_data = {
            "my_array": [[0, 0], [1, 2]],
            "is_something": True,
            "this_is": None,
            "dict": {
                "name": "pedrochaves",
                "another_list": ["my_string"]
            }
        }

        json = pyjson.stringify(my_data)

        assert_in('"my_array": [[0, 0], [1, 2]]', json)
        assert_in('"is_something": true', json)
        assert_in('"this_is": null', json)
        assert_in('"dict": {', json)
예제 #4
0
    def test_simple_dict(self):
        json = pyjson.stringify({
            "string": "value",
            "number": 1,
            "float": 2.5,
            "nullkey": None,
            "boolt": True,
            "boolf": False
        })

        assert_equals(json[0], "{")
        assert_equals(json[-1], "}")
        assert_in('"string": "value"', json)
        assert_in('"boolf": false', json)
        assert_in('"number": 1', json)
        assert_in('"boolt": true', json)
        assert_in('"nullkey": null', json)
        assert_in('"float": 2.5', json)
        assert_equals(json.count(","), 5)
예제 #5
0
    def test_list_within_list(self):
        json = [[1, 2, 3], [4, 5, 6]]

        assert_equals(pyjson.stringify(json), '[[1, 2, 3], [4, 5, 6]]')
예제 #6
0
    def test_mixed_list(self):
        json = [None, "abc", 1]

        assert_equals(pyjson.stringify(json), '[null, "abc", 1]')
예제 #7
0
    def test_true_false_null(self):
        json = [True, False, None]

        assert_equals(pyjson.stringify(json),
            "[true, false, null]")
예제 #8
0
    def test_simple_string_list(self):
        json = ["str1", "2", "yeah"]

        assert_equals(pyjson.stringify(json),
            '["str1", "2", "yeah"]')
예제 #9
0
    def test_number_list(self):
        json = [1, 2, 3, 2.5, 10e1]

        assert_equals(pyjson.stringify(json),
            "[1, 2, 3, 2.5, 100.0]")
예제 #10
0
    def test_empty_list(self):
        json = []

        assert_equals(pyjson.stringify(json), "[]")