test: convert lda/tcube/409b to hardware_testbench

This commit is contained in:
Robert Jördens 2015-07-04 21:44:28 -06:00
parent 959ba99f1c
commit 409c66e966
4 changed files with 24 additions and 24 deletions

View File

@ -14,6 +14,21 @@ artiq_root = os.getenv("ARTIQ_ROOT")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def get_from_ddb(*path, default="skip"):
if not artiq_root:
raise unittest.SkipTest("no ARTIQ_ROOT")
v = FlatFileDB(os.path.join(artiq_root, "ddb.pyon")).data
try:
for p in path:
v = v.read[v]
return v.read
except KeyError:
if default == "skip":
raise unittest.SkipTest("ddb path {} not found".format(path))
else:
return default
@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT") @unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")
class ExperimentCase(unittest.TestCase): class ExperimentCase(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@ -1,11 +1,8 @@
import unittest import unittest
import os
from artiq.devices.lda.driver import Lda, Ldasim from artiq.devices.lda.driver import Lda, Ldasim
from artiq.language.units import dB from artiq.language.units import dB
from artiq.test.hardware_testbench import get_from_ddb
lda_serial = os.getenv("ARTIQ_LDA_SERIAL")
class GenericLdaTest: class GenericLdaTest:
@ -19,16 +16,13 @@ class GenericLdaTest:
self.assertEqual(i, self.cont.get_attenuation()) self.assertEqual(i, self.cont.get_attenuation())
@unittest.skipUnless(lda_serial, "no hardware")
class TestLda(GenericLdaTest, unittest.TestCase): class TestLda(GenericLdaTest, unittest.TestCase):
def setUp(self): def setUp(self):
product = os.getenv("ARTIQ_LDA_PRODUCT") lda_serial = get_from_ddb("lda", "device")
self.cont = Lda(serial=lda_serial, product=product) lda_product = get_from_ddb("lda", "product")
self.cont = Lda(serial=lda_serial, product=lda_product)
class TestLdaSim(GenericLdaTest, unittest.TestCase): class TestLdaSim(GenericLdaTest, unittest.TestCase):
def setUp(self): def setUp(self):
self.cont = Ldasim() self.cont = Ldasim()
if __name__ == "__main__":
unittest.main()

View File

@ -1,10 +1,7 @@
import unittest import unittest
import os
from artiq.devices.novatech409b.driver import Novatech409B from artiq.devices.novatech409b.driver import Novatech409B
from artiq.test.hardware_testbench import get_from_ddb
novatech409b_device = os.getenv("NOVATECH409B_DEVICE")
class GenericNovatech409BTest: class GenericNovatech409BTest:
@ -23,9 +20,9 @@ class GenericNovatech409BTest:
self.assertEqual(r[0:23], "00989680 2000 01F5 0000") self.assertEqual(r[0:23], "00989680 2000 01F5 0000")
@unittest.skipUnless(novatech409b_device, "no hardware")
class TestNovatech409B(GenericNovatech409BTest, unittest.TestCase): class TestNovatech409B(GenericNovatech409BTest, unittest.TestCase):
def setUp(self): def setUp(self):
novatech409b_device = get_from_ddb("novatech409b", "device")
self.driver = Novatech409B(novatech409b_device) self.driver = Novatech409B(novatech409b_device)

View File

@ -1,9 +1,9 @@
import unittest import unittest
import os
import time import time
from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim
from artiq.language.units import V from artiq.language.units import V
from artiq.test.hardware_testbench import get_from_ddb
class GenericTdcTest: class GenericTdcTest:
@ -131,12 +131,9 @@ class GenericTpzTest:
self.assertEqual(test_vector, self.cont.get_tpz_io_settings()) self.assertEqual(test_vector, self.cont.get_tpz_io_settings())
tdc_serial = os.getenv("ARTIQ_TDC_SERIAL")
@unittest.skipUnless(tdc_serial, "no hardware")
class TestTdc(unittest.TestCase, GenericTdcTest): class TestTdc(unittest.TestCase, GenericTdcTest):
def setUp(self): def setUp(self):
tdc_serial = get_from_ddb("tdc", "device")
self.cont = Tdc(serial_dev=tdc_serial) self.cont = Tdc(serial_dev=tdc_serial)
@ -145,12 +142,9 @@ class TestTdcSim(unittest.TestCase, GenericTdcTest):
self.cont = TdcSim() self.cont = TdcSim()
tpz_serial = os.getenv("ARTIQ_TPZ_SERIAL")
@unittest.skipUnless(tpz_serial, "no hardware")
class TestTpz(unittest.TestCase, GenericTpzTest): class TestTpz(unittest.TestCase, GenericTpzTest):
def setUp(self): def setUp(self):
tpz_serial = get_from_ddb("tpz", "device")
self.cont = Tpz(serial_dev=tpz_serial) self.cont = Tpz(serial_dev=tpz_serial)