Exemplo n.º 1
0
def test_deleteNode_fail():
    non_node_obj = cmdc.Object()

    for exc, name, value in (
        [ValueError, 'null object', cmdc.Object()],
        [TypeError, 'non-node object',
         as_plug('persp.message').attribute()],
        [TypeError, 'DAG object', as_obj('persp')],
    ):
        test_deleteNode_fail.__doc__ = """Test MDGModifier::deleteNode raises error if called with a(n) {}.""".format(
            name)

        yield _deleteNode_fail, exc, value
Exemplo n.º 2
0
def test_renameNode():
    """Test MDGModfifier::renameNode binding."""

    node = cmds.createNode('network')
    node_obj = as_obj(node)
    null_obj = cmdc.Object()

    fn_node = cmdc.FnDependencyNode(node_obj)
    old_name, new_name = node, 'foobar123'

    mod = cmdc.DGModifier()
    mod.renameNode(node_obj, new_name)

    mod.doIt()
    assert fn_node.name() == new_name, 'DGModifier.renameNode doIt failed'

    mod.undoIt()
    assert fn_node.name() == old_name, 'DGModifier.renameNode undo failed'

    mod.renameNode(node_obj, 'invalid name')
    mod.doIt()
    assert fn_node.name(
    ) == 'invalid_name', 'DGModifier.renameNode doIt failed with an invalid node name'

    nose.tools.assert_raises(ValueError,
                             cmdc.DGModifier().renameNode, node_obj, '')

    nose.tools.assert_raises(ValueError,
                             cmdc.DGModifier().renameNode, null_obj, 'foobar')
Exemplo n.º 3
0
def test_null_obj_fn():
    """Test that a null Object has the expected Fn."""

    o = cmdc.Object()

    assert not o.hasFn(cmdc.Fn.kInvalid)
    assert o.apiType() == cmdc.Fn.kInvalid.value
    assert o.apiTypeStr() == cmdc.Fn.kInvalid.name
Exemplo n.º 4
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())
Exemplo n.º 5
0
def test_getAPathTo():
    sel = cmdc.SelectionList().add("persp").add("time1")

    persp_obj = sel.getDependNode(0)
    persp_dag = sel.getDagPath(0)
    result = cmdc.DagPath.getAPathTo(persp_obj)
    assert result == persp_dag

    time_obj = sel.getDependNode(1)
    nose.tools.assert_raises(TypeError, cmdc.DagPath.getAPathTo, time_obj)

    invalid_obj = cmdc.Object()
    nose.tools.assert_raises(RuntimeError, cmdc.DagPath.getAPathTo,
                             invalid_obj)
Exemplo n.º 6
0
def test_addAttribute_fail():
    node = as_obj(cmds.createNode('network'))
    null = cmdc.Object()

    attr = as_plug('persp.message').attribute()

    for exc, doc, node, attr in (
        [ValueError, 'a null object', null, null],
        [ValueError, 'a null attribute', node, null],
        [TypeError, 'a non-node object', attr, null],
        [TypeError, 'a non-attribute object', node, node],
    ):
        test_addAttribute_fail.__doc__ = """Test MDGModifier::addAttribute raises error if called with {}.""".format(
            doc)

        yield _addAttribute_fail, exc, node, attr
Exemplo n.º 7
0
def test_removeAttribute_fail():
    node = cmds.createNode('network')
    cmds.addAttr(node, ln='test')

    plug = as_plug(node + '.test')
    null = cmdc.Object()

    for exc, doc, (node, attr) in (
        [ValueError, "a null node", (null, null)],
        [ValueError, "a null attribute", (plug.node(), null)],
        [TypeError, "a non-node object", (plug.attribute(), null)],
        [TypeError, "a non-attribute object", (plug.node(), plug.node())],
    ):
        test_removeAttribute_fail.__doc__ = """Test MDGModifier::removeAttribute raises an error if called with {}.""".format(
            doc)

        yield _removeAttribute_fail, exc, node, attr
