mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#2680: sphinx.ext.todo now emits warnings if todo_emit_warnings enabled
This commit is contained in:
4
tests/roots/test-ext-todo/bar.rst
Normal file
4
tests/roots/test-ext-todo/bar.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
bar
|
||||
===
|
||||
|
||||
.. todo:: todo in bar
|
||||
4
tests/roots/test-ext-todo/conf.py
Normal file
4
tests/roots/test-ext-todo/conf.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
extensions = ['sphinx.ext.todo']
|
||||
master_doc = 'index'
|
||||
4
tests/roots/test-ext-todo/foo.rst
Normal file
4
tests/roots/test-ext-todo/foo.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
foo
|
||||
===
|
||||
|
||||
.. todo:: todo in foo
|
||||
9
tests/roots/test-ext-todo/index.rst
Normal file
9
tests/roots/test-ext-todo/index.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
test for sphinx.ext.todo
|
||||
========================
|
||||
|
||||
.. toctree::
|
||||
|
||||
foo
|
||||
bar
|
||||
|
||||
.. todolist::
|
||||
85
tests/test_ext_todo.py
Normal file
85
tests/test_ext_todo.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_ext_todo
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Test sphinx.ext.todo extension.
|
||||
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
from util import with_app
|
||||
|
||||
|
||||
@with_app('html', testroot='ext-todo', freshenv=True,
|
||||
confoverrides={'todo_include_todos': True, 'todo_emit_warnings': True})
|
||||
def test_todo(app, status, warning):
|
||||
todos = []
|
||||
|
||||
def on_todo_defined(app, node):
|
||||
todos.append(node)
|
||||
|
||||
app.connect('todo-defined', on_todo_defined)
|
||||
app.builder.build_all()
|
||||
|
||||
# check todolist
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = ('<p class="first admonition-title">Todo</p>\n'
|
||||
'<p class="last">todo in foo</p>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = ('<p class="first admonition-title">Todo</p>\n'
|
||||
'<p class="last">todo in bar</p>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
# check todo
|
||||
content = (app.outdir / 'foo.html').text()
|
||||
html = ('<p class="first admonition-title">Todo</p>\n'
|
||||
'<p class="last">todo in foo</p>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
# check emitted warnings
|
||||
assert 'WARNING: TODO entry found: todo in foo' in warning.getvalue()
|
||||
assert 'WARNING: TODO entry found: todo in bar' in warning.getvalue()
|
||||
|
||||
# check handled event
|
||||
assert len(todos) == 2
|
||||
assert set(todo[1].astext() for todo in todos) == set(['todo in foo', 'todo in bar'])
|
||||
|
||||
|
||||
@with_app('html', testroot='ext-todo', freshenv=True,
|
||||
confoverrides={'todo_include_todos': False, 'todo_emit_warnings': True})
|
||||
def test_todo_not_included(app, status, warning):
|
||||
todos = []
|
||||
|
||||
def on_todo_defined(app, node):
|
||||
todos.append(node)
|
||||
|
||||
app.connect('todo-defined', on_todo_defined)
|
||||
app.builder.build_all()
|
||||
|
||||
# check todolist
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = ('<p class="first admonition-title">Todo</p>\n'
|
||||
'<p class="last">todo in foo</p>')
|
||||
assert not re.search(html, content, re.S)
|
||||
|
||||
html = ('<p class="first admonition-title">Todo</p>\n'
|
||||
'<p class="last">todo in bar</p>')
|
||||
assert not re.search(html, content, re.S)
|
||||
|
||||
# check todo
|
||||
content = (app.outdir / 'foo.html').text()
|
||||
html = ('<p class="first admonition-title">Todo</p>\n'
|
||||
'<p class="last">todo in foo</p>')
|
||||
assert not re.search(html, content, re.S)
|
||||
|
||||
# check emitted warnings
|
||||
assert 'WARNING: TODO entry found: todo in foo' in warning.getvalue()
|
||||
assert 'WARNING: TODO entry found: todo in bar' in warning.getvalue()
|
||||
|
||||
# check handled event
|
||||
assert len(todos) == 2
|
||||
assert set(todo[1].astext() for todo in todos) == set(['todo in foo', 'todo in bar'])
|
||||
Reference in New Issue
Block a user