1from .compat import unittest 2import json 3import ucl 4 5_ucl_inp = ''' 6param = value; 7section { 8 param = value; 9 param1 = value1; 10 flag = true; 11 number = 10k; 12 time = 0.2s; 13 string = "something"; 14 subsection { 15 host = { 16 host = "hostname"; 17 port = 900; 18 } 19 host = { 20 host = "hostname"; 21 port = 901; 22 } 23 } 24} 25''' 26 27_json_res = { 28 'param': 'value', 29 'section': { 30 'param': 'value', 31 'param1': 'value1', 32 'flag': True, 33 'number': 10000, 34 'time': '0.2s', 35 'string': 'something', 36 'subsection': { 37 'host': [ 38 { 39 'host': 'hostname', 40 'port': 900, 41 }, 42 { 43 'host': 'hostname', 44 'port': 901, 45 } 46 ] 47 } 48 } 49} 50 51class TestExample(unittest.TestCase): 52 def test_example(self): 53 # load in sample UCL 54 u = ucl.load(_ucl_inp) 55 56 # Output and read back the JSON 57 uj = json.loads(json.dumps(u)) 58 59 self.assertEqual(uj, _json_res) 60