コード例 #1
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')
コード例 #2
0
def test_commandToExecute():
    """Test MDGModifier::commandToExecute binding."""

    mod = cmdc.DGModifier()
    mod.commandToExecute('createNode -name "foobar" "transform";')

    mod.doIt()
    assert cmds.objExists('foobar'), 'DGModifier::commandToExecute doIt failed'

    mod.undoIt()
    assert not cmds.objExists(
        'foobar'), 'DGModifier::commandToExecute undo failed'

    nose.tools.assert_raises(ValueError,
                             cmdc.DGModifier().commandToExecute, '')
コード例 #3
0
def _newPlugValue(new_value, method_name, add_attr_kwargs):
    node = cmds.createNode('network')
    cmds.addAttr(node, longName='test', **add_attr_kwargs)
    attr = node + '.test'

    old_value = new_value.__class__(cmds.getAttr(attr))

    plug = as_plug(attr)

    mod = cmdc.DGModifier()
    mod_fn = getattr(mod, method_name)
    mod_fn(plug, new_value)
    mod.doIt()

    # My kingdom for fStrings
    doit_value = new_value.__class__(cmds.getAttr(attr))
    assert_equals(
        new_value, doit_value,
        'DGModifier.{} doIt failed to set the value - expected: {}, actual: {}'
        .format(method_name, new_value, doit_value))

    mod.undoIt()

    undo_value = new_value.__class__(cmds.getAttr(attr))
    assert_equals(
        old_value, undo_value,
        'DGModifier.{} undo failed to set the value - expected: {}, actual: {}'
        .format(method_name, old_value, undo_value))
コード例 #4
0
def test_removeMultiInstance_pass():
    """Test MDGModfifier::removeMultiInstance binding."""

    node = cmds.createNode('network')

    cmds.addAttr(node, ln='pass', multi=True)

    plug_obj = as_plug(node + '.pass')
    null_obj = cmdc.Plug()

    cmds.setAttr(node + '.pass[0]', 1.0)
    cmds.setAttr(node + '.pass[1]', 1.0)
    cmds.setAttr(node + '.pass[2]', 1.0)

    index_obj = plug_obj.elementByLogicalIndex(1)

    mod = cmdc.DGModifier()
    mod.removeMultiInstance(index_obj, True)

    mod.doIt()
    assert plug_obj.getExistingArrayAttributeIndices() == [
        0, 2
    ], 'DGMOdifier.removeMultiInstance doIt failed'

    mod.undoIt()
    assert plug_obj.getExistingArrayAttributeIndices() == [
        0, 1, 2
    ], 'DGMOdifier.removeMultiInstance undoIt failed'
コード例 #5
0
def test_pythonCommandToExecute():
    """Test MDGModifier::pythonCommandToExecute binding."""

    mod = cmdc.DGModifier()
    mod.pythonCommandToExecute(
        'from maya import cmds; cmds.createNode("transform", name="foobar")')

    mod.doIt()
    assert cmds.objExists(
        'foobar'), 'DGModifier::pythonCommandToExecute doIt failed'

    mod.undoIt()
    assert not cmds.objExists(
        'foobar'), 'DGModifier::pythonCommandToExecute undo failed'

    nose.tools.assert_raises(ValueError,
                             cmdc.DGModifier().commandToExecute, '')
コード例 #6
0
def _deleteNode_fail(exception, arg):
    old_nodes = cmds.ls(long=True)

    nose.tools.assert_raises(exception, cmdc.DGModifier().deleteNode, arg)

    new_nodes = cmds.ls(long=True)

    assert len(old_nodes) == len(
        new_nodes), "DGModifier.deleteNode modified the scene graph."
コード例 #7
0
def _connect_pass(src_plug, dst_plug, args):
    mod = cmdc.DGModifier()
    mod.connect(*args)

    mod.doIt()
    assert cmds.isConnected(src_plug.name(),
                            dst_plug.name()), "DGModifier.connect doIt failed"

    mod.undoIt()
    assert not cmds.isConnected(
        src_plug.name(), dst_plug.name()), 'DGModifier.connect undoIt failed'
コード例 #8
0
def _createNode_pass(arg):
    old_nodes = cmds.ls(long=True)

    mod = cmdc.DGModifier()
    node = mod.createNode(arg)
    mod.doIt()

    new_nodes = cmds.ls(long=True)

    add_nodes = set(new_nodes) - set(old_nodes)

    assert not node.isNull(), "Created node is not valid."
    assert len(add_nodes) == 1, "`ls` did not return new node."
コード例 #9
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)
コード例 #10
0
def test_deleteNode_pass():
    """Test MDGModifier::createNode if called with a valid node."""

    node = cmds.createNode('network')
    obj = as_obj(node)

    mod = cmdc.DGModifier()
    mod.deleteNode(obj)

    mod.doIt()
    assert not cmds.objExists(node), 'DGModifier.deleteNode doIt failed'

    mod.undoIt()
    assert cmds.objExists(node), 'DGModifier.deleteNode undoIt failed'
コード例 #11
0
def _disconnect_pass(setup_fn):
    src_plug, dst_plug, args = setup_fn()
    cmds.connectAttr(src_plug.name(), dst_plug.name())

    mod = cmdc.DGModifier()
    mod.disconnect(*args)

    mod.doIt()
    assert not cmds.isConnected(
        src_plug.name(), dst_plug.name()), "DGModifier.disconnect doIt failed"

    mod.undoIt()
    assert cmds.isConnected(
        src_plug.name(),
        dst_plug.name()), 'DGModifier.disconnect undoIt failed'
コード例 #12
0
def test_removeAttribute_pass():
    """Test MDGModifier::removeAttribute if called with a valid attribute."""

    node = cmds.createNode('network')
    attr = node + '.test'

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

    plug = as_plug(attr)

    mod = cmdc.DGModifier()
    mod.removeAttribute(plug.node(), plug.attribute())

    mod.doIt()
    assert not cmds.objExists(attr), 'DGModifier.removeAttribute doIt failed'

    mod.undoIt()
    assert cmds.objExists(attr), 'DGModifier.removeAttribute undoIt failed'
コード例 #13
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'
コード例 #14
0
def _removeAttribute_fail(exception, node, attr):
    nose.tools.assert_raises(exception,
                             cmdc.DGModifier().removeAttribute, node, attr)
コード例 #15
0
def _renameAttribute_fail(exception, node_obj, attr_obj, short_name,
                          long_name):
    nose.tools.assert_raises(exception,
                             cmdc.DGModifier().renameAttribute, node_obj,
                             attr_obj, short_name, long_name)
コード例 #16
0
def _disconnect_fail(exception, args):
    nose.tools.assert_raises(exception, cmdc.DGModifier().disconnect, *args)
コード例 #17
0
def _removeMultiInstance_fail(exception, plug_obj):
    nose.tools.assert_raises(exception,
                             cmdc.DGModifier().removeMultiInstance, plug_obj,
                             True)