Skip to content

Commit

Permalink
test(core): added read_only and write_only properties to test_instrum…
Browse files Browse the repository at this point in the history
…ent_driver and correspondingly accounted for these properties in auto_test_driver so that they will be handled and tested properly.
  • Loading branch information
rsbrost committed Jun 25, 2024
1 parent b1601e8 commit 64a75d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
19 changes: 8 additions & 11 deletions pyscan/drivers/testing/auto_test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.5.3 at 2024-06-25 15:19:53
Original file line number Diff line number Diff line change
@@ -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
Passed with test_voltage version v0.1.0 tested on pyscan version v0.5.3 at 2024-06-25 14:33:11
24 changes: 24 additions & 0 deletions pyscan/drivers/testing/test_instrument_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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',
Expand All @@ -144,6 +167,7 @@ def update_properties(self):
self.range
self.indexed_values
self.dict_values
self.read_only

@property
def version(self):
Expand Down

0 comments on commit 64a75d1

Please sign in to comment.