From 3066d86d75b3249b6a7d1ea52b5668e68f43762d Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 30 Sep 2016 11:20:35 +0200 Subject: [PATCH 1/3] add validate_status function and basic test --- qcodes/instrument/base.py | 9 +++++++++ qcodes/tests/test_instrument.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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..fb9e38035cc7 100644 --- a/qcodes/tests/test_instrument.py +++ b/qcodes/tests/test_instrument.py @@ -963,6 +963,17 @@ def tearDown(self): # TODO (giulioungaretti) remove ( does nothing ?) pass + def validate_function(self): + instrument = self.instrument + instrument.validate_status() + instrument.dac1._save_val(1000) # overrule the validator + try: + instrument.validate_status() + except: + pass + else: + raise Exception('validate_status did not function') + def test_attr_access(self): instrument = self.instrument @@ -975,7 +986,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) From d9fe662068adaebd171c885686f1b48f9509ffcc Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 30 Sep 2016 11:21:32 +0200 Subject: [PATCH 2/3] autopep --- qcodes/tests/test_instrument.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/tests/test_instrument.py b/qcodes/tests/test_instrument.py index fb9e38035cc7..d258308576a5 100644 --- a/qcodes/tests/test_instrument.py +++ b/qcodes/tests/test_instrument.py @@ -966,14 +966,14 @@ def tearDown(self): def validate_function(self): instrument = self.instrument instrument.validate_status() - instrument.dac1._save_val(1000) # overrule the validator + instrument.dac1._save_val(1000) # overrule the validator try: instrument.validate_status() except: pass else: raise Exception('validate_status did not function') - + def test_attr_access(self): instrument = self.instrument From 3b0a34f5d19ea015ea02e9eca28ccb8938cacdcd Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 21 Oct 2016 13:31:44 +0200 Subject: [PATCH 3/3] rename test function; use self.assetRaises in test --- qcodes/tests/test_instrument.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qcodes/tests/test_instrument.py b/qcodes/tests/test_instrument.py index d258308576a5..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,16 +964,13 @@ def tearDown(self): # TODO (giulioungaretti) remove ( does nothing ?) pass - def validate_function(self): + def test_validate_function(self): instrument = self.instrument - instrument.validate_status() + instrument.validate_status() # test the instrument has valid values + instrument.dac1._save_val(1000) # overrule the validator - try: + with self.assertRaises(Exception): instrument.validate_status() - except: - pass - else: - raise Exception('validate_status did not function') def test_attr_access(self): instrument = self.instrument