Maya and Subprocess

Hi Guys

I am trying to create some unit tests for my pipeline and I am trying to get my head around this whole subprocess thing

This is Pseudo code of what I am trying to do


1)Launch mayabatch with the command to open a file
2)Run a script  in the launched maya which modifies the file
3)Check that the file has the new info using unitTest.py modules

So I am using the following code to run my maya from python command line


import subprocess
#set up the arguements to launch maya and open the target file
process=subprocess.Popen(args, env=maya_env,stdout=subprocess.PIPE, stderr=subprocess.PIPE )      

So what is happening is that the script jumps directly to step number 3 while mayabatch is till launching and doing it thing. I just want maya to load completely and do it;s thing and then goto to step 3 where I can test the conditions

I tried process.wait() command but that does not solve the problem

What would be cool would to do something like this

Whereby I can send commands to maya to bunch of stuff from the python command line.

Hope I am clear what I am trying to achieve

Cheers

Pritish

This sounds more like a job for maya.standalone. You don’t have to worry about synchronicity, exit codes, or that kind of junk and you can debug in a real debugger if your tests seem not to be working.

This is a non-working example from my codebase. You can’t c-and-p it because the module it’s testing is proprietary – but it give you an idea of how you can set up tests in a standalone. I run this inside Eclipse.


import maya.standalone
import maya.cmds as cmds
try:
    maya.standalone.initialize()
except:
    pass

import tools.geometryMinder.ui

from unittest import TestCase

class test_geometry_minder( TestCase ):

    def test_geometry_minder_loads( self ):
        test = tools.geometryMinder.ui.GeometryMinder()
        assert test != None



    def test_geometry_minder_finds_degenerate_faces( self ):

        cmds.file( new=True, force=True )

        p1 = cmds.polyCube()
        cmds.xform( p1, s=[1, 0, 0] )
        cmds.makeIdentity( p1, a=True )
        cmds.delete( ch=True )

        test = tools.geometryMinder.ui.GeometryMinder()
        test.refresh()
        assert len( test.roots() ) == 1
        cmds.file( new=True, force=True )

    def test_geometry_minder_finds_untextured_faces( self ):

        cmds.file( new=True, force=True )
        p1 = cmds.polyCube()
        cmds.polyMapDel( p1, ch=1 )
        test = tools.geometryMinder.ui.GeometryMinder()
        test.refresh()
        assert len( test.roots() ) == 1
        cmds.file( new=True, force=True )

    def test_geometry_minder_finds_lamina_faces( self ):

        cmds.file( new=True, force=True )
        p1 = cmds.polyPlane()
        p2 = cmds.polyPlane()
        p3 = cmds.polyUnite( p1, p2 )
        cmds.polyMergeVertex( p3, d=0.01 )
        test = tools.geometryMinder.ui.GeometryMinder()
        test.refresh()
        assert len( test.roots() ) == 1
        cmds.file( new=True, force=True )


[QUOTE=Theodox;18111]This sounds more like a job for maya.standalone. You don’t have to worry about synchronicity, exit codes, or that kind of junk and you can debug in a real debugger if your tests seem not to be working.

[/QUOTE]

Thank you for pointing me in the right direction.

After I manage to setup my eclipse using this

http://www.luma-pictures.com/tools/pymel/docs/1.0/eclipse.html

and this

http://old.nabble.com/-Users--Maya-2008-remote-debugging-isn't-working-to30697056.html#a30789352

I got it to work