diff options
Diffstat (limited to 'python/tests')
| -rw-r--r-- | python/tests/test_example.py | 59 | ||||
| -rw-r--r-- | python/tests/test_load.py | 17 |
2 files changed, 75 insertions, 1 deletions
diff --git a/python/tests/test_example.py b/python/tests/test_example.py new file mode 100644 index 000000000000..f0785531f4e2 --- /dev/null +++ b/python/tests/test_example.py @@ -0,0 +1,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) diff --git a/python/tests/test_load.py b/python/tests/test_load.py index 786587a67f3d..73d43188f3d5 100644 --- a/python/tests/test_load.py +++ b/python/tests/test_load.py @@ -71,7 +71,22 @@ class LoadTest(unittest.TestCase): self.assertEqual(ucl.load("{/*1*/}"), {}) def test_1_in(self): - valid = { 'key1': 'value' } + valid = { + 'key1': [ + 'value', + 'value2', + 'value;', + 1.0, + -0xdeadbeef, + '0xdeadbeef.1', + '0xreadbeef', + -1e-10, + 1, + True, + False, + True, + ] + } with open("../tests/basic/1.in", "r") as in1: self.assertEqual(ucl.load(in1.read()), valid) |
