Skip to content
Snippets Groups Projects
Commit 6f3b8395 authored by Martin Lange's avatar Martin Lange
Browse files

add a check for rule types

parent 4233e807
No related branches found
No related tags found
1 merge request!154Auto-transfer infos
......@@ -281,7 +281,7 @@ class Component(IComponent, Loggable, ABC):
}
)
The :class:`.Info` object for output ``Out`` will be crated and pushed automatically in :meth:`.try_connect`
The :class:`.Info` object for output ``Out`` will be created and pushed automatically in :meth:`.try_connect`
as soon as the metadata for ``In`` becomes available.
Here, the metadata of an output is composed from the metadata of two inputs and a user-defined value:
......
......@@ -174,13 +174,20 @@ class ConnectHelper(Loggable):
self._check_rule(rule)
def _check_rule(self, rule):
if isinstance(rule, FromInput) and rule.name not in self._inputs:
raise KeyError(
f"No input named '{rule.name}' to use in info transfer rule."
)
if isinstance(rule, FromOutput) and rule.name not in self._outputs:
raise KeyError(
f"No output named '{rule.name}' to use in info transfer rule."
if isinstance(rule, FromInput):
if rule.name not in self._inputs:
raise KeyError(
f"No input named '{rule.name}' to use in info transfer rule."
)
elif isinstance(rule, FromOutput):
if rule.name not in self._outputs:
raise KeyError(
f"No output named '{rule.name}' to use in info transfer rule."
)
elif not isinstance(rule, FromValue):
raise TypeError(
f"Rules must be one of the types FromInput, FromOutput or FromValue. "
f"Got '{rule.__class__.__name__}'."
)
@property
......
......@@ -358,3 +358,11 @@ class TestConnectHelper(unittest.TestCase):
outputs,
in_info_rules={"In1": [FromOutput("OutX", "grid")]},
)
with self.assertRaises(TypeError):
_connector: ConnectHelper = ConnectHelper(
"TestLogger",
inputs,
outputs,
in_info_rules={"In1": [0]},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment