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
|
from .compat import unittest
import json
import ucl
_ucl_inp = '''
param = value;
section {
param = value;
param1 = value1;
flag = true;
number = 10k;
time = 0.2s;
string = "something";
subsection {
host = {
host = "hostname";
port = 900;
}
host = {
host = "hostname";
port = 901;
}
}
}
'''
_json_res = {
'param': 'value',
'section': {
'param': 'value',
'param1': 'value1',
'flag': True,
'number': 10000,
'time': '0.2s',
'string': 'something',
'subsection': {
'host': [
{
'host': 'hostname',
'port': 900,
},
{
'host': 'hostname',
'port': 901,
}
]
}
}
}
class TestExample(unittest.TestCase):
def test_example(self):
# load in sample UCL
u = ucl.load(_ucl_inp)
# Output and read back the JSON
uj = json.loads(json.dumps(u))
self.assertEqual(uj, _json_res)
|