-
Notifications
You must be signed in to change notification settings - Fork 10
/
devTest.py
101 lines (71 loc) · 2.44 KB
/
devTest.py
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
try:
import wingdbstub
except ImportError: pass
from filesystem import Path
from unittest import TestCase, TestResult
from maya import cmds as cmd
import sys
import inspect
### POPULATE THE LIST OF TEST SCRIPTS ###
TEST_SCRIPTS = {}
def populateTestScripts():
global TEST_SCRIPTS
thisScriptDir = Path( __file__ ).up()
pathsToSearch = sys.path[:] + [ thisScriptDir ]
for pyPath in pathsToSearch:
pyPath = Path( pyPath )
if pyPath.isDir():
for f in pyPath.files():
if f.hasExtension( 'py' ):
if f.name().startswith( 'devTest_' ):
TEST_SCRIPTS[ f ] = []
populateTestScripts()
### POPULATE TEST_CASES ###
TEST_CASES = []
def populateTestCases():
global TEST_CASES
for script in TEST_SCRIPTS:
testModule = __import__( script.name() )
scriptTestCases = TEST_SCRIPTS[ script ] = []
for name, obj in testModule.__dict__.iteritems():
if obj is TestCase:
continue
if isinstance( obj, type ):
if issubclass( obj, TestCase ):
if obj.__name__.startswith( '_' ):
continue
TEST_CASES.append( obj )
scriptTestCases.append( obj )
populateTestCases()
def runTestCases( testCases=TEST_CASES ):
thisPath = Path( __file__ ).up()
testResults = TestResult()
reloadedTestCases = []
for test in testCases:
#find the module the test comes from
module = inspect.getmodule( test )
performReload = getattr( module, 'PERFORM_RELOAD', True )
#reload the module the test comes from
if performReload:
module = reload( module )
#find the test object inside the newly re-loaded module and append it to the reloaded tests list
reloadedTestCases.append( getattr( module, test.__name__ ) )
for ATestCase in reloadedTestCases:
testCase = ATestCase()
testCase.run( testResults )
#force a new scene
cmd.file( new=True, f=True )
OK = 'Ok'
BUTTONS = (OK,)
if testResults.errors:
print '------------- THE FOLLOWING ERRORS OCCURRED -------------'
for error in testResults.errors:
print error[0]
print error[1]
print '--------------------------'
cmd.confirmDialog( t='TEST ERRORS OCCURRED!', m='Errors occurred running the tests - see the script editor for details!', b=BUTTONS, db=OK )
else:
print '------------- %d TESTS WERE RUN SUCCESSFULLY -------------' % len( testCases )
cmd.confirmDialog( t='SUCCESS!', m='All tests were successful!', b=BUTTONS, db=OK )
return testResults
#end