Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The testing tools will allow me to easily run unit tests as tools are written.
- Loading branch information
Showing
24 changed files
with
3,475 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.mll filter=lfs diff=lfs merge=lfs -text | ||
*.bundle filter=lfs diff=lfs merge=lfs -text | ||
*.so filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,6 @@ target/ | |
|
||
#Ipython Notebook | ||
.ipynb_checkpoints | ||
|
||
# PyCharm | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# cmt | ||
Various maya tools that I write for my personal projects. | ||
cmt is a collection of various Maya tools I have written for my personal projects. | ||
|
||
* Unit test runner for Maya tools. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
""" | ||
Command-line unit test runner for mayapy. | ||
This can be used to run tests from a commandline environment like on a build server. | ||
Usage: | ||
python runmayatests.py -m 2016 | ||
""" | ||
import argparse | ||
import os | ||
import platform | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
import uuid | ||
|
||
CMT_ROOT_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) | ||
|
||
|
||
def get_maya_location(maya_version): | ||
""" | ||
Get the location where Maya is installed. | ||
@param maya_version The maya version number. | ||
@return The path to where Maya is installed. | ||
""" | ||
if 'MAYA_LOCATION' in os.environ.keys(): | ||
return os.environ['MAYA_LOCATION'] | ||
if platform.system() == 'Windows': | ||
return 'C:/Program Files/Autodesk/Maya{0}'.format(maya_version) | ||
elif platform.system() == 'Darwin': | ||
return '/Applications/Autodesk/maya{0}/Maya.app/Contents'.format(maya_version) | ||
else: | ||
location = '/usr/autodesk/maya{0}'.format(maya_version) | ||
if maya_version < 2016: | ||
# Starting Maya 2016, the default install directory name changed. | ||
location += '-x64' | ||
return location | ||
|
||
|
||
def mayapy(maya_version): | ||
""" | ||
Get the mayapy executable path. | ||
@param maya_version The maya version number. | ||
@return: The mayapy executable path. | ||
""" | ||
python_exe = '{0}/bin/mayapy'.format(get_maya_location(maya_version)) | ||
if platform.system() == 'Windows': | ||
python_exe += '.exe' | ||
return python_exe | ||
|
||
|
||
def create_clean_maya_app_dir(): | ||
""" | ||
Creates a copy of the clean Maya preferences so we can create predictable results. | ||
@return: The path to the clean MAYA_APP_DIR folder. | ||
""" | ||
app_dir = os.path.join(CMT_ROOT_DIR, 'tests', 'clean_maya_app_dir') | ||
temp_dir = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) | ||
if not os.path.exists(temp_dir): | ||
os.makedirs(temp_dir) | ||
dst = os.path.join(temp_dir, 'maya_app_dir') | ||
shutil.copytree(app_dir, dst) | ||
return dst | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Runs unit tests for a Maya module') | ||
parser.add_argument('-m', '--maya', | ||
help='Maya version', | ||
type=int, | ||
default=2016) | ||
pargs = parser.parse_args() | ||
mayaunittest = os.path.join(CMT_ROOT_DIR, 'scripts', 'cmt', 'mayaunittest.py') | ||
cmd = [mayapy(pargs.maya), mayaunittest] | ||
if not os.path.exists(cmd[0]): | ||
raise RuntimeError('Maya {0} is not installed on this system.'.format(pargs.maya)) | ||
|
||
maya_app_dir = create_clean_maya_app_dir() | ||
# Create clean prefs | ||
os.environ['MAYA_APP_DIR'] = maya_app_dir | ||
# Clear out any MAYA_SCRIPT_PATH value so we know we're in a clean env. | ||
os.environ['MAYA_SCRIPT_PATH'] = '' | ||
# Run the tests in this module. | ||
os.environ['MAYA_MODULE_PATH'] = CMT_ROOT_DIR | ||
try: | ||
subprocess.check_call(cmd) | ||
except subprocess.CalledProcessError: | ||
pass | ||
finally: | ||
shutil.rmtree(maya_app_dir) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
+ MAYAVERSION:2016 cmt 1.0.0 ./ |
Empty file.
Oops, something went wrong.