Ejemplo n.º 1
0
    def test_elementByPhysicalIndex(self):
        """Test for MPlug::elementByPhysicalIndex binding."""

        array_root = cmdc.SelectionList().add(p(self.node, 'array')).getPlug(0)

        selection = cmdc.SelectionList().add(p(self.node, 'array[*]'))

        plug_0 = selection.getPlug(0)
        plug_1 = selection.getPlug(1)
        plug_3 = selection.getPlug(2)

        assert array_root.elementByPhysicalIndex(0) == plug_0
        assert array_root.elementByPhysicalIndex(1) == plug_1
        assert array_root.elementByPhysicalIndex(2) == plug_3

        nose.tools.assert_raises(IndexError, array_root.elementByPhysicalIndex,
                                 9001)

        non_array_root = cmdc.SelectionList().add(p(self.node,
                                                    'single')).getPlug(0)

        nose.tools.assert_raises(TypeError,
                                 non_array_root.elementByPhysicalIndex, 0)
        nose.tools.assert_raises(ValueError,
                                 cmdc.Plug().elementByPhysicalIndex, 0)
Ejemplo n.º 2
0
    def test_elementByLogicalIndex(self):
        """Test for MPlug::elementByLogicalIndex binding."""

        array_root = cmdc.SelectionList().add(p(self.node, 'array')).getPlug(0)

        selection = cmdc.SelectionList().add(p(self.node, 'array[*]'))

        plug_0 = selection.getPlug(0)
        plug_1 = selection.getPlug(1)
        plug_3 = selection.getPlug(2)

        assert array_root.elementByLogicalIndex(0) == plug_0
        assert array_root.elementByLogicalIndex(1) == plug_1
        assert array_root.elementByLogicalIndex(3) == plug_3

        # A plug will be created at the requested index if it does not exist.
        assert not array_root.elementByLogicalIndex(5).isNull()

        non_array_root = cmdc.SelectionList().add(p(self.node,
                                                    'single')).getPlug(0)

        nose.tools.assert_raises(TypeError,
                                 non_array_root.elementByLogicalIndex, 0)
        nose.tools.assert_raises(ValueError,
                                 cmdc.Plug().elementByLogicalIndex, 0)
Ejemplo n.º 3
0
    def test_destinationsWithConversion(self):
        """Test for MPlug::destinationsWithConversions binding."""

        src_plug = cmdc.SelectionList().add(p(self.src_node,
                                              'attr')).getPlug(0)
        tgt_plug = cmdc.SelectionList().add(p(self.tgt_node,
                                              'attr')).getPlug(0)
        alt_plug = cmdc.SelectionList().add(p(self.alt_node,
                                              'attr')).getPlug(0)

        assert tgt_plug.destinations(
        ) == [], 'Plug.destinationsWithConversions should return an empty list for unconnected plugs'

        destinations = src_plug.destinationsWithConversions()

        assert destinations is not None, 'Plug.destinationsWithConversions returned a null'

        assert len(
            destinations
        ) == 2, 'Plug.destinationsWithConversions returned %s values; expected 2' % len(
            destinations)

        assert destinations[0].node().hasFn(
            cmdc.Fn.kUnitConversion
        ), 'Plug.destinationsWithConversions skipped over conversion node'
        assert destinations[1].node().hasFn(
            cmdc.Fn.kUnitConversion
        ), 'Plug.destinationsWithConversions skipped over conversion node'

        assert tgt_plug not in destinations, 'Plug.destinationsWithConversions returned incorrect results'
        assert alt_plug not in destinations, 'Plug.destinationsWithConversions returned incorrect results'

        nose.tools.assert_raises(ValueError,
                                 cmdc.Plug().destinationsWithConversions)
Ejemplo n.º 4
0
def test_hasFn():
    sel = cmdc.SelectionList().add("persp")
    obj = sel.getDependNode(0)
    assert obj.hasFn(cmdc.Fn.kTransform)

    sel = cmdc.SelectionList().add("perspShape")
    obj = sel.getDependNode(0)
    assert obj.hasFn(cmdc.Fn.kCamera)
