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
This commit is part of merge request !154. Comments created here will be created in the context of that merge request.
...@@ -281,7 +281,7 @@ class Component(IComponent, Loggable, ABC): ...@@ -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. 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: 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): ...@@ -174,13 +174,20 @@ class ConnectHelper(Loggable):
self._check_rule(rule) self._check_rule(rule)
def _check_rule(self, rule): def _check_rule(self, rule):
if isinstance(rule, FromInput) and rule.name not in self._inputs: if isinstance(rule, FromInput):
raise KeyError( if rule.name not in self._inputs:
f"No input named '{rule.name}' to use in info transfer rule." 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( elif isinstance(rule, FromOutput):
f"No output named '{rule.name}' to use in info transfer rule." 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 @property
......
...@@ -358,3 +358,11 @@ class TestConnectHelper(unittest.TestCase): ...@@ -358,3 +358,11 @@ class TestConnectHelper(unittest.TestCase):
outputs, outputs,
in_info_rules={"In1": [FromOutput("OutX", "grid")]}, 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