diff --git a/qcodes/instrument/base.py b/qcodes/instrument/base.py index cb3ca105dfab..e049d384097a 100644 --- a/qcodes/instrument/base.py +++ b/qcodes/instrument/base.py @@ -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) diff --git a/qcodes/tests/test_instrument.py b/qcodes/tests/test_instrument.py index 500330743209..60b0fa3a9c62 100644 --- a/qcodes/tests/test_instrument.py +++ b/qcodes/tests/test_instrument.py @@ -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 @@ -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 @@ -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)