예제 #1
0
파일: test_core.py 프로젝트: suimong/pyungo
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)
예제 #2
0
파일: core.py 프로젝트: ioancw/pyungo
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
파일: test_core.py 프로젝트: suimong/pyungo
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
예제 #6
0
파일: test_core.py 프로젝트: Tosa95/pyungo
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
예제 #7
0
파일: test_core.py 프로젝트: Tosa95/pyungo
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
예제 #8
0
파일: test_core.py 프로젝트: suimong/pyungo
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
예제 #9
0
파일: test_core.py 프로젝트: suimong/pyungo
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)
예제 #10
0
파일: test_core.py 프로젝트: Tosa95/pyungo
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)
예제 #11
0
파일: test_io.py 프로젝트: suimong/pyungo
def test_Output():
    out = Output("a")
    assert out.name == "a"
    out.value = 2
    assert out._value == 2
    assert out.value == 2
예제 #12
0
def test_Output():
    out = Output('a')
    assert out.name == 'a'
    out.value = 2
    assert out._value == 2
    assert out.value == 2