compiler.embedding: add tests for quote serialization.

This commit is contained in:
whitequark 2015-08-28 05:24:57 -05:00
parent 37811f690b
commit cbd903a9dc
2 changed files with 52 additions and 7 deletions

View File

@ -0,0 +1,41 @@
from artiq.language import *
from artiq.test.hardware_testbench import ExperimentCase
class Roundtrip(EnvExperiment):
def build(self):
self.attr_device("core")
@kernel
def roundtrip(self, obj, fn):
fn(obj)
class RoundtripTest(ExperimentCase):
def assertRoundtrip(self, obj):
exp = self.create(Roundtrip)
def callback(objcopy) -> TNone:
self.assertEqual(obj, objcopy)
exp.roundtrip(obj, callback)
def test_None(self):
self.assertRoundtrip(None)
def test_bool(self):
self.assertRoundtrip(True)
self.assertRoundtrip(False)
def test_int(self):
self.assertRoundtrip(42)
self.assertRoundtrip(int(42, width=64))
def test_float(self):
self.assertRoundtrip(42.0)
def test_str(self):
self.assertRoundtrip("foo")
def test_list(self):
self.assertRoundtrip([10])
def test_object(self):
obj = object()
self.assertRoundtrip(obj)

View File

@ -37,7 +37,16 @@ class ExperimentCase(unittest.TestCase):
self.pdb = FlatFileDB(os.path.join(artiq_root, "pdb.pyon"))
self.rdb = ResultDB()
def execute(self, cls, **kwargs):
def create(self, cls, **kwargs):
try:
exp = cls(self.dmgr, self.pdb, self.rdb, **kwargs)
exp.prepare()
return exp
except KeyError as e:
# skip if ddb does not match requirements
raise unittest.SkipTest(*e.args)
def execute(self, cls, *args, **kwargs):
expid = {
"file": sys.modules[cls.__module__].__file__,
"class_name": cls.__name__,
@ -45,12 +54,7 @@ class ExperimentCase(unittest.TestCase):
}
self.dmgr.virtual_devices["scheduler"].expid = expid
try:
try:
exp = cls(self.dmgr, self.pdb, self.rdb, **kwargs)
except KeyError as e:
# skip if ddb does not match requirements
raise unittest.SkipTest(*e.args)
exp.prepare()
exp = self.create(cls, **kwargs)
exp.run()
exp.analyze()
return exp