Commit 22c46e590cd by Julien Salort

Fix unittest

parent a4be2aee417
......@@ -3,7 +3,10 @@
"""
from fluidlab.instruments.drivers import VISADriver
from fluidlab.interfaces import PhysicalInterfaceType, set_default_interface
from fluidlab.interfaces.visa_inter import set_default_pyvisa_backend
from fluidlab.instruments.drivers import Driver
from fluidlab.instruments.features import (
QueryCommand,
......@@ -12,8 +15,11 @@ from fluidlab.instruments.features import (
BoolValue,
)
set_default_interface(PhysicalInterfaceType.Serial, "VISAInterface")
set_default_pyvisa_backend("@sim")
class Device2(VISADriver):
class Device2(Driver):
"""Simple instrument driver
The instrument is defined in pyvisa-sim (as "device 2").
......@@ -48,4 +54,4 @@ Device2._build_class_with_features(
if __name__ == "__main__":
dev = Device2("ASRL2::INSTR", backend="@sim")
dev = Device2("ASRL2::INSTR")
......@@ -8,33 +8,31 @@ from fluidlab.instruments.test.devices_pyvisasim import Device2
class SimpleTestCase(unittest.TestCase):
def test_device2(self):
with stdout_redirected():
with stdout_redirected(), Device2("ASRL2::INSTR") as dev:
dev = Device2("ASRL2::INSTR", backend="@sim")
idn = dev.get_idn()
self.assertEqual(idn, "SCPI,MOCK,VERSION_1.0\n")
idn = dev.get_idn()
self.assertEqual(idn, "SCPI,MOCK,VERSION_1.0\n")
dev.voltage.set(2)
voltage = dev.voltage.get()
self.assertEqual(voltage, 2)
dev.voltage.set(2)
voltage = dev.voltage.get()
self.assertEqual(voltage, 2)
dev.output_enabled.set(True)
oe = dev.output_enabled.get()
self.assertEqual(oe, True)
dev.output_enabled.set(True)
oe = dev.output_enabled.get()
self.assertEqual(oe, True)
# test errors:
with self.assertRaises(ValueError):
dev.voltage.set(7)
# test errors:
with self.assertRaises(ValueError):
dev.voltage.set(7)
with self.assertRaises(ValueError):
dev.output_enabled = True
with self.assertRaises(ValueError):
dev.output_enabled = True
with self.assertRaises(AttributeError):
dev.get("aaaaa")
with self.assertRaises(AttributeError):
dev.get("aaaaa")
with self.assertRaises(ValueError):
dev.get("interface")
with self.assertRaises(ValueError):
dev.get("interface")
if __name__ == "__main__":
......
......@@ -12,8 +12,7 @@ class InstruWithTrigger(IEC60488, Trigger):
class SimpleTestCase(unittest.TestCase):
def test_instr(self):
with stdout_redirected():
instr = InstruWithTrigger()
with stdout_redirected(), InstruWithTrigger() as instr:
# coming from IEC60488
instr.clear_status()
......
......@@ -19,6 +19,11 @@ opened_devices_for_rm = dict() # key: rm, object: device
resource_managers = dict() # key: backend(str), object: rm
def set_default_pyvisa_backend(backend):
global default_visa_backend
default_visa_backend = backend
class VISAInterface(QueryInterface):
def __init__(self, resource_name, backend=None):
super().__init__()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment