From 044756287ff41b7e71be5e38956cc68e494ee058 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 4 Dec 2014 17:52:22 +0800 Subject: [PATCH] test: add serialization --- test/serialization.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/serialization.py diff --git a/test/serialization.py b/test/serialization.py new file mode 100644 index 000000000..542c20ded --- /dev/null +++ b/test/serialization.py @@ -0,0 +1,36 @@ +import unittest +import json +from fractions import Fraction + +import numpy as np + +from artiq.management import pyon + + +_pyon_test_object = { + (1, 2): [(3, 4.2), (2, )], + Fraction(3, 4): np.linspace(5, 10, 1) +} + + +class PYON(unittest.TestCase): + def test_encdec(self): + for enc in pyon.encode, lambda x: pyon.encode(x, True): + self.assertEqual(pyon.decode(enc(_pyon_test_object)), + _pyon_test_object) + + +_json_test_object = { + "a": "b", + "x": [1, 2, {}], + "foo\nbaz\\qux\"": ["bar", 1.2, {"x": "y"}], + "bar": [True, False, None] +} + + +class JSONPYON(unittest.TestCase): + def test_encdec(self): + for enc in pyon.encode, lambda x: pyon.encode(x, True), json.dumps: + for dec in pyon.decode, json.loads: + self.assertEqual(dec(enc(_json_test_object)), + _json_test_object)