diff --git a/.gitignore b/.gitignore index 9ec2e265b..37dbb588d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,10 @@ MANIFEST *.so *.c autograd.egg-info/ + +# Unit test / coverage reports +htmlcov/ +.coverage +.coverage.* +coverage.xml +*,cover diff --git a/.travis.yml b/.travis.yml index 191d57fad..68cbf7ceb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ before_install: - conda update --yes conda - conda config --add channels conda-forge install: - - conda install --yes python=$TRAVIS_PYTHON_VERSION pip numpy scipy nose future + - conda install --yes python=$TRAVIS_PYTHON_VERSION pip numpy scipy nose future coveralls - pip install -v . script: nosetests tests +after_success: + - coveralls diff --git a/autograd/util.py b/autograd/util.py index 1be8d179a..0e6e0bfb5 100644 --- a/autograd/util.py +++ b/autograd/util.py @@ -14,6 +14,11 @@ from copy import copy EPS, RTOL, ATOL = 1e-4, 1e-4, 1e-6 +COVERAGE_CHECKING = False + +if COVERAGE_CHECKING: + import coverage + cover = coverage.Coverage() def nd(f, *args): unary_f = lambda x : f(*x) @@ -54,12 +59,18 @@ def check_equivalent(A, B, rtol=RTOL, atol=ATOL): A_flat - B_flat, A_flat, B_flat) def check_grads(fun, *args): + if COVERAGE_CHECKING: + cover.load() + cover.start() if not args: raise Exception("No args given") exact = tuple([grad(fun, i)(*args) for i in range(len(args))]) args = [float(x) if isinstance(x, int) else x for x in args] numeric = nd(fun, *args) check_equivalent(exact, numeric) + if COVERAGE_CHECKING: + cover.stop() + cover.save() def to_scalar(x): if isinstance(getval(x), list) or isinstance(getval(x), tuple): diff --git a/tests/numpy_utils.py b/tests/numpy_utils.py index c6b90179d..18a3961d3 100644 --- a/tests/numpy_utils.py +++ b/tests/numpy_utils.py @@ -6,6 +6,8 @@ from autograd.util import check_equivalent, check_grads, to_scalar from builtins import range import warnings +import coverage +cover = coverage.Coverage() test_complex = True @@ -21,6 +23,8 @@ def combo_check(fun, argnums, *args, **kwargs): print(".", end=' ') def check_fun_and_grads(fun, args, kwargs, argnums): + cover.load() + cover.start() wrt_args = [args[i] for i in argnums] try: if isinstance(fun, primitive): @@ -54,6 +58,8 @@ def d_scalar_fun(*args): except: print("Second derivative test failed! Args were", args, kwargs) raise + cover.stop() + cover.save() def stat_check(fun, test_complex=test_complex): # Tests functions that compute statistics, like sum, mean, etc