Skip to content

Commit 7737fda

Browse files
committed
test documentation docstrings
1 parent c488cd9 commit 7737fda

File tree

7 files changed

+282
-225
lines changed

7 files changed

+282
-225
lines changed

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ jobs:
6464
set -xe
6565
pip install --upgrade pip setuptools wheel
6666
pip install -r docs/requirements.txt
67-
- name: Build documentation
67+
- name: Test examples and docstrings
6868
run: |
6969
set -xe
7070
python -VV
71-
cd docs && make clean && make html
71+
make doctest

docs/Makefile

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
# You can set these variables from the command line, and also
55
# from the environment for the first two.
6-
SPHINXOPTS ?=
76
SPHINXBUILD ?= sphinx-build
87
SOURCEDIR = .
98
BUILDDIR = _build
9+
SPHINXOPTS = -d $(BUILDDIR)/doctrees -T
1010

1111
# Put it first so that "make" without argument is like "make help".
1212
help:
1313
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1414

15-
.PHONY: help Makefile
15+
.PHONY: help Makefile doctest
1616

1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
@@ -25,6 +25,11 @@ clean:
2525
rm -rf _autosummary/
2626

2727
html-noplot:
28-
$(SPHINXBUILD) -D plot_gallery=0 -D jupyter_execute_notebooks=off -b html $(ALLSPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
28+
$(SPHINXBUILD) -D plot_gallery=0 -D jupyter_execute_notebooks=off -b html $(SPHINXOPTS) $(SOURCEDIR) $(BUILDDIR)/html
2929
@echo
3030
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
31+
32+
doctest:
33+
$(SPHINXBUILD) -b doctest $(SPHINXOPTS) . $(BUILDDIR)/doctest
34+
@echo "Testing of doctests in the sources finished, look at the " \
35+
"results in $(BUILDDIR)/doctest/output.txt."

docs/conf.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@
5050
'sphinx.ext.napoleon', # napoleon on top of autodoc: https://stackoverflow.com/a/66930447 might correct some warnings
5151
'sphinx.ext.autodoc',
5252
'sphinx.ext.autosummary',
53+
'sphinx.ext.doctest',
5354
'sphinx.ext.intersphinx',
5455
'sphinx.ext.mathjax',
5556
'sphinx.ext.viewcode',
5657
'matplotlib.sphinxext.plot_directive',
5758
'sphinx_autodoc_typehints',
5859
'myst_nb',
59-
"sphinx_remove_toctrees",
60+
'sphinx_remove_toctrees',
6061
'sphinx_rtd_theme',
6162
'sphinx_gallery.gen_gallery',
6263
'sphinx_copybutton',
@@ -70,7 +71,12 @@
7071
"backreferences_dir": os.path.join("modules", "generated"),
7172
}
7273

74+
# Specify how to identify the prompt when copying code snippets
75+
copybutton_prompt_text = r">>> |\.\.\. "
76+
copybutton_prompt_is_regexp = True
77+
copybutton_exclude = "style"
7378

79+
trim_doctests_flags = True
7480
source_suffix = ['.rst', '.ipynb', '.md']
7581

7682
autosummary_generate = True

0 commit comments

Comments
 (0)