diff --git a/src/reportengine/tests/test_executor.py b/src/reportengine/tests/test_executor.py index a3c3b7b..925c28a 100644 --- a/src/reportengine/tests/test_executor.py +++ b/src/reportengine/tests/test_executor.py @@ -15,30 +15,34 @@ from reportengine.dag import DAG from reportengine.utils import ChainMap from reportengine import namespaces -from reportengine.resourcebuilder import (ResourceExecutor, CallSpec) +from reportengine.resourcebuilder import ResourceExecutor, CallSpec """ Define some simple functions that will be used as nodes in the DAG. """ + def node_1(param): print("Executing node_1") time.sleep(0.1) return "node_1_result: %s" % param + def node_2_1(node_1_result): print("Executing node_2_1") time.sleep(0.2) - return node_1_result*2 + return node_1_result * 2 + def node_2_2(node_1_result): print("Executing node_2_2") time.sleep(0.2) - return node_1_result*3 + return node_1_result * 3 + def node_3(node_2_1_result, node_2_2_result, param=None): print("executing node_3") - return (node_2_1_result+node_2_2_result)*(param//2) + return (node_2_1_result + node_2_2_result) * (param // 2) class TestResourceExecutor(unittest.TestCase, ResourceExecutor): @@ -57,46 +61,48 @@ def setUp(self): node_3 """ - self.rootns = ChainMap({'param':4, 'inner': {}}) + self.rootns = ChainMap({"param": 4, "inner": {}}) + def nsspec(x, beginning=()): ns = namespaces.resolve(self.rootns, beginning) - default_label = '_default' + str(x) + default_label = "_default" + str(x) namespaces.push_nslevel(ns, default_label) return beginning + (default_label,) self.graph = DAG() - node_1_call = CallSpec(node_1, ('param',), 'node_1_result', - nsspec(node_1)) + node_1_call = CallSpec(node_1, ("param",), "node_1_result", nsspec(node_1)) - node_2_1_call = CallSpec(node_2_1, ('node_1_result',), 'node_2_1_result', - nsspec(node_2_1)) - - node_2_2_call = CallSpec(node_2_2, ('node_1_result',), 'node_2_2_result', - nsspec(node_2_2)) - - node_3_call = CallSpec(node_3, ('node_2_1_result','node_2_2_result','param'), 'node_3_result', - nsspec(node_3)) + node_2_1_call = CallSpec( + node_2_1, ("node_1_result",), "node_2_1_result", nsspec(node_2_1) + ) + node_2_2_call = CallSpec( + node_2_2, ("node_1_result",), "node_2_2_result", nsspec(node_2_2) + ) + node_3_call = CallSpec( + node_3, + ("node_2_1_result", "node_2_2_result", "param"), + "node_3_result", + nsspec(node_3), + ) self.graph.add_node(node_1_call) self.graph.add_node(node_2_1_call, inputs={node_1_call}) self.graph.add_node(node_2_2_call, inputs={node_1_call}) self.graph.add_node(node_3_call, inputs={node_2_1_call, node_2_2_call}) - def _test_ns(self, promise=False): """ Asserts that the namespace contains the expected results. """ - node_3_result = 'node_1_result: 4'*10 + node_3_result = "node_1_result: 4" * 10 namespace = self.rootns if promise: - self.assertEqual(namespace['node_3_result'].result(), node_3_result) + self.assertEqual(namespace["node_3_result"].result(), node_3_result) else: - self.assertEqual(namespace['node_3_result'], node_3_result) - + self.assertEqual(namespace["node_3_result"], node_3_result) def test_seq_execute(self): """ @@ -113,5 +119,6 @@ def test_parallel_execute(self): self.execute_parallel() self._test_ns(promise=True) -if __name__ =='__main__': + +if __name__ == "__main__": unittest.main()