Skip to content

Commit

Permalink
pr response, test dict remains unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Apr 10, 2024
1 parent 672695b commit fbfcecf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions EasyReflectometry/parameter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

def get_as_parameter(value: Union[Parameter, Number, None], name, default_dict: dict[str, str]) -> Parameter:
# Should leave the passed dictionary unchanged
default_dict = deepcopy(default_dict)
local_dict = deepcopy(default_dict)
if value is None:
return Parameter(name, **default_dict[name])
return Parameter(name, **local_dict[name])
elif isinstance(value, Number):
del default_dict[name]['value']
return Parameter(name, value, **default_dict[name])
del local_dict[name]['value']
return Parameter(name, value, **local_dict[name])
elif not isinstance(value, Parameter):
raise ValueError(f'{name} must be a Parameter, a number, or None.')
return value
21 changes: 21 additions & 0 deletions tests/test_parameter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,24 @@ def test_get_as_parameter_not_number():
# Then Expected
with pytest.raises(ValueError):
test_parameter = get_as_parameter(test_parameter, 'test_parameter', PARAMETER_DETAILS)


def test_dict_remains_unchanged():
expected_parameter_details = {
'test_parameter': {
'description': 'Test parameter',
'url': 'https://veryrealwebsite.com',
'value': 1.0,
'min': 0,
'max': np.Inf,
'fixed': True,
}
}
# When
test_parameter = 2.0

# Then
test_parameter = get_as_parameter(int(test_parameter), 'test_parameter', PARAMETER_DETAILS)

# Expected
assert_equal(expected_parameter_details['test_parameter'], PARAMETER_DETAILS['test_parameter'])

0 comments on commit fbfcecf

Please sign in to comment.