示例#1
0
def test_that_check_nodeinput_fallback_values():
    nice_input = NodeInput(dummy_node, "niceinput", str, False)
    nice_input.set("This is a fallback value")
    assert nice_input.get() == "This is a fallback value"
    str_output = NodeOutput(dummy_node, "stroutput",
                            str)  # The famous creator of C++
    str_output.set("This is not a fallback value")
    nice_input.connect(str_output)
    assert nice_input.get() == "This is not a fallback value"
示例#2
0
def test_that_checks_multiple_nodeoutput_types():
    versatile_output = NodeOutput(dummy_node, "versatile_output", [int])
    versatile_output.set([1, 2, 3, 4])

    assert versatile_output.get()[0] == 1
    assert versatile_output.get()[1] == 2
    assert versatile_output.get()[2] == 3
    assert versatile_output.get()[3] == 4

    beautiful_output = NodeOutput(
        dummy_node,
        "beautiful_output",
        {
            "a": [int],
            "b": {
                "c": [[int]]
            },
            "d": [{
                "e": str
            }]
        },
    )
    beautiful_output.set({
        "a": [44],
        "b": {
            "c": [[22]]
        },
        "d": [{
            "e": "hello"
        }, {
            "e": "goodbye"
        }]
    })

    assert beautiful_output.get()["a"][0] == 44
    assert beautiful_output.get()["b"]["c"][0][0] == 22
    assert beautiful_output.get()["d"][0]["e"] == "hello"
    assert beautiful_output.get()["d"][1]["e"] == "goodbye"
示例#3
0
def test_that_checks_invalid_output_type():
    wrong_output = NodeOutput(dummy_node, "wrong_output", [str])
    with pytest.raises(InvalidNodeOutputTypeError):
        wrong_output.set([22])

    wrong_output2 = NodeOutput(dummy_node, "wrong_output2", {"a": 1})
    with pytest.raises(RuntimeError):
        wrong_output2.set({"a": "no"})

    wrong_output3 = NodeOutput(dummy_node, "wrong_output3", [1])
    with pytest.raises(RuntimeError):
        wrong_output3.set(["yes"])
示例#4
0
def test_that_check_nodeoutput_value_getter():
    str_output = NodeOutput(dummy_node, "str_output", str)
    str_output.set("Strange string")
    assert str_output.get() == "Strange string"
示例#5
0
def test_that_check_nodeoutput_typecheck():
    int_output = NodeOutput(dummy_node, "int_output", int)
    with pytest.raises(InvalidNodeOutputTypeError):
        int_output.set("hello")
    int_output.set(22)
    any_output = NodeOutput(dummy_node, "any_output", Any())
    any_output.set(lambda x: x)
    any_output.set(11)
    any_output.set("It works with anything")
    sumtype_output = NodeOutput(dummy_node, "none_output", SumType(bool, str))
    sumtype_output.set(True)
    sumtype_output.set("Goodbye")
    with pytest.raises(InvalidNodeOutputTypeError):
        sumtype_output.set(22)
示例#6
0
def test_typing_in_node_output():
    deprecated_output = NodeOutput(dummy_node, "deprecated_output",
                                   typing.Optional[int])
    deprecated_output.set(22)