summaryrefslogtreecommitdiff
path: root/tests/test_util_nodes.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_util_nodes.py')
-rw-r--r--tests/test_util_nodes.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/test_util_nodes.py b/tests/test_util_nodes.py
index 5cdd20a19..c90139c88 100644
--- a/tests/test_util_nodes.py
+++ b/tests/test_util_nodes.py
@@ -16,13 +16,24 @@ from docutils.utils import new_document
from docutils import frontend
from sphinx.util.nodes import extract_messages
+from sphinx.transforms import ApplySourceWorkaround
-def _get_doctree(text):
+def _transform(doctree):
+ ApplySourceWorkaround(doctree).apply()
+
+
+def create_new_document():
settings = frontend.OptionParser(
components=(rst.Parser,)).get_default_values()
document = new_document('dummy.txt', settings)
+ return document
+
+
+def _get_doctree(text):
+ document = create_new_document()
rst.Parser().parse(text, document)
+ _transform(document)
return document
@@ -119,3 +130,26 @@ def test_extract_messages():
extract_messages(_get_doctree(text)),
nodes.line, 2,
)
+
+
+def test_extract_messages_without_rawsource():
+ """
+ Check node.rawsource is fall-backed by using node.astext() value.
+
+ `extract_message` which is used from Sphinx i18n feature drop ``not node.rawsource``
+ nodes. So, all nodes which want to translate must have ``rawsource`` value.
+ However, sometimes node.rawsource is not set.
+
+ For example: recommonmark-0.2.0 doesn't set rawsource to `paragraph` node.
+
+ refs #1994: Fall back to node's astext() during i18n message extraction.
+ """
+ p = nodes.paragraph()
+ p.append(nodes.Text('test'))
+ p.append(nodes.Text('sentence'))
+ assert not p.rawsource # target node must not have rawsource value
+ document = create_new_document()
+ document.append(p)
+ _transform(document)
+ assert_node_count(extract_messages(document), nodes.TextElement, 1)
+ assert [m for n, m in extract_messages(document)][0], 'text sentence'