예제 #1
0
def test_connection_to_node_with_subplugs(clear_default_graph):
    """Test the INode.connect() method with subplugs."""
    @Node(outputs=["compound"])
    def Node1():
        return {"compound": {"sub1": 1, "sub2": 2}}

    @Node(outputs=[])
    def Node2(compound):
        return {}

    n1 = Node1()
    n2 = Node2()
    n3 = Node2(name='Node3')

    n1.outputs["compound"]["sub1"].connect(n2.inputs["compound"]["sub1"])
    n1.outputs["compound"]["sub2"].connect(n2.inputs["compound"]["sub2"])

    n1.connect(n3)

    print(get_default_graph())
    assert isinstance(n2.inputs["compound"]["sub1"], SubInputPlug)
    assert isinstance(n2.inputs["compound"]["sub2"], SubInputPlug)
    assert n2.inputs["compound"]["sub1"] in n1.outputs["compound"][
        "sub1"].connections
    assert n2.inputs["compound"]["sub2"] in n1.outputs["compound"][
        "sub2"].connections

    assert isinstance(n3.inputs["compound"]["sub1"], SubInputPlug)
    assert isinstance(n3.inputs["compound"]["sub2"], SubInputPlug)
    assert n3.inputs["compound"]["sub1"] in n1.outputs["compound"][
        "sub1"].connections
    assert n3.inputs["compound"]["sub2"] in n1.outputs["compound"][
        "sub2"].connections
예제 #2
0
def test_deserialize_node_does_not_add_to_default_graph(clear_default_graph):
    node1 = SquareNode('Node1')
    node2 = SquareFunctionNode(name='Node2')

    node1.from_json(node1.to_json())
    node1.from_json(node1.to_json())

    node2.from_json(node2.to_json())
    node2.from_json(node2.to_json())

    assert len(get_default_graph().nodes) == 2
예제 #3
0
def test_reset_default_graph(clear_default_graph):
    new_default = Graph(name='new default')
    set_default_graph(new_default)
    assert get_default_graph().name == 'new default'
    reset_default_graph()
    assert get_default_graph().name == 'default'
예제 #4
0
def test_get_default_graph():
    direct = flowpipe.graph.default_graph
    getter = get_default_graph()
    assert direct is getter
예제 #5
0
def test_reset_default_graph(clear_default_graph):
    new_default = Graph(name="new default")
    set_default_graph(new_default)
    assert get_default_graph().name == "new default"
    reset_default_graph()
    assert get_default_graph().name == "default"