diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000000..4be9bb19b03c --- /dev/null +++ b/.coveragerc @@ -0,0 +1,9 @@ +[run] +source=matplotlib +[report] +omit = + lib/matplotlib/tests/* + lib/matplotlib/testing/* + +exclude_lines = + raise NotImplemented diff --git a/.gitignore b/.gitignore index 722a42ec6185..2b7d5ec615c7 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,10 @@ result_images *.swp setup.cfg + +# Coverage generated files # +############################ + +.coverage +.coverage.* +cover/ diff --git a/.travis.yml b/.travis.yml index 47931f7680ff..b749e95781ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ env: - PANDAS= - NPROC=2 - TEST_ARGS=--no-pep8 + - NOSE_ARGS="--processes=$NPROC --process-timeout=300" language: python @@ -38,7 +39,7 @@ matrix: env: MOCK=mock NUMPY=numpy==1.6 - python: 3.4 - python: 3.5 - env: PANDAS=pandas + env: PANDAS=pandas NOSE_ARGS=--with-coverage - python: 3.5 env: TEST_ARGS=--pep8 - python: 2.7 @@ -67,19 +68,17 @@ install: pip install $PRE python-dateutil $NUMPY pyparsing!=2.0.4 pillow sphinx!=1.3.0; fi # Always install from pypi - - pip install $PRE pep8 cycler - - 'pip install https://github.com/tacaswell/nose/zipball/mnt_py36_compat#egg=nose' + - pip install $PRE pep8 cycler coveralls coverage + - 'pip install git+https://github.com/jenshnielsen/nose.git@matplotlibnose' # We manually install humor sans using the package from Ubuntu 14.10. Unfortunatly humor sans is not # availible in the Ubuntu version used by Travis but we can manually install the deb from a later # version since is it basically just a .ttf file # The current Travis Ubuntu image is to old to search .local/share/fonts so we store fonts in .fonts - # We install ipython to use the console highlighting. From IPython 3 this depends on jsonschema and mistune. - # Neihter is installed as a dependency of IPython since they are not used by the IPython console. - | if [[ $BUILD_DOCS == true ]]; then - pip install $PRE numpydoc ipython jsonschema mistune + pip install $PRE numpydoc ipython pip install -q $PRE linkchecker wget https://github.com/google/fonts/blob/master/ofl/felipa/Felipa-Regular.ttf?raw=true -O Felipa-Regular.ttf wget http://mirrors.kernel.org/ubuntu/pool/universe/f/fonts-humor-sans/fonts-humor-sans_1.0-1_all.deb @@ -94,17 +93,18 @@ install: cp .travis/setup.cfg . fi; - - python setup.py install + - pip install -e . script: # The number of processes is hardcoded, because using too many causes the # Travis VM to run out of memory (since so many copies of inkscape and # ghostscript are running at the same time). - echo Testing using $NPROC processes + - echo The following args are passed to nose $NOSE_ARGS - | if [[ $BUILD_DOCS == false ]]; then export MPL_REPO_DIR=$PWD # needed for pep8-conformance test of the examples - gdb -return-child-result -batch -ex r -ex bt --args python tests.py --processes=$NPROC --process-timeout=300 $TEST_ARGS + gdb -return-child-result -batch -ex r -ex bt --args python tests.py $NOSE_ARGS $TEST_ARGS else cd doc python make.py html --small --warningsaserrors @@ -165,3 +165,6 @@ after_success: fi fi fi + if [[ $NOSE_ARGS="--with-coverage" ]]; then + coveralls + fi diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index c81cc8106a53..a19dd3c807db 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1529,7 +1529,14 @@ def _get_extra_test_plugins(): return [KnownFailure, attrib.Plugin] -def test(verbosity=1): +def _get_nose_env(): + env = {'NOSE_COVER_PACKAGE': 'matplotlib', + 'NOSE_COVER_HTML': 1, + 'NOSE_COVER_NO_PRINT': 1} + return env + + +def test(verbosity=1, coverage=False): """run the matplotlib test suite""" _init_tests() @@ -1553,9 +1560,14 @@ def test(verbosity=1): # a list. multiprocess._instantiate_plugins = plugins + env = _get_nose_env() + if coverage: + env['NOSE_WITH_COVERAGE'] = 1 + success = nose.run( defaultTest=default_test_modules, config=config, + env=env, ) finally: if old_backend.lower() != 'agg': diff --git a/tests.py b/tests.py index 529dbe70d112..87a6f8ba6601 100755 --- a/tests.py +++ b/tests.py @@ -23,6 +23,8 @@ def run(extra_args): from nose.plugins import multiprocess + env = matplotlib._get_nose_env() + matplotlib._init_tests() # Nose doesn't automatically instantiate all of the plugins in the @@ -33,8 +35,8 @@ def run(extra_args): nose.main(addplugins=[x() for x in plugins], defaultTest=default_test_modules, - argv=sys.argv + extra_args) - + argv=sys.argv + extra_args, + env=env) if __name__ == '__main__': extra_args = []