Ejemplo n.º 5
0
    def test_numElements(self):
        """Test for MPlug::numElements binding."""

        array_root = cmdc.SelectionList().add(p(self.node, 'array')).getPlug(0)

        assert array_root.numElements() == 3

        non_array_root = cmdc.SelectionList().add(p(self.node,
                                                    'single')).getPlug(0)

        nose.tools.assert_raises(TypeError, non_array_root.numElements)
        nose.tools.assert_raises(ValueError, cmdc.Plug().numElements)
Ejemplo n.º 6
0
    def test_numChildren(self):
        """Test for MPlug::numChildren binding."""

        parent = cmdc.SelectionList().add(p(self.node, 'parent_a')).getPlug(0)

        assert parent.numChildren() == 1

        non_parent = cmdc.SelectionList().add(p(self.node,
                                                'single')).getPlug(0)

        nose.tools.assert_raises(TypeError, non_parent.numChildren)
        nose.tools.assert_raises(ValueError, cmdc.Plug().numChildren)
Ejemplo n.º 7
0
    def test_source(self):
        """Test for MPlug::source binding."""

        src_plug = cmdc.SelectionList().add(p(self.src_node,
                                              'attr')).getPlug(0)
        tgt_plug = cmdc.SelectionList().add(p(self.tgt_node,
                                              'attr')).getPlug(0)

        assert src_plug.source().isNull(
        ), 'Plug.source should return a null plug when not a destination'
        assert tgt_plug.source(
        ) == src_plug, 'Plug.source did not return the source plug.'

        nose.tools.assert_raises(ValueError, cmdc.Plug().source)
Ejemplo n.º 8
0
    def test_parent(self):
        """Test for MPlug::parent binding."""

        parent = cmdc.SelectionList().add(p(self.node, 'parent_a')).getPlug(0)
        child = cmdc.SelectionList().add(p(self.node, 'parent_a',
                                           'child_a')).getPlug(0)

        result = child.parent()

        assert result is not None
        assert result.name() == parent.name()

        nose.tools.assert_raises(TypeError, parent.parent)
        nose.tools.assert_raises(ValueError, cmdc.Plug().parent)
Ejemplo n.º 9
0
    def test_array(self):
        """Test for MPlug::array binding."""

        array_element = cmdc.SelectionList().add(p(self.node, 'array',
                                                   0)).getPlug(0)
        array_root = array_element.array()

        assert array_root is not None
        assert array_root.name() == p(self.node, 'array')

        non_array_element = cmdc.SelectionList().add(p(self.node,
                                                       'single')).getPlug(0)

        nose.tools.assert_raises(TypeError, non_array_element.array)
        nose.tools.assert_raises(ValueError, cmdc.Plug().array)
Ejemplo n.º 10
0
def test_isValid():
    sel = cmdc.SelectionList().add("persp")
    persp = sel.getDagPath(0)
    assert persp.isValid()

    invalid_dag = cmdc.DagPath()
    assert not invalid_dag.isValid()
Ejemplo n.º 11
0
def test_inequality():
    sel = cmdc.SelectionList()
    sel.add("persp")
    sel.add("front")
    persp = sel.getDependNode(0)
    front = sel.getDependNode(1)
    assert persp != front
Ejemplo n.º 12
0
    def test_connectedTo(self):
        """Test for MPlug::connectedTo binding."""

        src_node = cmds.createNode('network')
        the_node = cmds.createNode('network')
        dst_node_a = cmds.createNode('network')
        dst_node_b = cmds.createNode('network')

        cmds.addAttr(src_node, ln='attr', at='double')
        cmds.addAttr(the_node, ln='attr', at='double')
        cmds.addAttr(dst_node_a, ln='attr', at='double')
        cmds.addAttr(dst_node_b, ln='attr', at='double')

        cmds.connectAttr(p(src_node, 'attr'), p(the_node, 'attr'))
        cmds.connectAttr(p(the_node, 'attr'), p(dst_node_a, 'attr'))
        cmds.connectAttr(p(the_node, 'attr'), p(dst_node_b, 'attr'))

        the_plug = cmdc.SelectionList().add(p(the_node, 'attr')).getPlug(0)

        src_connections = the_plug.connectedTo(True, True)
        src_input = the_plug.connectedTo(True, False)
        src_outputs = the_plug.connectedTo(False, True)

        assert len(src_connections) == 3
        assert len(src_input) == 1
        assert len(src_outputs) == 2
