diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:48:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:48:59 +0000 |
commit | c484829272cd13a738e35412498e12f2c9a194ac (patch) | |
tree | a1f5ec09629ee895bd3963fa8820b45f2f4c574b /test/python/test_json.py | |
parent | Initial commit. (diff) | |
download | liborcus-f5bf3877c7cf3538ca1337452cf57cc99b0ace0e.tar.xz liborcus-f5bf3877c7cf3538ca1337452cf57cc99b0ace0e.zip |
Adding upstream version 0.19.2.upstream/0.19.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/python/test_json.py')
-rwxr-xr-x | test/python/test_json.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/python/test_json.py b/test/python/test_json.py new file mode 100755 index 0000000..2fde74c --- /dev/null +++ b/test/python/test_json.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +######################################################################## +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +######################################################################## + +import unittest +from orcus import json + + +class JsonTest(unittest.TestCase): + + def test_loads(self): + s = '[1,2,3,"foo",[4,5,6], {"a": 12.3, "b": 34.4, "c": [true, false, null]}]' + o = json.loads(s) + self.assertTrue(isinstance(o, list)) + self.assertEqual(len(o), 6) + self.assertEqual(o[0], 1) + self.assertEqual(o[1], 2) + self.assertEqual(o[2], 3) + self.assertEqual(o[3], "foo") + + self.assertTrue(isinstance(o[4], list)) + self.assertEqual(o[4][0], 4) + self.assertEqual(o[4][1], 5) + self.assertEqual(o[4][2], 6) + + d = o[5] + self.assertTrue(isinstance(d, dict)) + self.assertEqual(len(d), 3) + self.assertEqual(d["a"], 12.3) + self.assertEqual(d["b"], 34.4) + + l = d["c"] + self.assertEqual(len(l), 3) + self.assertEqual(l[0], True) + self.assertEqual(l[1], False) + self.assertEqual(l[2], None) + + +if __name__ == '__main__': + unittest.main() |