summaryrefslogtreecommitdiff
path: root/reconfigure/tests/parsers/jsonparser_tests.py
blob: c385763204b9595d2ac3d074a18f03e40601497a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
from reconfigure.tests.parsers.base_test import BaseParserTest
from reconfigure.parsers import JsonParser
from reconfigure.nodes import *


class JsonParserTest (BaseParserTest):
    parser = JsonParser()
    source = """{
    "p2": 123,
    "s1": {
        "s1p1": "qwerty"
    }
}
"""

    parsed = RootNode(None,
        PropertyNode('p2',  123),
        Node('s1',
            PropertyNode('s1p1',  'qwerty'),
        ),
    )

    def test_stringify(self):
        unparsed = self.parser.stringify(self.__class__.parsed)
        a, b = self.stringified, unparsed
        if json.loads(a) != json.loads(b):
            print('SOURCE: %s\n\nGENERATED: %s' % (a, b))
            self.assertEquals(a, b)

del BaseParserTest