From 8f7936d75cd39bfb3f7b4e54a0cb3705b962365d Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Tue, 26 Aug 2014 01:39:26 +0900 Subject: [PATCH] * gettext does not extract nodes.line in a table or list. Closes #1477 --- CHANGES | 1 + sphinx/util/nodes.py | 1 + tests/test_util_nodes.py | 121 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 tests/test_util_nodes.py diff --git a/CHANGES b/CHANGES index c78ab4313..2003236a3 100644 --- a/CHANGES +++ b/CHANGES @@ -38,6 +38,7 @@ Bugs fixed inheritance-diagram directive. Thanks to WAKAYAMA shirou. * PR#281, PR#282, #1509: TODO extension not compatible with websupport. Thanks to Takeshi Komiya. +* #1477: gettext does not extract nodes.line in a table or list. Release 1.2.2 (released Mar 2, 2014) ==================================== diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index dd7fa08e5..eb3b86b53 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -59,6 +59,7 @@ def apply_source_workaround(node): nodes.caption, nodes.title, nodes.rubric, + nodes.line, ))): node.source = find_source_node(node) node.line = 0 # need fix docutils to get `node.line` diff --git a/tests/test_util_nodes.py b/tests/test_util_nodes.py new file mode 100644 index 000000000..9ddc049dc --- /dev/null +++ b/tests/test_util_nodes.py @@ -0,0 +1,121 @@ +# -*- coding: utf-8 -*- +""" + test_util_nodes + ~~~~~~~~~~~~~~~ + + Tests uti.nodes functions. + + :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +from textwrap import dedent + +from docutils import nodes +from docutils.parsers import rst +from docutils.utils import new_document +from docutils import frontend + +from sphinx.util.nodes import extract_messages + + +def _get_doctree(text): + settings = frontend.OptionParser( + components=(rst.Parser,)).get_default_values() + document = new_document('dummy.txt', settings) + rst.Parser().parse(text, document) + return document + + +def assert_node_count(messages, node_type, expect_count): + count = 0 + node_list = [node for node, msg in messages] + for node in node_list: + if isinstance(node, node_type): + count += 1 + + assert count == expect_count, ( + "Count of %r in the %r is %d instead of %d" + % (node_type, node_list, count, expect_count)) + + +def test_extract_messages(): + text = dedent( + """ + .. admonition:: admonition title + + admonition body + """ + ) + yield ( + assert_node_count, + extract_messages(_get_doctree(text)), + nodes.title, 1, + ) + + text = dedent( + """ + .. figure:: foo.jpg + + this is title + """ + ) + yield ( + assert_node_count, + extract_messages(_get_doctree(text)), + nodes.caption, 1, + ) + + text = dedent( + """ + .. rubric:: spam + """ + ) + yield ( + assert_node_count, + extract_messages(_get_doctree(text)), + nodes.rubric, 1, + ) + + + text = dedent( + """ + | spam + | egg + """ + ) + yield ( + assert_node_count, + extract_messages(_get_doctree(text)), + nodes.line, 2, + ) + + + text = dedent( + """ + section + ======= + + +----------------+ + | | **Title 1** | + | | Message 1 | + +----------------+ + """ + ) + yield ( + assert_node_count, + extract_messages(_get_doctree(text)), + nodes.line, 2, + ) + + + text = dedent( + """ + * | **Title 1** + | Message 1 + """ + ) + yield ( + assert_node_count, + extract_messages(_get_doctree(text)), + nodes.line, 2, + )