Ejemplo n.º 1
0
def test_basic_assertion():
    equals_check_node = build_int_equals_check(1, 2, "{} is equal to {}")
    equals_check_true_node = build_int_equals_check(2, 2, "{} is equal to {}")

    test_sequence_node = sequence_node()
    test_sequence_node.connect_flow(equals_check_node)
    test_sequence_node.connect_flow(equals_check_true_node)

    test_sequence_node.trigger()

    assert not equals_check_node.result()["out"]["result"]
    assert equals_check_node.result()["out"]["message"] == "1 is equal to 2"
    assert equals_check_true_node.result()["out"]["result"]
    assert equals_check_true_node.result(
    )["out"]["message"] == "2 is equal to 2"
Ejemplo n.º 2
0
def test_http_checker():
    http_200_node = http_test_node()
    http_200_node.connect_input(code=200)
    http_201_node = http_test_node()
    http_201_node.connect_input(code=201)
    http_check = check_http_code(http_200_node, 200)
    http_check_false = check_http_code(http_201_node, 204)

    test_sequence_node = sequence_node()
    test_sequence_node.connect_flow(http_check)
    test_sequence_node.connect_flow(http_check_false)

    test_sequence_node.trigger()

    assert http_check.result()["out"]["result"]
    assert not http_check_false.result()["out"]["result"]
Ejemplo n.º 3
0
def test_and_node():
    true = true_node()
    false = false_node()
    and_check_false = and_node()
    and_check_false.connect_input(a=true)
    and_check_false.connect_input(b=false)
    and_check_true = and_node()
    and_check_true.connect_input(a=true)
    and_check_true.connect_input(b=true)

    test_sequence_node = sequence_node()
    test_sequence_node.connect_flow(and_check_false)
    test_sequence_node.connect_flow(and_check_true)

    test_sequence_node.trigger()

    assert not and_check_false["out"].get()
    assert and_check_true["out"].get()
Ejemplo n.º 4
0
def test_or_node():
    true = true_node()
    false = false_node()
    or_check_false = or_node()
    or_check_false.connect_input(a=false)
    or_check_false.connect_input(b=false)
    or_check_true = or_node()
    or_check_true.connect_input(a=false)
    or_check_true.connect_input(b=true)

    test_sequence_node = sequence_node()
    test_sequence_node.connect_flow(or_check_false)
    test_sequence_node.connect_flow(or_check_true)

    test_sequence_node.trigger()

    assert not or_check_false["out"].get()
    assert or_check_true["out"].get()
Ejemplo n.º 5
0
def test_list_check():
    input_list = [{"key": "a"}, {"key": "b"}, {"key": "c"}]
    list_check_node = build_list_check(input_list, "key", "b")
    list_check_false_node = build_list_check(input_list, "key", "d")

    test_sequence_node = sequence_node()
    test_sequence_node.connect_flow(list_check_node)
    test_sequence_node.connect_flow(list_check_false_node)

    test_sequence_node.trigger()

    assert list_check_node.result()["out"]["result"]
    assert list_check_node.result()["out"]["message"] == "Does key:b appear in " \
                                                         "[{'key': 'a'}, {'key': 'b'}," \
                                                         " {'key': 'c'}]"
    assert not list_check_false_node.result()["out"]["result"]
    assert list_check_false_node.result()["out"]["message"] == "Does key:d appear in " \
                                                               "[{'key': 'a'}, {'key': 'b'}," \
                                                               " {'key': 'c'}]"
Ejemplo n.º 6
0
def test_false_report(result_bool):
    equals_node_true = build_int_equals_check(2, 2, "Does {} equal {}")
    other_int = 2 if result_bool else 1
    other_equals_node = build_int_equals_check(2, other_int,
                                               "Does {} equal {}")
    equality_report_node = report_node()
    equality_report_node.connect_input(equals_node_true, other_equals_node)

    test_sequence_node = sequence_node()
    test_sequence_node.connect_flow(equals_node_true)
    test_sequence_node.connect_flow(other_equals_node)
    test_sequence_node.connect_flow(equality_report_node)

    test_sequence_node.trigger()

    assert result_bool == equality_report_node.result()["passed"]
    assert "Does 2 equal 2: True" in equality_report_node.result()["report"]
    assert f"""Does 2 equal {other_int}: {result_bool}""" in equality_report_node.result(
    )["report"]
def test_static_analysis():
    sequence = sequence_node()

    with sequence.step("test1") as first_step:
        first_step.dummy = should_be_autotrigger_node()
        first_step.dummy2 = takes_single_input_node()
        first_step.dummy_with_bad_name_node = takes_single_input_node()
        first_step.dummy_with_non_connected_input = takes_single_input_node()

        first_step.dummy2.connect_input(a=first_step.dummy)
        first_step.dummy2.connect_flow(first_step.dummy_with_bad_name_node)
        first_step.dummy2.connect_flow(first_step.dummy_with_non_connected_input)

        first_step.dummy3 = should_be_autotrigger_node()
        first_step.dummy2.connect_flow(first_step.dummy3)
        first_step.dummy_with_bad_name_node.connect_input(a=first_step.dummy3)

        first_step << first_step.dummy2

    f = io.StringIO()
    with redirect_stdout(f):
        sequence.trigger()
    stdout = f.getvalue().split("\n")
    assert (
        "[WARNING] Node test.NodeThatShouldBeAutotriggerable(test1.dummy)"
        + " is never triggered nor autotriggerable (needed by "
        + "test.NodeThatTakesSingleInput(test1.dummy2))"
    ) in stdout
    assert (
        "[WARNING] Node 'test.NodeThatTakesSingleInput(test1.dummy_with_non_connected_input)'"
        " has empty NodeInput 'Input[a](accepts=<class 'int'>, "
        "bind=None, hidden=False, optional=False, value=None)'"
    ) in stdout
    assert (
        "[WARNING] A Node instance shouldn't end with _node (on test1.dummy_with_bad_name_node)"
        in stdout
    )
Ejemplo n.º 8
0
from pineapple_nodes.nodes.flow_nodes import sequence_node, format_exception_node
from pineapple_nodes.nodes.io_nodes import print_node

sequence = sequence_node()

with sequence.step("first_step") as first_step:
    first_step.print = print_node()
    first_step.print.connect_input(a="Hello, I'm a first step")
    first_step << first_step.print

with sequence.step("second_step") as second_step:
    second_step.print = print_node()
    second_step.print.connect_input(a="Here comes the second step")
    second_step << second_step.print

with sequence.step("third_step") as third_step:
    third_step.print = print_node()
    third_step.print.connect_input(a="Now is the time for the third step")
    third_step.print2 = print_node()
    third_step.print2.connect_input(a="Still in the third step")
    third_step.print.connect_flow(third_step.print2)
    third_step << third_step.print

with sequence.step("fourth_step") as fourth_step:
    fourth_step.print = print_node()
    fourth_step.print.connect_input(a="I'm the fourth step")
    fourth_step << fourth_step.print

with sequence.step("fifth_step") as fifth_step:
    fifth_step.exception = format_exception_node()
    fifth_step.exception.connect_input(