From 64a75d16f5304d34e1eb00fd308fbc90e0447006 Mon Sep 17 00:00:00 2001 From: Ryan Brost Date: Tue, 25 Jun 2024 15:24:18 -0600 Subject: [PATCH] test(core): added read_only and write_only properties to test_instrument_driver and correspondingly accounted for these properties in auto_test_driver so that they will be handled and tested properly. --- pyscan/drivers/testing/auto_test_driver.py | 19 +++++++-------- .../test_instrument_driver_test_log.txt | 9 +------ .../test_voltage_test_log.txt | 4 +--- .../drivers/testing/test_instrument_driver.py | 24 +++++++++++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/pyscan/drivers/testing/auto_test_driver.py b/pyscan/drivers/testing/auto_test_driver.py index 103ccb18..f6d5bab0 100644 --- a/pyscan/drivers/testing/auto_test_driver.py +++ b/pyscan/drivers/testing/auto_test_driver.py @@ -70,17 +70,17 @@ def validate_blacklist(test_instrument): def save_initial_state(device): saved_settings = [] - print(device.__dict__.keys()) + # print(device.__dict__.keys()) for attribute_name in device.__dict__.keys(): if "_settings" in attribute_name: '''try: name = "_{}".format(device[attribute_name]['name']) val = device[name] except (Exception):''' + if "write_only" in device[attribute_name].keys(): + continue name = "{}".format(device[attribute_name]['name']) val = device[name] - if 'ranges' in device[attribute_name].keys(): - val = tuple(val) saved_settings.append((name, val)) # print(device.__dict__.keys()) @@ -101,6 +101,9 @@ def restore_initial_state(device, saved_settings): restored_settings.append((setter, device[setter])) continue + if 'read_only' in device["_{}_settings".format(setter)].keys(): + continue + if 'ranges' in device["_{}_settings".format(setter)].keys(): val = device["_{}_settings".format(setter)]['return_type'](val) try: @@ -169,11 +172,9 @@ def check_attribute_values(device, attributes, ev): # designed for testing read only properties of any type def check_read_only_property(device, key): name = device[key]['name'] - settings = device[name + '_settings'] - return_type = device + settings = device['_' + name + '_settings'] + return_type = settings['return_type'] - # I'm not sure that this will work. It might be that only the underscore property can be used to access - # the property value. assert type(device[name]) is return_type, "read_only property {} returned type {} not {}".format( name, type(device[name]), return_type) assert type(device["_{}".format(name)]) is return_type, "read_only _property {} returned type {} not {}".format( @@ -182,8 +183,6 @@ def check_read_only_property(device, key): assert 'write_string' not in settings, "read_only property {} has write_string {}".format( name, settings['write_string']) - # I'm not sure that this will fail. If not, it should be that the original value remains the same no matter what - # you try to set it to. for val in BAD_INPUTS: with pytest.raises(Exception): device[name] = val @@ -353,7 +352,6 @@ def check_properties(test_instrument): check_read_only_property(test_instrument, name) elif 'write_only' in keys: write_only_settings.append(name) - continue elif ('values' in keys) and ('indexed_' not in keys) and ('dict_' not in keys): values_counter += 1 # values_idx.append(values_counter) @@ -403,7 +401,6 @@ def check_properties(test_instrument): print("Restored settings are different for the following: ", diff) assert hasattr(test_instrument, '_version'), "The instrument had no attribute _version" - print("The previous instrument version was: ", test_instrument._version) def write_log(device, exception): diff --git a/pyscan/drivers/testing/driver_test_logs/test_instrument_driver_test_log.txt b/pyscan/drivers/testing/driver_test_logs/test_instrument_driver_test_log.txt index 2db2bc7b..304a6a7f 100644 --- a/pyscan/drivers/testing/driver_test_logs/test_instrument_driver_test_log.txt +++ b/pyscan/drivers/testing/driver_test_logs/test_instrument_driver_test_log.txt @@ -1,8 +1 @@ -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:58 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:57 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:57 -Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.3.0 at 2024-05-30 10:39:46 \ No newline at end of file +Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.5.3 at 2024-06-25 15:19:53 \ No newline at end of file diff --git a/pyscan/drivers/testing/driver_test_logs/test_voltage_test_log.txt b/pyscan/drivers/testing/driver_test_logs/test_voltage_test_log.txt index 7f64cd28..86708536 100644 --- a/pyscan/drivers/testing/driver_test_logs/test_voltage_test_log.txt +++ b/pyscan/drivers/testing/driver_test_logs/test_voltage_test_log.txt @@ -1,3 +1 @@ -Passed with test_voltage version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38 -Passed with test_voltage version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:58 -Passed with test_voltage version v0.1.0 tested on pyscan version v0.3.0 at 2024-05-30 10:39:46 \ No newline at end of file +Passed with test_voltage version v0.1.0 tested on pyscan version v0.5.3 at 2024-06-25 14:33:11 \ No newline at end of file diff --git a/pyscan/drivers/testing/test_instrument_driver.py b/pyscan/drivers/testing/test_instrument_driver.py index d3deac10..92621256 100644 --- a/pyscan/drivers/testing/test_instrument_driver.py +++ b/pyscan/drivers/testing/test_instrument_driver.py @@ -24,6 +24,10 @@ class TestInstrumentDriver(InstrumentDriver): for testing indexed_values property dict_values : str for testing dict_values property + read_only : str + for testing read_only porperties + write_only : int + for testing write only properties ''' # tells pytest this is not a test case __test__ = False @@ -41,6 +45,7 @@ def __init__(self, debug=False, instrument=None, *arg, **kwarg): self._range = 0 self._indexed_values = 'A' self._dict_values = 'off' + self._read_only = '0' self._version = "0.1.0" self.update_properties() @@ -61,6 +66,9 @@ def query(self, string): elif string == 'DICT_VALUES?': val = self._dict_values_settings['dict_values'][self._dict_values] return str(val) + elif string == 'READ_ONLY?': + val = str(self._read_only) + return val def write(self, string): if 'FLOAT_VALUES' in string: @@ -127,6 +135,21 @@ def initialize_properties(self): 'dict_values': {'on': 1, 'off': 0, '1': 1, '0': 0}, 'return_type': str }) + + self.add_device_property({ + 'name': 'read_only', + 'query_string': 'READ_ONLY?', + 'values': [0, 1], + 'return_type': str + }) + + self.add_device_property({ + 'name': 'write_only', + 'write_string': 'WRITE_ONLY {}', + 'dict_values': {"0": 0, "1": 1}, + 'return_type': int + }) + with pytest.raises(Exception): self.add_device_property({ 'name': 'bad_values', @@ -144,6 +167,7 @@ def update_properties(self): self.range self.indexed_values self.dict_values + self.read_only @property def version(self):