Skip to content

Commit aa290a1

Browse files
authored
ENH: Test full output and coverage (#230)
* ENH: Test full output and coverage * FIX: Add new files to setup.py * ENH: dvipng * FIX: Cleaner test * ENH: Update * BUG: Remove StringIO * STY: Better naming and explanations
1 parent b031883 commit aa290a1

File tree

11 files changed

+193
-6
lines changed

11 files changed

+193
-6
lines changed

.coveragerc

+6
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

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ doc/_build
1313
build
1414
dist
1515
doc/_build
16+
numpydoc/tests/tinybuild/_build
17+
numpydoc/tests/tinybuild/generated
18+
MANIFEST

.travis.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ cache:
1313
directories:
1414
- $HOME/.cache/pip
1515
before_install:
16-
- sudo apt-get install texlive texlive-latex-extra latexmk
16+
- sudo apt-get install texlive texlive-latex-extra latexmk dvipng
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 numpy matplotlib sphinx${SPHINX_SPEC} codecov
1919
script:
2020
- |
2121
python setup.py sdist
2222
cd dist
2323
pip install numpydoc* -v
24-
- pytest --pyargs numpydoc
24+
- pytest -v --pyargs numpydoc
2525
- |
2626
cd ../doc
2727
make SPHINXOPTS=$SPHINXOPTS html
2828
make SPHINXOPTS=$SPHINXOPTS latexpdf
29+
after_script:
30+
- |
31+
cd ../dist
32+
codecov

codecov.yml

+14
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

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

numpydoc/tests/tinybuild/Makefile

+11
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

+22
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 numpydoc_test_module # noqa
7+
extensions = [
8+
'sphinx.ext.autodoc',
9+
'sphinx.ext.intersphinx',
10+
'numpydoc',
11+
]
12+
project = 'numpydoc_test_module'
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

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
numpydoc_test_module
2+
====================
3+
4+
.. automodule:: numpydoc_test_module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Numpydoc test module.
2+
3+
.. currentmodule:: numpydoc_test_module
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

+1-1
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-

setup.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ def read(fname):
4848
url="https://numpydoc.readthedocs.io",
4949
license="BSD",
5050
install_requires=["sphinx >= 1.6.5", 'Jinja2>=2.3'],
51-
package_data={'numpydoc': ['tests/test_*.py', 'templates/*.rst']},
52-
test_suite = 'nose.collector',
51+
package_data={'numpydoc': [
52+
'tests/test_*.py',
53+
'tests/tinybuild/Makefile',
54+
'tests/tinybuild/index.rst',
55+
'tests/tinybuild/*.py',
56+
'templates/*.rst',
57+
]},
5358
cmdclass={"sdist": sdist},
5459
)

0 commit comments

Comments
 (0)