2016-07-02 05:15:06 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_ext_todo
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test sphinx.ext.todo extension.
|
|
|
|
|
2017-03-22 06:21:12 -05:00
|
|
|
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
2016-07-02 05:15:06 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2016-07-02 05:15:06 -05:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-todo', freshenv=True,
|
2017-01-25 10:13:17 -06:00
|
|
|
confoverrides={'todo_include_todos': True, 'todo_emit_warnings': True})
|
2016-07-02 05:15:06 -05:00
|
|
|
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'])
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-todo', freshenv=True,
|
2017-01-25 10:13:17 -06:00
|
|
|
confoverrides={'todo_include_todos': False, 'todo_emit_warnings': True})
|
2016-07-02 05:15:06 -05:00
|
|
|
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'])
|