Beispiel #1
0
def test_contract_inputs():

    from contracts import ContractNotRespected

    graph = Graph()

    @graph.register(
        inputs=[Input(name='a', contract='int,>0'), 'b'],
        outputs=['c']
    )
    def f_my_function(a, b):
        return a + b

    res = graph.calculate(data={'a': 2, 'b': 3})
    assert res == 5
    res = graph.calculate(data={'a': 2, 'b': 3})
    assert res == 5

    with pytest.raises(ContractNotRespected) as err:
        res = graph.calculate(data={'a': -2, 'b': 3})

    assert "Condition -2 > 0 not respected" in str(err.value)
Beispiel #2
0
def test_get_if_exists_ok():
    inputs = [Input("a"), Input("b"), Input("c")]
    existing = {i.name: i for i in inputs}
    res = get_if_exists(["a", "b", "c", {"d": 3}], existing)
    for i, j in zip(inputs, res):  # skip the dict on purpose
        assert i == j
Beispiel #3
0
def test_get_if_exists_ok():
    inputs = [Input('a'), Input('b'), Input('c')]
    existing = {i.name: i for i in inputs}
    res = get_if_exists(['a', 'b', 'c', {'d': 3}], existing)
    for i, j in zip(inputs, res):  # skip the dict on purpose
        assert i == j
Beispiel #4
0
def test_Input():
    inp = Input(name="a")
    assert inp.name == "a"
    assert inp.value is None
    assert inp.is_arg is False
    assert inp.is_kwarg is False
Beispiel #5
0
def test_Input_kwarg():
    inp = Input.kwarg(name='a')
    assert inp.name == 'a'
    assert inp.value is None
    assert inp.is_arg is False
    assert inp.is_kwarg is True