-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_jsonod.py
105 lines (81 loc) · 2.32 KB
/
test_jsonod.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import pytest
from pprint import pprint
from objdictgen import Node
from objdictgen.jsonod import generate_jsonc, generate_node, remove_jsonc
from .test_odcompare import shave_equal
def test_jsonod_remove_jsonc():
""" Test that the remove_jsonc function works as expected. """
out = remove_jsonc("""{
"a": "abc", // remove
"b": 42
}""")
assert out == """{
"a": "abc",
"b": 42
}"""
# This was a bug where there quoted string made jsonc parsing fail
out = remove_jsonc("""{
"a": "a\\"bc", // remove
"b": 42
}""")
assert out == """{
"a": "a\\"bc",
"b": 42
}"""
out = remove_jsonc("""{
"a": "a\\"bc", /* remove it */ "c": 42,
"b": 42
}""")
assert out == """{
"a": "a\\"bc","c": 42,
"b": 42
}"""
out = remove_jsonc("""{
"a": "a'bc", // remove
"b": 42
}""")
assert out == """{
"a": "a'bc",
"b": 42
}"""
def test_jsonod_roundtrip(odjsoneds):
""" Test that the file can be exported to json and that the loaded file
is equal to the first.
"""
od = odjsoneds
m1 = Node.LoadFile(od)
out = generate_jsonc(m1, compact=False, sort=False, internal=False, validate=True)
m2 = generate_node(out)
a, b = shave_equal(m1, m2, ignore=["IndexOrder", "DefaultStringSize"])
try:
# pprint(out)
pprint(a)
pprint(b)
# pprint(a.keys())
# pprint(b.keys())
# pprint(a.keys() == b.keys())
# pprint(a["UserMapping"][8193])
# pprint(b["UserMapping"][8193])
except KeyError:
pass
assert a == b
def test_jsonod_roundtrip_compact(odjsoneds):
""" Test that the file can be exported to json and that the loaded file
is equal to the first.
"""
od = odjsoneds
m1 = Node.LoadFile(od)
out = generate_jsonc(m1, compact=True, sort=False, internal=False, validate=True)
m2 = generate_node(out)
a, b = shave_equal(m1, m2, ignore=["IndexOrder", "DefaultStringSize"])
assert a == b
def test_jsonod_roundtrip_internal(odjsoneds):
""" Test that the file can be exported to json and that the loaded file
is equal to the first.
"""
od = odjsoneds
m1 = Node.LoadFile(od)
out = generate_jsonc(m1, compact=False, sort=False, internal=True, validate=True)
m2 = generate_node(out)
a, b = shave_equal(m1, m2, ignore=["IndexOrder", "DefaultStringSize"])
assert a == b