def test_provide_inputs_outputs_already_defined(): inputs = [Input("a"), Input("b")] outputs = [Output("c")] graph = Graph(inputs=inputs, outputs=outputs) with pytest.raises(TypeError) as err: @graph.register(inputs=["a", "b"], outputs=[Output("c")]) def f_my_function(a, b): return a + b msg = "You cannot use Input / Output in a Node if already defined" assert msg in str(err.value)
def _process_outputs(self, outputs): for output in outputs: if isinstance(output, Output): new_output = output elif isinstance(output, str): new_output = Output(output) self._outputs.append(new_output)
def _process_outputs(self, outputs): """ converter data passed to Output objects and store them """ for output in outputs: if isinstance(output, Output): new_output = output elif isinstance(output, str): new_output = Output(output) self._outputs.append(new_output)
def _process_outputs(self, outputs): """ converter data passed to Output objects and store them """ if outputs is None: outputs = get_function_return_names(self._fct) for output in outputs: if isinstance(output, Output): new_output = output elif isinstance(output, str): new_output = Output(output) self._outputs.append(new_output)
def test_provide_inputs_outputs(): inputs = [Input("a"), Input("b")] outputs = [Output("c")] graph = Graph(inputs=inputs, outputs=outputs) @graph.register(inputs=["a", "b"], outputs=["c"]) def f_my_function(a, b): return a + b res = graph.calculate(data={"a": 2, "b": 3}) assert res == 5
def test_map(): graph = Graph() @graph.register(inputs=[Input('a', map='q'), Input('b', map='w')], outputs=[Output('c', map='e')]) def f_my_function(a, b): return a + b res = graph.calculate(data={'q': 2, 'w': 3}) assert res == 5 assert graph.data['e'] == 5
def test_provide_inputs_outputs(): inputs = [Input('a'), Input('b')] outputs = [Output('c')] graph = Graph(inputs=inputs, outputs=outputs) @graph.register(inputs=['a', 'b'], outputs=['c']) def f_my_function(a, b): return a + b res = graph.calculate(data={'a': 2, 'b': 3}) assert res == 5
def test_map(): graph = Graph() @graph.register( inputs=[Input("a", map="q"), Input("b", map="w")], outputs=[Output("c", map="e")], ) def f_my_function(a, b): return a + b res = graph.calculate(data={"q": 2, "w": 3}) assert res == 5 assert graph.data["e"] == 5
def test_contract_outputs(): from contracts import ContractNotRespected graph = Graph() @graph.register(inputs=["a", "b"], outputs=[Output("c", contract="int,>0")]) def f_my_function(a, b): return a + b res = graph.calculate(data={"a": 2, "b": 3}) assert res == 5 with pytest.raises(ContractNotRespected) as err: res = graph.calculate(data={"a": -4, "b": 3}) assert "Condition -1 > 0 not respected" in str(err.value)
def test_contract_outputs(): from contracts import ContractNotRespected graph = Graph() @graph.register(inputs=['a', 'b'], outputs=[Output('c', contract='int,>0')]) def f_my_function(a, b): return a + b res = graph.calculate(data={'a': 2, 'b': 3}) assert res == 5 with pytest.raises(ContractNotRespected) as err: res = graph.calculate(data={'a': -4, 'b': 3}) assert "Condition -1 > 0 not respected" in str(err.value)
def test_Output(): out = Output("a") assert out.name == "a" out.value = 2 assert out._value == 2 assert out.value == 2
def test_Output(): out = Output('a') assert out.name == 'a' out.value = 2 assert out._value == 2 assert out.value == 2