Ejemplo n.º 13
0
    def test_getExistingArrayAttributeIndices(self):
        """Test for MPlug::getExistingArrayAttributeIndices binding."""

        array_root = cmdc.SelectionList().add(p(self.node, 'array')).getPlug(0)

        indices = array_root.getExistingArrayAttributeIndices()

        assert indices == [0, 1, 3]

        non_array_root = cmdc.SelectionList().add(p(self.node,
                                                    'single')).getPlug(0)

        nose.tools.assert_raises(
            TypeError, non_array_root.getExistingArrayAttributeIndices)
        nose.tools.assert_raises(ValueError,
                                 cmdc.Plug().getExistingArrayAttributeIndices)
Ejemplo n.º 14
0
def check_setType_method(method_name, value, add_attr_kwargs):
    """Test for MPlug::set* bindings."""

    node = cmds.createNode('network')

    attr = p(node, 'attr')

    cmds.addAttr(node, ln='attr', **add_attr_kwargs)

    plug = cmdc.SelectionList().add(attr).getPlug(0)

    method = getattr(plug, method_name)
    method(value)

    expected = value
    actual = cmds.getAttr(attr)

    error_message = (
        'Plug method {} set the wrong value - expected: {}, actual: {}'.format(
            method_name, expected, actual))

    if isinstance(expected, float):
        assert abs(expected - actual) <= 1e-5, error_message
    else:
        assert expected == actual, error_message
Ejemplo n.º 15
0
def test_extendToShapeDirectlyBelow():
    transform = cmds.polyCube()[0]
    cmds.duplicate("pCubeShape1")
    shape1 = "pCubeShape1"
    shape2 = "pCubeShape2"
    cmds.parent(shape2, transform, shape=True, relative=True)
    assert len(cmds.listRelatives(transform, shapes=True)) == 2

    sel = cmdc.SelectionList().add(transform).add(shape1).add(shape2)

    transform_dag = sel.getDagPath(0)
    shape1_dag = sel.getDagPath(1)
    transform_dag.extendToShapeDirectlyBelow(0)
    assert transform_dag == shape1_dag

    transform_dag = sel.getDagPath(0)
    shape2_dag = sel.getDagPath(2)
    transform_dag.extendToShapeDirectlyBelow(1)
    assert transform_dag == shape2_dag

    transform_dag = sel.getDagPath(0)
    nose.tools.assert_raises(IndexError,
                             transform_dag.extendToShapeDirectlyBelow, 2)

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(RuntimeError,
                             invalid_dag.extendToShapeDirectlyBelow, 0)
Ejemplo n.º 16
0
def test_set():
    sel = cmdc.SelectionList().add("persp")

    persp_dag = sel.getDagPath(0)

    dag = cmdc.DagPath()
    dag.set(persp_dag)
    assert dag == persp_dag
Ejemplo n.º 17
0
    def test_sourceWithConversion(self):
        """Test for MPlug::sourceWithConversion binding."""

        src_plug = cmdc.SelectionList().add(p(self.src_node,
                                              'attr')).getPlug(0)
        tgt_plug = cmdc.SelectionList().add(p(self.tgt_node,
                                              'attr')).getPlug(0)

        assert src_plug.sourceWithConversion().isNull(
        ), 'Plug.sourceWithConversion should return a null plug when not a destination'
        assert tgt_plug.sourceWithConversion(
        ) != src_plug, 'Plug.sourceWithConversion skipped over the conversion node'
        assert tgt_plug.sourceWithConversion().node().hasFn(
            cmdc.Fn.kUnitConversion
        ), 'Plug.sourceWithConversion skipped over conversion node'

        nose.tools.assert_raises(ValueError, cmdc.Plug().sourceWithConversion)
Ejemplo n.º 18
0
def test_apiType():
    sel = cmdc.SelectionList().add("persp")

    valid_dag = sel.getDagPath(0)
    assert valid_dag.apiType() == cmdc.Fn.kTransform

    invalid_dag = cmdc.DagPath()
    assert invalid_dag.apiType() == cmdc.Fn.kInvalid
Ejemplo n.º 19
0
def test_add_object_that_exists():
    sel = cmdc.SelectionList().add('time1')

    assert len(sel) == 1

    obj = sel.getDependNode(0)

    assert obj.hasFn(cmdc.Fn.kTime)
