Skip to content

Commit 0447562

Browse files
committedDec 4, 2014
test: add serialization
1 parent 4c7749b commit 0447562

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 

‎test/serialization.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import unittest
2+
import json
3+
from fractions import Fraction
4+
5+
import numpy as np
6+
7+
from artiq.management import pyon
8+
9+
10+
_pyon_test_object = {
11+
(1, 2): [(3, 4.2), (2, )],
12+
Fraction(3, 4): np.linspace(5, 10, 1)
13+
}
14+
15+
16+
class PYON(unittest.TestCase):
17+
def test_encdec(self):
18+
for enc in pyon.encode, lambda x: pyon.encode(x, True):
19+
self.assertEqual(pyon.decode(enc(_pyon_test_object)),
20+
_pyon_test_object)
21+
22+
23+
_json_test_object = {
24+
"a": "b",
25+
"x": [1, 2, {}],
26+
"foo\nbaz\\qux\"": ["bar", 1.2, {"x": "y"}],
27+
"bar": [True, False, None]
28+
}
29+
30+
31+
class JSONPYON(unittest.TestCase):
32+
def test_encdec(self):
33+
for enc in pyon.encode, lambda x: pyon.encode(x, True), json.dumps:
34+
for dec in pyon.decode, json.loads:
35+
self.assertEqual(dec(enc(_json_test_object)),
36+
_json_test_object)

0 commit comments

Comments
 (0)
Please sign in to comment.