Skip to content

Commit cae3c87

Browse files
committed
ENH: Test full output and coverage
1 parent b031883 commit cae3c87

File tree

10 files changed

+176
-2
lines changed

10 files changed

+176
-2
lines changed

.coveragerc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[run]
2+
branch = True
3+
source = numpydoc
4+
include = */numpydoc/*
5+
omit =
6+
*/setup.py

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ doc/_build
1313
build
1414
dist
1515
doc/_build
16+
numpydoc/tests/tinybuild/_build
17+
numpydoc/tests/tinybuild/generated

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cache:
1515
before_install:
1616
- sudo apt-get install texlive texlive-latex-extra latexmk
1717
- pip install --upgrade pip setuptools # Upgrade pip and setuptools to get ones with `wheel` support
18-
- pip install pytest pytest-cov numpy matplotlib sphinx${SPHINX_SPEC}
18+
- pip install pytest pytest-cov pytest-sugar numpy matplotlib sphinx${SPHINX_SPEC} codecov
1919
script:
2020
- |
2121
python setup.py sdist
@@ -26,3 +26,7 @@ script:
2626
cd ../doc
2727
make SPHINXOPTS=$SPHINXOPTS html
2828
make SPHINXOPTS=$SPHINXOPTS latexpdf
29+
after_script:
30+
- |
31+
cd ../dist
32+
codecov

codecov.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
coverage:
2+
precision: 2
3+
round: down
4+
range: "70...100"
5+
status:
6+
project:
7+
default:
8+
target: auto
9+
threshold: 0.01
10+
patch: false
11+
changes: false
12+
comment:
13+
layout: "header, diff, sunburst, uncovered"
14+
behavior: default

numpydoc/tests/test_full.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from io import StringIO
2+
import os.path as op
3+
import shutil
4+
5+
import pytest
6+
from sphinx.application import Sphinx
7+
from sphinx.util.docutils import docutils_namespace
8+
9+
10+
# Test framework adapted from sphinx-gallery
11+
@pytest.fixture(scope='module')
12+
def sphinx_app(tmpdir_factory):
13+
temp_dir = (tmpdir_factory.getbasetemp() / 'root').strpath
14+
src_dir = op.join(op.dirname(__file__), 'tinybuild')
15+
16+
def ignore(src, names):
17+
return ('_build', 'generated')
18+
19+
shutil.copytree(src_dir, temp_dir, ignore=ignore)
20+
# For testing iteration, you can get similar behavior just doing `make`
21+
# inside the tinybuild directory
22+
src_dir = temp_dir
23+
conf_dir = temp_dir
24+
out_dir = op.join(temp_dir, '_build', 'html')
25+
toctrees_dir = op.join(temp_dir, '_build', 'toctrees')
26+
# Avoid warnings about re-registration, see:
27+
# https://github.com/sphinx-doc/sphinx/issues/5038
28+
with docutils_namespace():
29+
app = Sphinx(src_dir, conf_dir, out_dir, toctrees_dir,
30+
buildername='html', status=StringIO())
31+
# need to build within the context manager
32+
# for automodule and backrefs to work
33+
app.build(False, [])
34+
return app
35+
36+
37+
def test_class(sphinx_app):
38+
"""Test that class documentation is reasonable."""
39+
src_dir, out_dir = sphinx_app.srcdir, sphinx_app.outdir
40+
class_rst = op.join(src_dir, 'generated', 'nd_test_mod.MyClass.rst')
41+
with open(class_rst, 'r') as fid:
42+
rst = fid.read()
43+
assert r'nd\_test\_mod.MyClass' in rst # properly escaped
44+
class_html = op.join(out_dir, 'generated', 'nd_test_mod.MyClass.html')
45+
with open(class_html, 'r') as fid:
46+
html = fid.read()
47+
# escaped * chars should no longer be preceded by \'s
48+
assert r'\*' in html # XXX should be "not in", bug!
49+
assert 'self,' in html # XXX should be "not in", bug!
50+
51+
52+
def test_function(sphinx_app):
53+
"""Test that a timings page is created."""
54+
out_dir = sphinx_app.outdir
55+
function_html = op.join(out_dir, 'generated',
56+
'nd_test_mod.my_function.html')
57+
with open(function_html, 'r') as fid:
58+
html = fid.read()
59+
assert r'\*args' not in html
60+
assert '*args' in html

numpydoc/tests/tinybuild/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
all: clean html show
2+
3+
clean:
4+
rm -rf _build/*
5+
rm -rf generated/
6+
7+
html:
8+
sphinx-build -b html -d _build/doctrees . _build/html
9+
10+
show:
11+
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(PWD)/_build/html/index.html')"

numpydoc/tests/tinybuild/conf.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import sys
3+
path = os.path.dirname(__file__)
4+
if path not in sys.path:
5+
sys.path.insert(0, path)
6+
import nd_test_mod # noqa
7+
extensions = [
8+
'sphinx.ext.autodoc',
9+
'sphinx.ext.intersphinx',
10+
'numpydoc',
11+
]
12+
project = 'nd_test_mod'
13+
autosummary_generate = True
14+
source_suffix = '.rst'
15+
master_doc = 'index'
16+
exclude_patterns = ['_build']
17+
intersphinx_mapping = {
18+
'python': ('https://docs.python.org/3', None),
19+
}
20+
nitpicky = True
21+
highlight_language = 'python3'
22+
numpydoc_xref_param_type = True

numpydoc/tests/tinybuild/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
nd_test_mod
2+
===========
3+
4+
.. automodule:: nd_test_mod
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Numpdoc test module.
2+
3+
.. currentmodule:: nd_test_mod
4+
5+
.. autosummary::
6+
:toctree: generated/
7+
8+
MyClass
9+
my_function
10+
"""
11+
12+
__all__ = ['MyClass', 'my_function']
13+
14+
15+
class MyClass(object):
16+
"""A class.
17+
18+
Parameters
19+
----------
20+
*args : iterable
21+
Arguments.
22+
**kwargs : dict
23+
Keyword arguments.
24+
"""
25+
26+
def __init__(self, *args, **kwargs):
27+
pass
28+
29+
30+
def my_function(*args, **kwargs):
31+
"""Return None.
32+
33+
See [1]_.
34+
35+
Parameters
36+
----------
37+
*args : iterable
38+
Arguments.
39+
**kwargs : dict
40+
Keyword arguments.
41+
42+
Returns
43+
-------
44+
out : None
45+
The output.
46+
47+
References
48+
----------
49+
.. [1] https://numpydoc.readthedocs.io
50+
"""
51+
return None

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ addopts =
33
--showlocals --doctest-modules -ra --cov-report= --cov=numpydoc
44
--junit-xml=junit-results.xml --ignore=doc/conf.py
55
filterwarnings =
6+
ignore:'U' mode is deprecated:DeprecationWarning
67
ignore:Using or importing the ABCs.*:DeprecationWarning
7-

0 commit comments

Comments
 (0)