Skip to content

Commit c2558d2

Browse files
author
Mathias Burger
committed
RFC for using sphinx doctest and continously migrating the doctest code to being tested
1 parent 5575cc9 commit c2558d2

File tree

8 files changed

+33
-5
lines changed

8 files changed

+33
-5
lines changed

.github/workflows/_build_test_upload.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ jobs:
504504
run: |
505505
cd ./docs
506506
pip3 install -r requirements.txt
507+
make doctest
507508
make html
508509
cd ..
509510
- name: Export Target Folder

docs/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ BUILDDIR = build
1212
help:
1313
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1414

15-
.PHONY: help Makefile
15+
doctest:
16+
$(SPHINXBUILD) -b doctest $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)"/doctest
17+
@echo "Testing of doctests in the sources finished, look at the " \
18+
"results in $(BUILDDIR)/doctest/output.txt."
19+
20+
.PHONY: help doctest Makefile
1621

1722
# Catch-all target: route all unknown targets to Sphinx using the new
1823
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).

docs/source/conf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@
4848
# Add any Sphinx extension module names here, as strings. They can be
4949
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
5050
# ones.
51-
extensions = ["sphinx.ext.napoleon", "sphinx.ext.autodoc", "sphinx.ext.autosummary", "sphinx.ext.intersphinx"]
51+
extensions = [
52+
"sphinx.ext.napoleon",
53+
"sphinx.ext.autodoc",
54+
"sphinx.ext.autosummary",
55+
"sphinx.ext.intersphinx",
56+
"sphinx.ext.doctest",
57+
]
58+
59+
# Do not execute standard reST doctest blocks so that documentation can
60+
# be successively migrated to sphinx's doctest directive.
61+
doctest_test_doctest_blocks = ""
5262

5363
# Add any paths that contain templates here, relative to this directory.
5464
templates_path = ["_templates"]

test/datapipes/__init__.py

Whitespace-only changes.

test/datapipes/iter/__init__.py

Whitespace-only changes.

test/datapipes/iter/util/__init__.py

Whitespace-only changes.

test/datapipes/iter/util/test_header.py

Whitespace-only changes.

torchdata/dataloader2/adapter.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,21 @@ class Shuffle(Adapter):
5353
- None: No-op. Introduced for backward compatibility.
5454
5555
Example:
56-
>>> dp = IterableWrapper(range(size)).shuffle()
57-
>>> dl = DataLoader2(dp, [Shuffle(False)])
58-
>>> self.assertEqual(list(range(size)), list(dl))
56+
57+
.. testsetup::
58+
59+
from torchdata.datapipes.iter import IterableWrapper
60+
from torchdata.dataloader2 import DataLoader2
61+
from torchdata.dataloader2.adapter import Shuffle
62+
63+
size = 12
64+
65+
.. testcode::
66+
67+
dp = IterableWrapper(range(size)).shuffle()
68+
dl = DataLoader2(dp, [Shuffle(False)])
69+
assert list(range(size)) == list(dl)
70+
5971
"""
6072

6173
def __init__(self, enable=True):

0 commit comments

Comments
 (0)