Skip to content

Commit

Permalink
test: add serialization
Browse files Browse the repository at this point in the history
sbourdeauducq committed Dec 4, 2014
1 parent 4c7749b commit 0447562
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/serialization.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0447562

Please sign in to comment.