Ejemplo n.º 20
0
    def test_info(self):
        """Test for MPlug::info binding."""

        attr = p(self.node, 'root', 'branch', 0, 'leaf')
        plug = cmdc.SelectionList().add(attr).getPlug(0)

        # You would think it would return the full plug path, but it doesn't...
        assert plug.info() == p(self.node, 'branch', 0, 'leaf')
Ejemplo n.º 21
0
def test_add_object_that_does_not_exist():
    sel = cmdc.SelectionList()

    nose.tools.assert_raises(
        ValueError,
        sel.add, 'free_lunch'
    )

    assert len(sel) == 0
Ejemplo n.º 22
0
    def test_logicalIndex(self):
        """Test for MPlug::logicalIndex binding."""

        selection = cmdc.SelectionList().add(p(self.node, 'array[*]'))

        plug_0 = selection.getPlug(0)
        plug_1 = selection.getPlug(1)
        plug_3 = selection.getPlug(2)

        assert plug_0.logicalIndex() == 0
        assert plug_1.logicalIndex() == 1
        assert plug_3.logicalIndex() == 3

        non_element = cmdc.SelectionList().add(p(self.node,
                                                 'single')).getPlug(0)

        nose.tools.assert_raises(TypeError, non_element.logicalIndex)
        nose.tools.assert_raises(ValueError, cmdc.Plug().logicalIndex)
Ejemplo n.º 23
0
def test_get_object_from_empty_list():
    sel = cmdc.SelectionList()

    assert sel.isEmpty()
    assert len(sel) == 0

    nose.tools.assert_raises(
        IndexError,
        sel.getDependNode, 0
    )
Ejemplo n.º 24
0
def test_exclusiveMatrixInverse():
    sel = cmdc.SelectionList().add("persp").add("perspShape")

    persp = sel.getDagPath(0)
    assert isinstance(persp.exclusiveMatrixInverse(), cmdc.Matrix)

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(
        RuntimeError,
        invalid_dag.exclusiveMatrixInverse,
    )
Ejemplo n.º 25
0
def test_child():
    sel = cmdc.SelectionList().add("persp").add("perspShape")

    dag_with_child = sel.getDagPath(0)
    assert isinstance(dag_with_child.child(0), cmdc.Object)

    dag_without_children = sel.getDagPath(1)
    nose.tools.assert_raises(IndexError, dag_without_children.child, 0)

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(RuntimeError, invalid_dag.child, 0)
Ejemplo n.º 26
0
def test_node():
    sel = cmdc.SelectionList().add("persp")

    persp_dag = sel.getDagPath(0)
    persp_obj = sel.getDependNode(0)
    assert persp_dag.node() == persp_obj

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(
        RuntimeError,
        invalid_dag.length,
    )
Ejemplo n.º 27
0
def test_push():
    sel = cmdc.SelectionList().add("persp").add("perspShape")

    persp_dag = sel.getDagPath(0)
    persp_shape_dag = sel.getDagPath(1)
    persp_shape_obj = sel.getDependNode(1)

    persp_dag.push(persp_shape_obj)
    assert persp_dag == persp_shape_dag

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(RuntimeError, invalid_dag.push, cmdc.Object())
Ejemplo n.º 28
0
def test_hasFn():
    sel = cmdc.SelectionList().add("persp").add("perspShape")

    persp = sel.getDagPath(0)
    assert persp.hasFn(cmdc.Fn.kTransform)

    persp_shape = sel.getDagPath(1)
    assert persp_shape.hasFn(cmdc.Fn.kCamera)

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(RuntimeError, invalid_dag.hasFn,
                             cmdc.Fn.kTransform)
Ejemplo n.º 29
0
def test_extendToShape():
    sel = cmdc.SelectionList().add("persp").add("perspShape")

    persp = sel.getDagPath(0)
    persp_shape = sel.getDagPath(1)
    persp.extendToShape()
    assert persp == persp_shape

    invalid_dag = cmdc.DagPath()
    nose.tools.assert_raises(
        RuntimeError,
        invalid_dag.extendToShape,
    )
Ejemplo n.º 30
0
def test_selection_strings():
    sel = cmdc.SelectionList()
    sel.add('time1')
    sel.add('persp')
    sel.add('front')

    sel_str = sel.getSelectionStrings()

    assert sel_str == ['time1', 'persp', 'front']

    sel_str = sel.getSelectionStrings(0)

    assert sel_str == ['time1']