From 409c66e96661ccee9a9e312157517e0b56659bfa Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sat, 4 Jul 2015 21:44:28 -0600 Subject: [PATCH] test: convert lda/tcube/409b to hardware_testbench --- artiq/test/hardware_testbench.py | 15 +++++++++++++++ artiq/test/lda.py | 14 ++++---------- artiq/test/novatech409b.py | 7 ++----- artiq/test/thorlabs_tcube.py | 12 +++--------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/artiq/test/hardware_testbench.py b/artiq/test/hardware_testbench.py index 47d230ad2..e1b206885 100644 --- a/artiq/test/hardware_testbench.py +++ b/artiq/test/hardware_testbench.py @@ -14,6 +14,21 @@ artiq_root = os.getenv("ARTIQ_ROOT") 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") class ExperimentCase(unittest.TestCase): def setUp(self): diff --git a/artiq/test/lda.py b/artiq/test/lda.py index 96a1ab0b1..5231b7964 100644 --- a/artiq/test/lda.py +++ b/artiq/test/lda.py @@ -1,11 +1,8 @@ import unittest -import os from artiq.devices.lda.driver import Lda, Ldasim from artiq.language.units import dB - - -lda_serial = os.getenv("ARTIQ_LDA_SERIAL") +from artiq.test.hardware_testbench import get_from_ddb class GenericLdaTest: @@ -19,16 +16,13 @@ class GenericLdaTest: self.assertEqual(i, self.cont.get_attenuation()) -@unittest.skipUnless(lda_serial, "no hardware") class TestLda(GenericLdaTest, unittest.TestCase): def setUp(self): - product = os.getenv("ARTIQ_LDA_PRODUCT") - self.cont = Lda(serial=lda_serial, product=product) + lda_serial = get_from_ddb("lda", "device") + lda_product = get_from_ddb("lda", "product") + self.cont = Lda(serial=lda_serial, product=lda_product) class TestLdaSim(GenericLdaTest, unittest.TestCase): def setUp(self): self.cont = Ldasim() - -if __name__ == "__main__": - unittest.main() diff --git a/artiq/test/novatech409b.py b/artiq/test/novatech409b.py index 165b81fad..314b1cb19 100644 --- a/artiq/test/novatech409b.py +++ b/artiq/test/novatech409b.py @@ -1,10 +1,7 @@ import unittest -import os from artiq.devices.novatech409b.driver import Novatech409B - - -novatech409b_device = os.getenv("NOVATECH409B_DEVICE") +from artiq.test.hardware_testbench import get_from_ddb class GenericNovatech409BTest: @@ -23,9 +20,9 @@ class GenericNovatech409BTest: self.assertEqual(r[0:23], "00989680 2000 01F5 0000") -@unittest.skipUnless(novatech409b_device, "no hardware") class TestNovatech409B(GenericNovatech409BTest, unittest.TestCase): def setUp(self): + novatech409b_device = get_from_ddb("novatech409b", "device") self.driver = Novatech409B(novatech409b_device) diff --git a/artiq/test/thorlabs_tcube.py b/artiq/test/thorlabs_tcube.py index eb2a18f97..0ecb362e8 100644 --- a/artiq/test/thorlabs_tcube.py +++ b/artiq/test/thorlabs_tcube.py @@ -1,9 +1,9 @@ import unittest -import os import time from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim from artiq.language.units import V +from artiq.test.hardware_testbench import get_from_ddb class GenericTdcTest: @@ -131,12 +131,9 @@ class GenericTpzTest: 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): def setUp(self): + tdc_serial = get_from_ddb("tdc", "device") self.cont = Tdc(serial_dev=tdc_serial) @@ -145,12 +142,9 @@ class TestTdcSim(unittest.TestCase, GenericTdcTest): self.cont = TdcSim() -tpz_serial = os.getenv("ARTIQ_TPZ_SERIAL") - - -@unittest.skipUnless(tpz_serial, "no hardware") class TestTpz(unittest.TestCase, GenericTpzTest): def setUp(self): + tpz_serial = get_from_ddb("tpz", "device") self.cont = Tpz(serial_dev=tpz_serial)