Skip to content

Commit

Permalink
Merge branch 'dls-controls-param_checks'
Browse files Browse the repository at this point in the history
This is a manual merge of PR #40 due to conflicts with master between
dls-controls and the main odin-detector repo. Fixes issue with
incorrect checking of max metadata field in parameter tree.
  • Loading branch information
timcnicholls committed Oct 15, 2019
2 parents 164170b + 212a25a commit 82be0cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/odin/adapters/parameter_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def set(self, value):

# Raise an error if the parameter has a maximum value specified in metadata and the
# value to set is above this
if "min" in self.metadata and value > self.metadata["max"]:
if "max" in self.metadata and value > self.metadata["max"]:
raise ParameterTreeError(
"{} is above the maximum value {} for {}".format(
value, self.metadata["max"], self.path
Expand Down
12 changes: 11 additions & 1 deletion tests/adapters/test_parameter_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ def __init__(self):
self.intCallableRwParamGet, self.intCallableRwParamSet, self.int_rw_param_metadata
),
'intEnumParam': (0, {"allowed_values": self.int_enum_param_allowed_values}),
'valueParam': (24601,)
'valueParam': (24601,),
'minNoMaxParam': (1, {'min': 0})
}
self.metadata_tree = ParameterTree(self.metadata_tree_dict)

Expand Down Expand Up @@ -758,6 +759,15 @@ def test_value_param_writeable(self, test_tree_metadata):
assert set_param["value"] == new_value
assert set_param["writeable"] == True

def test_rw_param_min_no_max(self, test_tree_metadata):
"""Test that a parameter with a minimum but no maximum works as expected."""
new_value = 2
test_tree_metadata.metadata_tree.set("minNoMaxParam", new_value)
set_param = test_tree_metadata.metadata_tree.get(
"minNoMaxParam", with_metadata=True)["minNoMaxParam"]
assert set_param["value"] == new_value
assert set_param["writeable"] == True

def test_rw_param_below_min_value(self, test_tree_metadata):
"""
Test that attempting to set a value for a RW parameter below the specified minimum
Expand Down

0 comments on commit 82be0cd

Please sign in to comment.