forked from lightwave-lab/lightlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_visa_drivers.py
38 lines (31 loc) · 1.33 KB
/
test_visa_drivers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
''' Tests whether all the visa drivers included in lightlab are properly
coded. All tests should be safe to run locally.'''
import pytest
from mock import patch
from lightlab.equipment import lab_instruments
from lightlab.equipment.lab_instruments import VISAInstrumentDriver, experimental_instruments
import inspect
classes = [
obj
for name, obj in inspect.getmembers(lab_instruments)
if inspect.isclass(obj) and issubclass(obj, VISAInstrumentDriver) and name not in experimental_instruments
]
class OpenError(RuntimeError):
pass
@pytest.mark.parametrize("instrum", classes)
def test_instantiate_instrum(instrum):
''' Instatiates instruments and asserts that .open should not be called
'''
def open_error(self):
raise OpenError("self.open() function being called upon initialization.")
with patch.object(instrum, 'open', open_error):
obj = instrum()
with pytest.raises((RuntimeError, AttributeError)):
obj.open()
from lightlab.equipment.lab_instruments import NI_PCI_6723, ILX_7900B_LS
from lightlab.util.io import ChannelError
def test_instrums_withChannels():
cs = NI_PCI_6723(name='a CS', address=None, useChans=[1, 2])
with pytest.raises(ChannelError):
cs = NI_PCI_6723(name='a CS', address=None, useChans=[50])
ls = ILX_7900B_LS(name='a LS', address=None, useChans=[1, 2])