diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80911c558..9fbec1efa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,12 @@ jobs: BUILD_S3: 1 - name: Install test requirements run: pip3 install -r test/requirements.txt + - name: Test documentation examples + run: | + cd ./docs + pip3 install -r requirements.txt + make doctest + cd .. - name: Run DataPipes tests with pytest if: ${{ ! contains(github.event.pull_request.labels.*.name, 'ciflow/slow') }} run: diff --git a/docs/Makefile b/docs/Makefile index d0c3cbf10..1e84df4e5 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -12,7 +12,12 @@ BUILDDIR = build help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -.PHONY: help Makefile +doctest: html + $(SPHINXBUILD) -b doctest $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)"/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: help doctest Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). diff --git a/docs/source/conf.py b/docs/source/conf.py index cc11b1a3a..1a179cfe0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -48,7 +48,17 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ["sphinx.ext.napoleon", "sphinx.ext.autodoc", "sphinx.ext.autosummary", "sphinx.ext.intersphinx"] +extensions = [ + "sphinx.ext.napoleon", + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.doctest", +] + +# Do not execute standard reST doctest blocks so that documentation can +# be successively migrated to sphinx's doctest directive. +doctest_test_doctest_blocks = "" # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] diff --git a/torchdata/dataloader2/adapter.py b/torchdata/dataloader2/adapter.py index 1c1236791..f155feb2b 100644 --- a/torchdata/dataloader2/adapter.py +++ b/torchdata/dataloader2/adapter.py @@ -53,9 +53,21 @@ class Shuffle(Adapter): - None: No-op. Introduced for backward compatibility. Example: - >>> dp = IterableWrapper(range(size)).shuffle() - >>> dl = DataLoader2(dp, [Shuffle(False)]) - >>> self.assertEqual(list(range(size)), list(dl)) + + .. testsetup:: + + from torchdata.datapipes.iter import IterableWrapper + from torchdata.dataloader2 import DataLoader2 + from torchdata.dataloader2.adapter import Shuffle + + size = 12 + + .. testcode:: + + dp = IterableWrapper(range(size)).shuffle() + dl = DataLoader2(dp, [Shuffle(False)]) + assert list(range(size)) == list(dl) + """ def __init__(self, enable=True):