Esempio n. 1
0
def test_unitConversion(cmds):  # pylint: disable=invalid-name
    """
    Test we can understand TdataNumeric attributes.
    unitConversion nodes are a good case.
    """
    cmds.createNode("transform")
    cmds.createNode("unitConversion")
    cmds.connectAttr("transform1.rotateX", "unitConversion1.input")
    cmds.connectAttr("unitConversion1.output", "transform1.translateX")

    create_from_nodes(["unitConversion1"], expose=True)
Esempio n. 2
0
def test_integration(cmds):
    """
    Test a complex case where:
    - We expose two element attributes from the same array
    """
    cmds.createNode("transform", name="inputs1")
    cmds.createNode("transform", name="inputs2")
    cmds.createNode("plusMinusAverage", name="util")
    cmds.createNode("transform", name="outputs")

    cmds.connectAttr("inputs1.translate", "util.input3D[0]")
    cmds.connectAttr("inputs2.translate", "util.input3D[1]")
    cmds.connectAttr("util.output3D", "outputs.translate")

    create_from_nodes(["util"], expose=True)
Esempio n. 3
0
def test_create_from_nodes_nested():
    """Validate we can create compound inside compound from a set of nodes."""
    create_from_nodes({"b", "c", "d"}, namespace="namespace_a")
    create_from_nodes({"namespace_a:c"}, namespace="namespace_b")

    assert _ls() == {
        "a",
        "namespace_a:inputs",
        "namespace_a:b",
        "namespace_a:namespace_b:inputs",
        "namespace_a:namespace_b:c",
        "namespace_a:namespace_b:outputs",
        "namespace_a:d",
        "namespace_a:outputs",
        "e",
    }
Esempio n. 4
0
def test_create_from_nodes_nested_2(scene):
    create_from_nodes({"c"}, namespace="namespace_b")
    create_from_nodes(
        {"b", "namespace_b:c", "namespace_b:inputs", "namespace_b:outputs"},
        namespace="namespace_a",
    )

    assert _ls() == {
        "a",
        "namespace_a:inputs",
        "namespace_a:b",
        "namespace_a:namespace_b:inputs",
        "namespace_a:namespace_b:c",
        "namespace_a:namespace_b:outputs",
        "namespace_a:outputs",
        "d",
        "e",
    }
Esempio n. 5
0
def test_create_from_nodes_namespaces(scene):
    cmds.namespace(addNamespace="namespace")
    cmds.rename("a", "namespace:a")
    cmds.rename("b", "namespace:b")
    cmds.rename("c", "namespace:c")
    cmds.rename("d", "namespace:d")
    cmds.rename("e", "namespace:e")

    create_from_nodes({"namespace:c"}, namespace="new_namespace")

    assert _ls() == {
        "namespace:a",
        "namespace:b",
        "namespace:new_namespace:inputs",
        "namespace:new_namespace:c",
        "namespace:new_namespace:outputs",
        "namespace:d",
        "namespace:e",
    }
Esempio n. 6
0
def test_create_from_nodes_namespaces():
    """Validate we can create a compound from a set of nodes and namespace them."""
    cmds.namespace(addNamespace="namespace")
    cmds.rename("a", "namespace:a")
    cmds.rename("b", "namespace:b")
    cmds.rename("c", "namespace:c")
    cmds.rename("d", "namespace:d")
    cmds.rename("e", "namespace:e")

    create_from_nodes({"namespace:c"}, namespace="new_namespace")

    assert _ls() == {
        "namespace:a",
        "namespace:b",
        "namespace:new_namespace:inputs",
        "namespace:new_namespace:c",
        "namespace:new_namespace:outputs",
        "namespace:d",
        "namespace:e",
    }
Esempio n. 7
0
def test_map_from_nodes_expose_simple(cmds):
    cmds.createNode("transform", name="a")
    cmds.createNode("transform", name="b")
    cmds.createNode("transform", name="c")
    cmds.connectAttr("a.translateX", "b.translateX")
    cmds.connectAttr("b.translateY", "c.translateY")

    create_from_nodes(["b"], expose=True)

    assert _ls() == {
        "a", "compound1:inputs", "compound1:b", "compound1:outputs", "c"
    }

    for src, dst in (
        ("a.translateX", "compound1:inputs.translateX"),
        ("compound1:inputs.translateX", "compound1:b.translateX"),
        ("compound1:b.translateY", "compound1:outputs.translateY"),
        ("compound1:outputs.translateY", "c.translateY"),
    ):
        assert cmds.isConnected(src, dst)
Esempio n. 8
0
def test_create_from_nodes_nested_2():
    """
    Validate we can create a compound from a set of nodes containing another compound.
    """
    create_from_nodes({"c"}, namespace="namespace_b")
    create_from_nodes(
        {"b", "namespace_b:c", "namespace_b:inputs", "namespace_b:outputs"},
        namespace="namespace_a",
    )

    assert _ls() == {
        "a",
        "namespace_a:inputs",
        "namespace_a:b",
        "namespace_a:namespace_b:inputs",
        "namespace_a:namespace_b:c",
        "namespace_a:namespace_b:outputs",
        "namespace_a:outputs",
        "d",
        "e",
    }