Exemplo n.º 8
0
def test_disconnect_fail():
    src_plug = as_plug(cmds.createNode('transform') + '.visibility')
    src_node = src_plug.node()
    src_attr = src_plug.attribute()

    dst_plug = as_plug(cmds.createNode('transform') + '.visibility')
    dst_node = dst_plug.node()
    dst_attr = dst_plug.attribute()

    null = cmdc.Object()
    nop_plug = cmdc.Plug()

    for exc, doc, args in (
        [ValueError, 'a null source object', (null, null, null, null)],
        [ValueError, 'a null source attribute', (src_node, null, null, null)],
        [
            ValueError, 'a null destination object',
            (src_node, src_attr, null, null)
        ],
        [
            ValueError, 'a null destination attribute',
            (src_node, src_attr, dst_node, null)
        ],
        [
            TypeError, 'a non-node source object',
            (src_attr, src_attr, null, null)
        ],
        [
            TypeError, 'a non-attribute source attribute',
            (src_node, src_node, null, null)
        ],
        [
            TypeError, 'a non-node destination object',
            (src_node, src_attr, dst_attr, dst_attr)
        ],
        [
            TypeError, 'a non-attribute destination attribute',
            (src_node, src_attr, dst_node, dst_node)
        ],
        [ValueError, 'a null source plug', (nop_plug, dst_plug)],
        [ValueError, 'a null destination plug', (src_plug, nop_plug)],
    ):
        test_disconnect_fail.__doc__ = """Test MDGModifier::disconnect raises error if called with {}.""".format(
            doc)

        yield _disconnect_fail, exc, args
Exemplo n.º 9
0
def test_renameAttribute_fail():
    """Test MDGModfifier::renameAttribute binding error handling."""

    node = cmds.createNode('network')
    cmds.addAttr(node, ln='fizz')
    plug = as_plug(node + '.fizz')

    node_obj = plug.node()
    attr_obj = plug.attribute()
    null_obj = cmdc.Object()

    for exception, doc, (node, attr, short_name, long_name) in (
        [ValueError, "a null node", (null_obj, attr_obj, '', '')],
        [ValueError, "a null attribute", (node_obj, null_obj, '', '')],
        [ValueError, "an empty short name", (node_obj, attr_obj, '', '')],
        [ValueError, "an empty long name", (node_obj, attr_obj, 'buzz', '')],
    ):
        test_renameAttribute_fail.__doc__ = """Test MDGModifier::renameAttribute raises an error if called with {}.""".format(
            doc)
        yield _renameAttribute_fail, exception, node, attr, short_name, long_name
Exemplo n.º 10
0
def test_setNodeLockState():
    """Test MDGModifier::setNodeLockState."""

    node = cmds.createNode('network')
    node_obj = as_obj(node)
    null_obj = cmdc.Object()

    mod = cmdc.DGModifier()
    mod.setNodeLockState(node_obj, True)

    mod.doIt()
    assert cmds.lockNode(
        node, query=True,
        lock=True)[0], 'DGModifier.setNodeLockState doIt failed'

    mod.undoIt()
    assert not cmds.lockNode(
        node, query=True,
        lock=True)[0], 'DGModifier.setNodeLockState undo failed'

    nose.tools.assert_raises(TypeError,
                             cmdc.DGModifier().setNodeLockState, null_obj)
Exemplo n.º 11
0
def test_renameAttribute():
    """Test MDGModfifier::renameAttribute binding."""

    node = cmds.createNode('network')

    cmds.addAttr(node, ln='fizz')

    plug = as_plug(node + '.fizz')

    node_obj = plug.node()
    attr_obj = plug.attribute()
    null_obj = cmdc.Object()

    mod = cmdc.DGModifier()
    mod.renameAttribute(node_obj, attr_obj, 'buzz', 'buzz')

    mod.doIt()
    assert plug.name(
    ) == node + '.buzz', 'DGModifier.renameAttribute doIt failed'

    mod.undoIt()
    assert plug.name(
    ) == node + '.fizz', 'DGModifier.renameAttribute undo failed'
Exemplo n.º 12
0
def test_init_mobject():
    sel = cmdc.SelectionList().add("persp")
    obj = sel.getDependNode(0)
    other = cmdc.Object(obj)
    assert not other.isNull()
Exemplo n.º 13
0
def test_equality():
    sel = cmdc.SelectionList().add("persp")
    obj = sel.getDependNode(0)
    other = cmdc.Object(obj)
    assert obj == other
Exemplo n.º 14
0
def test_init_null():
    obj = cmdc.Object()
    assert obj.isNull()