Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions qcodes/instrument/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,12 @@ def __getstate__(self):
'were trying to use a local instrument (defined with '
'server_name=None) in a background Loop. Local instruments can '
'only be used in Loops with background=False.')

def validate_status(self, verbose=0):
""" Validate the values of all gettable parameters """
for k, p in self.parameters.items():
if p.has_get and p.has_set:
value = p.get()
if verbose:
print('validate_status: param %s: %s' % (k, value))
p.validate(value)
13 changes: 11 additions & 2 deletions qcodes/tests/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def setUpClass(cls):

cls.gates = MockGates(model=cls.model, server_name='')
cls.source = MockSource(model=cls.model, server_name='')
cls.meter = MockMeter(model=cls.model, keep_history=False, server_name='')
cls.meter = MockMeter(
model=cls.model, keep_history=False, server_name='')

def setUp(self):
# reset the model state via the gates function
Expand Down Expand Up @@ -963,6 +964,14 @@ def tearDown(self):
# TODO (giulioungaretti) remove ( does nothing ?)
pass

def test_validate_function(self):
instrument = self.instrument
instrument.validate_status() # test the instrument has valid values

instrument.dac1._save_val(1000) # overrule the validator
with self.assertRaises(Exception):
instrument.validate_status()

def test_attr_access(self):
instrument = self.instrument

Expand All @@ -975,7 +984,7 @@ def test_attr_access(self):
instrument.close()

# make sure we can still print the instrument
s = instrument.__repr__()
_ = instrument.__repr__()

# make sure the gate is removed
self.assertEqual(hasattr(instrument, 'dac1'), False)