瀏覽代碼

WIP: Sphinx autodoc picks up tasks automatically only if `undoc-members` is set (#4584)

* Add unit test for celery.contrib.sphinx

Note that this unit test reveals a bug: tasks are documented
automatically (e.g. without explicitly adding a `.. autotask::`
line) only if the `undoc-members` option is set. Try removing
'`undoc-members'` from `autodoc_default_flags` in conf.py, and
the test will fail!

* WIP: Remove undoc-members in test_sphinx
Leo Singer 7 年之前
父節點
當前提交
7726bc7426
共有 5 個文件被更改,包括 41 次插入1 次删除
  1. 1 1
      MANIFEST.in
  2. 10 0
      t/unit/contrib/proj/conf.py
  3. 1 0
      t/unit/contrib/proj/contents.rst
  4. 10 0
      t/unit/contrib/proj/foo.py
  5. 19 0
      t/unit/contrib/test_sphinx.py

+ 1 - 1
MANIFEST.in

@@ -7,7 +7,7 @@ include TODO
 include setup.cfg
 include setup.py
 
-recursive-include t *.py
+recursive-include t *.py *.rst
 recursive-include docs *
 recursive-include extra/bash-completion *
 recursive-include extra/centos *

+ 10 - 0
t/unit/contrib/proj/conf.py

@@ -0,0 +1,10 @@
+from __future__ import absolute_import, unicode_literals
+
+import os
+import sys
+
+extensions = ['celery.contrib.sphinx', 'sphinx.ext.autodoc']
+autodoc_default_flags = ['members']
+autosummary_generate = True
+
+sys.path.insert(0, os.path.abspath('.'))

+ 1 - 0
t/unit/contrib/proj/contents.rst

@@ -0,0 +1 @@
+.. automodule:: foo

+ 10 - 0
t/unit/contrib/proj/foo.py

@@ -0,0 +1,10 @@
+from __future__ import absolute_import, unicode_literals
+
+from celery import Celery
+
+app = Celery()
+
+
+@app.task
+def bar():
+    """This task has a docstring!"""

+ 19 - 0
t/unit/contrib/test_sphinx.py

@@ -0,0 +1,19 @@
+from __future__ import absolute_import, unicode_literals
+
+import pkg_resources
+import pytest
+
+try:
+    sphinx_build = pkg_resources.load_entry_point(
+        'sphinx', 'console_scripts', 'sphinx-build')
+except pkg_resources.DistributionNotFound:
+    sphinx_build = None
+
+
+@pytest.mark.skipif(sphinx_build is None, reason='Sphinx is not installed')
+def test_sphinx(tmpdir):
+    srcdir = pkg_resources.resource_filename(__name__, 'proj')
+    sphinx_build([srcdir, str(tmpdir)])
+    with open(tmpdir / 'contents.html', 'r') as f:
+        contents = f.read()
+    assert 'This task has a docstring!' in contents