2016-07-02 05:15:06 -05:00
|
|
|
"""Test sphinx.ext.todo extension."""
|
|
|
|
|
|
|
|
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
|
2022-04-26 21:04:19 -05:00
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in foo</p>') in content
|
2016-07-02 05:15:06 -05:00
|
|
|
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in bar</p>') in content
|
2016-07-02 05:15:06 -05:00
|
|
|
|
|
|
|
# check todo
|
2022-04-26 21:04:19 -05:00
|
|
|
content = (app.outdir / 'foo.html').read_text(encoding='utf8')
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in foo</p>') in content
|
2016-07-02 05:15:06 -05:00
|
|
|
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in param field</p>') in content
|
2018-12-21 10:08:59 -06:00
|
|
|
|
2016-07-02 05:15:06 -05:00
|
|
|
# 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
|
2018-12-21 10:08:59 -06:00
|
|
|
assert len(todos) == 3
|
2019-03-17 14:49:36 -05:00
|
|
|
assert {todo[1].astext() for todo in todos} == {'todo in foo',
|
|
|
|
'todo in bar',
|
|
|
|
'todo in param field'}
|
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': 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
|
2022-04-26 21:04:19 -05:00
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in foo</p>') not in content
|
2016-07-02 05:15:06 -05:00
|
|
|
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in bar</p>') not in content
|
2016-07-02 05:15:06 -05:00
|
|
|
|
|
|
|
# check todo
|
2022-04-26 21:04:19 -05:00
|
|
|
content = (app.outdir / 'foo.html').read_text(encoding='utf8')
|
2019-03-24 03:32:08 -05:00
|
|
|
assert ('<p class="admonition-title">Todo</p>\n'
|
|
|
|
'<p>todo in foo</p>') not in content
|
2016-07-02 05:15:06 -05:00
|
|
|
|
|
|
|
# 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
|
2018-12-21 10:08:59 -06:00
|
|
|
assert len(todos) == 3
|
2019-03-17 14:49:36 -05:00
|
|
|
assert {todo[1].astext() for todo in todos} == {'todo in foo',
|
|
|
|
'todo in bar',
|
|
|
|
'todo in param field'}
|
2017-10-14 16:34:48 -05:00
|
|
|
|
2017-12-23 06:20:32 -06:00
|
|
|
|
2017-10-14 16:34:48 -05:00
|
|
|
@pytest.mark.sphinx('latex', testroot='ext-todo', freshenv=True,
|
2017-11-05 15:58:27 -06:00
|
|
|
confoverrides={'todo_include_todos': True})
|
2017-10-14 16:34:48 -05:00
|
|
|
def test_todo_valid_link(app, status, warning):
|
|
|
|
"""
|
|
|
|
Test that the inserted "original entry" links for todo items have a target
|
|
|
|
that exists in the LaTeX output. The target was previously incorrectly
|
|
|
|
omitted (GitHub issue #1020).
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Ensure the LaTeX output is built.
|
|
|
|
app.builder.build_all()
|
|
|
|
|
2022-04-26 21:04:19 -05:00
|
|
|
content = (app.outdir / 'python.tex').read_text(encoding='utf8')
|
2017-10-14 16:34:48 -05:00
|
|
|
|
2017-11-05 15:48:43 -06:00
|
|
|
# Look for the link to foo. Note that there are two of them because the
|
|
|
|
# source document uses todolist twice. We could equally well look for links
|
|
|
|
# to bar.
|
2019-03-24 02:35:20 -05:00
|
|
|
link = (r'{\\hyperref\[\\detokenize{(.*?foo.*?)}]{\\sphinxcrossref{'
|
2019-03-24 03:32:08 -05:00
|
|
|
r'\\sphinxstyleemphasis{original entry}}}}')
|
2017-10-14 16:34:48 -05:00
|
|
|
m = re.findall(link, content)
|
2018-12-21 10:08:59 -06:00
|
|
|
assert len(m) == 4
|
2017-10-14 16:34:48 -05:00
|
|
|
target = m[0]
|
|
|
|
|
|
|
|
# Look for the targets of this link.
|
2019-03-24 02:35:20 -05:00
|
|
|
labels = re.findall(r'\\label{\\detokenize{([^}]*)}}', content)
|
|
|
|
matched = [l for l in labels if l == target]
|
2017-10-14 16:34:48 -05:00
|
|
|
|
|
|
|
# If everything is correct we should have exactly one target.
|
2019-03-24 02:35:20 -05:00
|
|
|
assert len(matched) == 1
|