diff --git a/bonobo/core/contexts.py b/bonobo/core/contexts.py index d0ed27d..0c0820a 100644 --- a/bonobo/core/contexts.py +++ b/bonobo/core/contexts.py @@ -71,7 +71,7 @@ class PluginExecutionContext: self.alive = False -def iterable(x): +def _iter(x): if isinstance(x, (dict, list, str)): raise TypeError(type(x).__name__) return iter(x) @@ -173,7 +173,7 @@ class ComponentExecutionContext(WithStatistics): # self._exec_time += timer.duration # Put data onto output channels try: - results = iterable(results) + results = _iter(results) except TypeError: if results: self.send(_resolve(results)) diff --git a/tests/core/test_contexts.py b/tests/core/test_contexts.py index e69de29..e2e6179 100644 --- a/tests/core/test_contexts.py +++ b/tests/core/test_contexts.py @@ -0,0 +1,34 @@ +from bonobo import Graph +from bonobo.core.contexts import ExecutionContext + + +def generate_integers(): + yield from range(10) + + +def square(i: int) -> int: + return i**2 + + +def test_empty_execution_context(): + graph = Graph() + + ctx = ExecutionContext(graph) + assert not len(ctx.components) + assert not len(ctx.plugins) + + assert not ctx.running + + +def test_simple_execution_context(): + graph = Graph() + graph.add_chain(generate_integers, square) + + ctx = ExecutionContext(graph) + assert len(ctx.components) == 2 + assert not len(ctx.plugins) + + assert ctx[0].component is generate_integers + assert ctx[1].component is square + + assert not ctx.running