Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Setup test and coverage harness
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Nov 12, 2017
1 parent 477d21f commit 4df24f1
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
@@ -0,0 +1,5 @@
[run]
source = scripts

[report]
include = scripts/*
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -51,3 +51,4 @@ excons.cache
/mGear.mod


cover/
13 changes: 13 additions & 0 deletions .travis.yml
@@ -0,0 +1,13 @@
language: python

python:
- 2.7

services:
- docker

install:
- docker build -t mgear .

script:
- docker run -ti --rm -v $(pwd):/workspace mgear
19 changes: 19 additions & 0 deletions Dockerfile
@@ -0,0 +1,19 @@
FROM mottosso/maya:2016sp1

RUN wget https://bootstrap.pypa.io/get-pip.py && \
mayapy get-pip.py && \
mayapy -m pip install \
nose \
nose-exclude \
coverage \
sphinx \
six \
sphinxcontrib-napoleon \
python-coveralls

# Avoid creation of auxilliary files
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR /workspace

ENTRYPOINT mayapy -u run_tests.py
102 changes: 102 additions & 0 deletions run_tests.py
@@ -0,0 +1,102 @@
"""Use Mayapy for testing
Usage:
$ mayapy run_tests.py
"""

import os
import sys
import nose
import logging
import contextlib

import six

from maya import standalone
from nose_exclude import NoseExclude


def null(*args, **kwargs):
pass


@contextlib.contextmanager
def mute():
try:
sys.stdout = six.moves.StringIO()
sys.stderr = six.moves.StringIO()
yield

finally:
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__


if __name__ == "__main__":
# Expose mgear Python package to tests
dirname = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(dirname, "scripts"))

print("Initialising Maya..")
with mute():
standalone.initialize()
import pymel.core
import pymel.internal.startup
pymel.internal.startup.fixMayapy2011SegFault()

for name, logger in logging.Logger.manager.loggerDict.items():
if "pymel" in name:
logger.disabled = True

argv = sys.argv[:]
argv.extend([

# Sometimes, files from Windows accessed
# from Linux cause the executable flag to be
# set, and Nose has an aversion to these
# per default.
"--exe",

# Produce nice, easily readable output from each test
"--verbose",

# Run through the docstring of every module
# and run anything prefixed with ">>> "
"--with-doctest",

# Produce a coverage report post-tests
"--with-coverage",
"--cover-html",
"--cover-tests",
"--cover-erase",

"--exclude-dir=cvwrap",
"--exclude-dir=docs",
"--exclude-dir=excons",
"--exclude-dir=src",

"tests",
"scripts",
])

# Visually separate output from the above Maya initialisation
# and the actual tests.
# TODO: Mute Maya output entirely; I don't know how it manages to still
# output anything when sys.stdout and err are discarded..
print("\n" + "-" * 70)
print("Running tests..\n")

try:
# Disable messages via PyMEL, they obfuscate the report
pymel.core.displayWarning = null
pymel.core.displayError = null

nose.main(argv=argv, addplugins=[NoseExclude()])

finally:
# Only bother when running when on Travis
if os.getenv("TRAVIS_JOB_ID"):
__import__("coveralls").wear()
else:
sys.stdout.write("Skipping coveralls\n")

0 comments on commit 4df24f1

Please sign in to comment.