diff options
| author | shimizukawa <shimizukawa@gmail.com> | 2013-06-16 23:57:08 +0900 |
|---|---|---|
| committer | shimizukawa <shimizukawa@gmail.com> | 2013-06-16 23:57:08 +0900 |
| commit | 6f9432b1105a55ed1e2ae07e40b247013e643d6f (patch) | |
| tree | b373280e7be240647955a177eb47ad294f385719 /tests | |
| parent | 8572dffb8c518299e0d0936e3ae83400970c2691 (diff) | |
| download | sphinx-6f9432b1105a55ed1e2ae07e40b247013e643d6f.tar.gz | |
Fix multiple cross references (term, ref, doc) in the same line return the same link with i18n. refs #1090, #1193
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/roots/test-intl/role_xref.po | 13 | ||||
| -rw-r--r-- | tests/roots/test-intl/role_xref.txt | 10 | ||||
| -rw-r--r-- | tests/test_intl.py | 66 |
3 files changed, 79 insertions, 10 deletions
diff --git a/tests/roots/test-intl/role_xref.po b/tests/roots/test-intl/role_xref.po index e7a348b3..4c6b099e 100644 --- a/tests/roots/test-intl/role_xref.po +++ b/tests/roots/test-intl/role_xref.po @@ -21,3 +21,16 @@ msgstr "I18N ROCK'N ROLE XREF" msgid "link to :term:`Some term`, :ref:`i18n-role-xref`, :doc:`contents`." msgstr "LINK TO :ref:`i18n-role-xref`, :doc:`contents`, :term:`SOME NEW TERM`." + +msgid "same type links" +msgstr "SAME TYPE LINKS" + +msgid "link to :term:`Some term` and :term:`Some other term`." +msgstr "LINK TO :term:`SOME OTHER NEW TERM` AND :term:`SOME NEW TERM`." + +msgid "link to :ref:`i18n-role-xref` and :ref:`same-type-links`." +msgstr "LINK TO :ref:`same-type-links` AND :ref:`i18n-role-xref`." + +msgid "link to :doc:`contents` and :doc:`glossary_terms`." +msgstr "LINK TO :doc:`glossary_terms` AND :doc:`contents`." + diff --git a/tests/roots/test-intl/role_xref.txt b/tests/roots/test-intl/role_xref.txt index 382b740c..f8103ddb 100644 --- a/tests/roots/test-intl/role_xref.txt +++ b/tests/roots/test-intl/role_xref.txt @@ -7,3 +7,13 @@ i18n role xref link to :term:`Some term`, :ref:`i18n-role-xref`, :doc:`contents`. +.. _same-type-links: + +same type links +================= + +link to :term:`Some term` and :term:`Some other term`. + +link to :ref:`i18n-role-xref` and :ref:`same-type-links`. + +link to :doc:`contents` and :doc:`glossary_terms`. diff --git a/tests/test_intl.py b/tests/test_intl.py index abec0802..1ee3da56 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -14,6 +14,7 @@ import os import re from StringIO import StringIO from subprocess import Popen, PIPE +from xml.etree import ElementTree from sphinx.util.pycompat import relpath @@ -292,25 +293,70 @@ def test_i18n_glossary_terms(app): assert 'term not in glossary' not in warnings -@with_intl_app(buildername='text', warning=warnfile) +@with_intl_app(buildername='xml', warning=warnfile) def test_i18n_role_xref(app): # regression test for #1090 + + def gettexts(elem): + def itertext(self): + # this function copied from Python-2.7 'ElementTree.itertext'. + # for compatibility to Python-2.5, 2.6, 3.1 + tag = self.tag + if not isinstance(tag, basestring) and tag is not None: + return + if self.text: + yield self.text + for e in self: + for s in itertext(e): + yield s + if e.tail: + yield e.tail + return filter(None, [s.strip() for s in itertext(elem)]) + + def getref(elem): + return elem.attrib.get('refid') or elem.attrib.get('refuri') + + def assert_text_refs(elem, text, refs): + _text = gettexts(elem) + assert _text == text + _refs = map(getref, elem.findall('reference')) + assert _refs == refs + app.builddir.rmtree(True) #for warnings acceleration app.builder.build(['role_xref']) - result = (app.outdir / 'role_xref.txt').text(encoding='utf-8') - expect = ( - u"\nI18N ROCK'N ROLE XREF" - u"\n*********************\n" - u"\nLINK TO *I18N ROCK'N ROLE XREF*, *CONTENTS*, *SOME NEW TERM*.\n" - ) - + et = ElementTree.parse(app.outdir / 'role_xref.xml') + sec1, sec2 = et.findall('section') + + para1, = sec1.findall('paragraph') + assert_text_refs( + para1, + ['LINK TO', "I18N ROCK'N ROLE XREF", ',', 'CONTENTS', ',', + 'SOME NEW TERM', '.'], + ['i18n-role-xref', + 'contents', + 'glossary_terms#term-some-new-term']) + + para21, para22, para23 = sec2.findall('paragraph') + assert_text_refs( + para21, + ['LINK TO', 'SOME OTHER NEW TERM', 'AND', 'SOME NEW TERM', '.'], + ['glossary_terms#term-some-other-new-term', + 'glossary_terms#term-some-new-term']) + assert_text_refs( + para22, + ['LINK TO', 'SAME TYPE LINKS', 'AND', "I18N ROCK'N ROLE XREF", '.'], + ['same-type-links', 'i18n-role-xref']) + assert_text_refs( + para23, + ['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', '.'], + ['glossary_terms', 'contents']) + + #warnings warnings = warnfile.getvalue().replace(os.sep, '/') assert 'term not in glossary' not in warnings assert 'undefined label' not in warnings assert 'unknown document' not in warnings - assert result == expect - @with_intl_app(buildername='text', warning=warnfile) def test_i18n_glossary_terms_inconsistency(app): |
