Skip to content

Commit

Permalink
compiler.embedding: add tests for quote serialization.
Browse files Browse the repository at this point in the history
whitequark committed Aug 28, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 37811f6 commit cbd903a
Showing 2 changed files with 52 additions and 7 deletions.
41 changes: 41 additions & 0 deletions artiq/test/coredevice/embedding.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 11 additions & 7 deletions artiq/test/hardware_testbench.py
Original file line number Diff line number Diff line change
@@ -37,20 +37,24 @@ def setUp(self):
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__,
"arguments": kwargs
}
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

0 comments on commit cbd903a

Please sign in to comment.