Skip to content
Snippets Groups Projects
Commit 837846d4 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

TST: Add unit tests for handle_value with units

parent a8c7279d
No related branches found
No related tags found
2 merge requests!198REL: Release 0.10.0,!187F unit
......@@ -169,13 +169,19 @@ Parameters
----------
value: Union[dict, str, list]
- If *str*, the value to be interpreted. E.g. "4", "hello" or "$a" etc.
- If *str*, the value to be interpreted. E.g. "4", "hello" or "$a"
etc. No unit is set and collection mode is determined from the
first character:
- '+' corresponds to "list"
- '*' corresponds to "multiproperty"
- everything else is "single"
- If *dict*, it must have a ``value`` key and may ``unit``, and
``collection_mode``. The returned tuple is directly created from
the corresponding values whereby unit defaults to None and
collection_mode defaults to "single".
- If *list*, each element is checked for replacement and the resulting list will be used
as (list) value for the property
the corresponding values if they are given; ``unit`` defaults to
None and ``collection_mode`` is determined from ``value`` as
explained for the str case above.
- If *list*, each element is checked for replacement and the
resulting list will be used as (list) value for the property
Returns
-------
......@@ -197,7 +203,7 @@ out: tuple
raise NotImplementedError(f"This definition has no \"value\": {value}")
propvalue = value["value"]
if "unit" in value:
propunit = value["unit"]
propunit = replace_variables(value["unit"], values)
# can be "single", "list" or "multiproperty"
if "collection_mode" in value:
collection_mode = value["collection_mode"]
......@@ -237,8 +243,6 @@ out: tuple
return (propvalue, propunit, collection_mode)
propvalue = replace_variables(propvalue, values)
if propunit:
propunit = replace_variables(propunit, values)
return (propvalue, propunit, collection_mode)
......
......@@ -384,9 +384,13 @@ def test_variable_replacement():
# Unit specified in the same way as value:
assert handle_value({"value": 5, "unit": "m"}, values) == (5, "m", "single")
assert handle_value({"value": 5, "unit": "${my_unit}"}, values) == (5, "m", "single")
assert handle_value({"value": "+5", "unit": "${my_unit}"}, values) == ("5", "m", "list")
assert handle_value({"value": "*5", "unit": "${my_unit}"}, values) == ("5", "m", "multiproperty")
assert handle_value(["a", "b"], values) == (["a", "b"], None, "single")
assert handle_value(["$a", "$b"], values) == ([4, "68"], None, "single")
assert handle_value({"value": ["$a", "$a"], "unit": "${my_unit}"}, values) == ([4, 4], "m", "single")
def test_apply_transformers(converter_registry):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment