Sunday, July 3, 2016

Maya Picture in Picture Tool (PiP) Development Part 2

I haven't had too much time to devote to getting PiP fully complete in a while - I am to a point now where I would like to put up a beta download and see what kind of feedback I get for improvements.

pip_tool.zip


Just unzip the pip_tool folder to your Maya python path (example, your documents/maya/scripts/ folder).  The code to launch the tool, from a Python tab in the Maya script Editor...


1
2
import pip_tool.pip as PiP
PiP.jbPiP_UI()


This can be dragged to a shelf for later use.


I recently posted about my exploration with unit tests, I wanted to also post some of my early work with unit testing for PiP.  I feel like most folks who are early on in their learning path with unit tests would benefit from seeing examples of what kinds of things to test for.  This isn't my most current test library for PiP but it should get the point across...



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
"""
Jason Breneman

unittest_pip.py

This file contains the unit test library for the Picture in Picture tool.  Some unit tests
do not pass specifically due to launching Maya through a standalone session.

"""

# maya libraries
import maya.standalone
import maya.cmds as cmds

try:
    maya.standalone.initialize()
    
except:
    pass

# python libraries
import unittest
import os
import uuid
import shutil
import logging

logging.basicConfig( level=logging.INFO )
logger = logging.getLogger( __name__ )
logger.info( "PiP Unit Test starting...\n" )

MAYA_VERSION = cmds.about( version=True )
MAYA_APP_DIR = os.environ["MAYA_APP_DIR"]
ROOT_DEV_DIR = sys.path[0].replace( "\\", "/" ).replace( "/pip_tool/tests", "" )
ROOT_TOOL_PATH = MAYA_APP_DIR + "/scripts"

logger.info( "'Maya Version' : " + MAYA_VERSION  + "\n" )
logger.info( "'MAYA_APP_DIR' : " + MAYA_APP_DIR + "\n" )


class TestLibrary( unittest.TestCase ):
    """
    Test Library
    
    unit test class for Picture in Picture tool
    
    """

    
    def setUp( self ):
        """
        Method to provide any standard setup instructions for a test case function
        
        Args:
            self (object) : reference to the TestLibrary class instance
            
        Returns:
            None
            
        """
        
        pass
        
        
    def tearDown( self ):
        """
        Method to provide any standard tear down instructions for a test case function
        
        Args:
            self (object) : reference to the TestLibrary class instance
            
        Returns:
            None
            
        """
        
        pass
    
    
    def test_files_installed_check( self ):
        """
        Test method for copying files from the development environment to the 
        MAYA_APP_DIR path
        
        Args:
            self (object) : reference to the TestLibrary class instance
            
        Returns:
            None
            
        """
        
        logger.info( "*** TestCase *** Remove existing install, and apply a fresh install\n" )
        
        if os.path.exists( ROOT_TOOL_PATH + "/pip_tool" ):
            shutil.rmtree( ROOT_TOOL_PATH + "/pip_tool" )

        shutil.copytree( ROOT_DEV_DIR + "/pip_tool", ROOT_TOOL_PATH + "/pip_tool" )
        
        
    def test_import_check( self ):
        """
        Test method to check for a successful module import
        
        Args:
            self (object) : reference to the TestLibrary class instance
            
        Returns:
            None
            
        """
        logger.info( "*** TestCase *** Import pip_tool module\n" )
        
        import_success = False
        error_message = "TestCase Failure, PiP module did not import correctly.\n"
        
        try:
            import pip_tool.pip as PiP
            import_success = True
            
        except:
            pass
            
        self.assertTrue( import_success, error_message )

        
        
    def test_pip_instance( self ):
        """
        Test method to check a successful instantiation of PiP
        
        Args:
            self (object) : reference to the TestLibrary class instance
            
        Returns:
            None
            
        """
        
        logger.info( "*** TestCase *** Load a PiP instance\n" )
        
        import pip_tool.pip as PiP
        reload( PiP )
        loadout = PiP.jbPiP_UI()
        
        loadout_exists = cmds.modelEditor( loadout.name_instance + "__ME", 
                                           query=True, 
                                           exists=True )
        error_message = "TestCase Failure, PiP loadout does not exist.  Maya UI required for successful TestCase\n"
        self.assertTrue( loadout_exists, error_message )
        
        
    def test_pip_callback_newscene( self ):
        """
        Test method to check if the new scene callback gets properly deleted when
        a new scene event occurs
        
        Args:
            self (object) : reference to the TestLibrary class instance
            
        Returns:
            None
            
        """
        
        logger.info( "*** TestCase *** Delete PiP on New Scene Callback\n" )
        
        import pip_tool.pip as PiP
        reload( PiP )
        loadout = PiP.jbPiP_UI()
                
        cmds.file( new=True, force=True )
        
        self.assertEquals( loadout.newscene_callbackid, None )


# if starting from a command prompt, load unit test class instance
if __name__ == "__main__":
    unittest.main()

From these examples, you can see I started with testing the results of early development stages such as moving files from my development path to the Maya script path, or just a simple import check, UI loading checks, etc.  Kind of a neat thing to note here is my unit tests are being ran from the windows command line to launch a standalone Maya session (no UI).  The problem with this is PiP is a UI based tool, so as I kept developing more tests I realized I could run some tests in command line but to run some specific tests I would need a normal Maya session.

The current beta release seems to have a few graphical glitches on certain computer setups - that and a few other "nice to haves" are the known issues that I am wanting to polish before I consider it complete. Anyway, that's all for now!

No comments:

Post a Comment