Esempio n. 9
0
def test_map_from_nodes_expose_cyclic(cmds):
    """ Validate we ignore connections pointing to nodes in the network."""
    cmds.createNode("transform", name="a")
    cmds.createNode("transform", name="b")
    cmds.createNode("transform", name="c")
    cmds.connectAttr("a.translateX", "b.translateX")
    cmds.connectAttr("b.translateY", "c.translateY")
    cmds.connectAttr("b.rotateX", "b.rotateY")

    create_from_nodes(["b"], expose=True)

    assert _ls() == {
        "a", "compound1:inputs", "compound1:b", "compound1:outputs", "c"
    }

    for src, dst in (
        ("a.translateX", "compound1:inputs.translateX"),
        ("compound1:inputs.translateX", "compound1:b.translateX"),
        ("compound1:b.translateY", "compound1:outputs.translateY"),
        ("compound1:outputs.translateY", "c.translateY"),
    ):
        assert cmds.isConnected(src, dst)
Esempio n. 10
0
def test_create_from_nodes():
    """Validate we can create a compound from a set of nodes."""
    compound = create_from_nodes({"b", "c"})

    assert isinstance(compound, Compound)
    assert _ls() == {
        "a",
        "compound1:inputs",
        "compound1:outputs",
        "compound1:b",
        "compound1:c",
        "d",
        "e",
    }
Esempio n. 11
0
def test_create_from_nodes_expose_reused_input_attributes(cmds):
    """ Ensure that we re-use an attribute if it is used twice as the network input.
    """
    cmds.createNode("transform", name="input1")
    cmds.createNode("transform", name="node1")
    cmds.createNode("transform", name="node2")

    cmds.connectAttr("input1.translateX", "node1.translateX")
    cmds.connectAttr("input1.translateX", "node2.translateX")

    create_from_nodes({"node1", "node2"},
                      namespace="test_namespace",
                      expose=True)

    assert _ls() == {
        "input1",
        "test_namespace:inputs",
        "test_namespace:node1",
        "test_namespace:node2",
        "test_namespace:outputs",
    }
    assert cmds.listAttr("test_namespace:inputs",
                         userDefined=True) == ["translateX"]
    assert not cmds.listAttr("test_namespace:outputs", userDefined=True)
Esempio n. 12
0
def test_integration_1(manager):
    """
    1) Create a compound
    2) Register the compound
    3) Modify the compound
    4) Register a new version of the compound
    5) Rollback to the previous version
    6) Update to latest
    """
    def _test_compound_v1():
        """
        Validate the namespace actually contain v1 of our test compound.

        :param str namespace: The compound namespace
        """
        # Validate internal connections
        for src, dst in (
            ("foo:inputs.input1X", "foo:multiplyDivide1"),
            ("foo:multiplyDivide1.outputX", "foo:outputs.outputX"),
        ):
            cmds.isConnected(src, dst)

        # Validate external connections
        for src, dst in (
            ("testInn.translateX", "foo:inputs.input1X"),
            ("foo:outputs.outputX", "testOut.translateX"),
        ):
            cmds.isConnected(src, dst)

        # Validate scene content
        for dagpath in (
                "foo:inputs",
                "foo:inputs.input1X",
                "foo:multiplyDivide1",
                "foo:outputs",
                "foo:outputs.outputX",
        ):
            assert cmds.objExists(dagpath)

        for dagpath in ("foo:outputs.outputY", ):
            assert not cmds.objExists(dagpath)

    def _test_compound_v2():
        for dagpath in (
                "foo:inputs",
                "foo:inputs.input1X",
                "foo:multiplyDivide1",
                "foo:outputs",
                "foo:outputs.outputX",
                "foo:outputs.outputY",
        ):
            assert cmds.objExists(dagpath)

    # 1) Create a simple network
    mult1 = pymel.createNode("multiplyDivide")

    # Create a compound from the network
    compound = create_from_nodes([mult1], namespace="foo")
    attr = mult1.input1X
    compound.expose_input_attr(attr)
    compound.expose_output_attr(mult1.outputX)

    # Create connections from outside the compound
    cmds.createNode("transform", name="testInn")
    cmds.createNode("transform", name="testOut")
    cmds.connectAttr("testInn.translateX", "foo:inputs.input1X")
    cmds.connectAttr("foo:outputs.outputX", "testOut.translateX")

    _test_compound_v1()

    # Register the compound?
    compound_def_1 = CompoundDefinition(name="compound_name",
                                        version="1.0.0",
                                        uid="compound_uid")
    compound.set_metadata(dict(compound_def_1))
    manager.publish_compound(compound)

    # Modify the scene content
    compound.expose_output_attr(mult1.outputY)

    _test_compound_v2()

    # TODO: Error if the file does not end with .ma?

    compound_def_2 = CompoundDefinition(name="compound_name",
                                        version="1.0.1",
                                        uid="compound_uid")
    compound.set_metadata(dict(compound_def_2))
    manager.publish_compound(compound)

    cmds.connectAttr("foo:outputs.outputY", "testOut.translateY")

    # Downgrade our compound
    manager.update_compound(compound, "1.0.0")

    _test_compound_v1()

    # Upgrade our compound
    manager.update_compound(compound)
    _test_compound_v2()

    # Verify that we can restore our in-memory registry
    new_registry = Registry()
    new_registry.parse_directory(manager.preferences.compound_location)

    assert manager.registry == new_registry