From 3747fbde09a0f078f2f77f53f51c7a458a087549 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Fri, 21 Jun 2013 01:09:13 +0000 Subject: test improvement --- tests/test_intl.py | 197 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 111 insertions(+), 86 deletions(-) (limited to 'tests') diff --git a/tests/test_intl.py b/tests/test_intl.py index 6a004a4e..4c792176 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -93,11 +93,16 @@ def elem_getref(elem): return elem.attrib.get('refid') or elem.attrib.get('refuri') -def assert_elem_text_refs(elem, text, refs): - _text = elem_gettexts(elem) - assert _text == text - _refs = map(elem_getref, elem.findall('reference')) - assert _refs == refs +def assert_elem(elem, texts=None, refs=None, names=None): + if texts is not None: + _texts = elem_gettexts(elem) + assert _texts == texts + if refs is not None: + _refs = map(elem_getref, elem.findall('reference')) + assert _refs == refs + if names is not None: + _names = elem.attrib.get('names').split() + assert _names == names @with_intl_app(buildername='text') @@ -142,22 +147,39 @@ def test_i18n_footnote_break_refid(app): # expect no error by build -@with_intl_app(buildername='text', warning=warnfile) +@with_intl_app(buildername='xml', warning=warnfile) def test_i18n_footnote_regression(app): - """regression test for fix #955""" + # regression test for fix #955 app.builddir.rmtree(True) app.builder.build(['footnote']) - result = (app.outdir / 'footnote.txt').text(encoding='utf-8') - expect = (u"\nI18N WITH FOOTNOTE" - u"\n******************\n" # underline matches new translation - u"\nI18N WITH FOOTNOTE INCLUDE THIS CONTENTS [ref] [1] [100]\n" - u"\n[1] THIS IS A AUTO NUMBERED FOOTNOTE.\n" - u"\n[ref] THIS IS A NAMED FOOTNOTE.\n" - u"\n[100] THIS IS A NUMBERED FOOTNOTE.\n") - assert result == expect + et = ElementTree.parse(app.outdir / 'footnote.xml') + secs = et.findall('section') + + para0 = secs[0].findall('paragraph') + assert_elem( + para0[0], + texts=['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', + '[ref]', '1', '100'], + refs=['i18n-with-footnote', 'ref']) + + footnote0 = secs[0].findall('footnote') + assert_elem( + footnote0[0], + texts=['1','THIS IS A AUTO NUMBERED FOOTNOTE.'], + names=['1']) + assert_elem( + footnote0[1], + texts=['100','THIS IS A NUMBERED FOOTNOTE.'], + names=['100']) + + citation0 = secs[0].findall('citation') + assert_elem( + citation0[0], + texts=['ref','THIS IS A NAMED FOOTNOTE.'], + names=['ref']) warnings = warnfile.getvalue().replace(os.sep, '/') - warning_expr = u'.*/footnote.txt:\\d*: SEVERE: Duplicate ID: ".*".\n' + warning_expr = u'.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n' assert not re.search(warning_expr, warnings) @@ -232,49 +254,52 @@ def test_i18n_keep_external_links(app): para0 = secs[0].findall('paragraph') # external link check - assert_elem_text_refs( + assert_elem( para0[0], - ['EXTERNAL LINK TO', 'Python', '.'], - ['http://python.org/index.html']) + texts=['EXTERNAL LINK TO', 'Python', '.'], + refs=['http://python.org/index.html']) # internal link check - assert_elem_text_refs( + assert_elem( para0[1], - ['EXTERNAL LINKS', 'IS INTERNAL LINK.'], - ['i18n-with-external-links']) + texts=['EXTERNAL LINKS', 'IS INTERNAL LINK.'], + refs=['i18n-with-external-links']) # inline link check - assert_elem_text_refs( + assert_elem( para0[2], - ['INLINE LINK BY', 'THE SPHINX SITE', '.'], - ['http://sphinx-doc.org']) + texts=['INLINE LINK BY', 'THE SPHINX SITE', '.'], + refs=['http://sphinx-doc.org']) # unnamed link check - assert_elem_text_refs( + assert_elem( para0[3], - ['UNNAMED', 'LINK', '.'], - ['http://google.com']) + texts=['UNNAMED', 'LINK', '.'], + refs=['http://google.com']) # link target swapped translation para1 = secs[1].findall('paragraph') - assert_elem_text_refs( + assert_elem( para1[0], - ['LINK TO', 'external2', 'AND', 'external1', '.'], - ['http://example.com/external2', 'http://example.com/external1']) - assert_elem_text_refs( + texts=['LINK TO', 'external2', 'AND', 'external1', '.'], + refs=['http://example.com/external2', + 'http://example.com/external1']) + assert_elem( para1[1], - ['LINK TO', 'THE PYTHON SITE', 'AND', 'THE SPHINX SITE', '.'], - ['http://python.org', 'http://sphinx-doc.org']) + texts=['LINK TO', 'THE PYTHON SITE', 'AND', 'THE SPHINX SITE', + '.'], + refs=['http://python.org', 'http://sphinx-doc.org']) # multiple references in the same line para2 = secs[2].findall('paragraph') - assert_elem_text_refs( + assert_elem( para2[0], - ['LINK TO', 'EXTERNAL LINKS', ',', 'Python', ',', - 'THE SPHINX SITE', ',', 'UNNAMED', 'AND', 'THE PYTHON SITE', '.'], - ['i18n-with-external-links', 'http://python.org/index.html', - 'http://sphinx-doc.org', 'http://google.com', - 'http://python.org']) + texts=['LINK TO', 'EXTERNAL LINKS', ',', 'Python', ',', + 'THE SPHINX SITE', ',', 'UNNAMED', 'AND', + 'THE PYTHON SITE', '.'], + refs=['i18n-with-external-links', 'http://python.org/index.html', + 'http://sphinx-doc.org', 'http://google.com', + 'http://python.org']) @with_intl_app(buildername='text', warning=warnfile, cleanenv=True) @@ -340,44 +365,46 @@ def test_i18n_role_xref(app): sec1, sec2 = et.findall('section') para1, = sec1.findall('paragraph') - assert_elem_text_refs( + assert_elem( para1, - ['LINK TO', "I18N ROCK'N ROLE XREF", ',', 'CONTENTS', ',', - 'SOME NEW TERM', '.'], - ['i18n-role-xref', - 'contents', - 'glossary_terms#term-some-term']) + texts=['LINK TO', "I18N ROCK'N ROLE XREF", ',', 'CONTENTS', ',', + 'SOME NEW TERM', '.'], + refs=['i18n-role-xref', 'contents', + 'glossary_terms#term-some-term']) para2 = sec2.findall('paragraph') - assert_elem_text_refs( + assert_elem( para2[0], - ['LINK TO', 'SOME OTHER NEW TERM', 'AND', 'SOME NEW TERM', '.'], - ['glossary_terms#term-some-other-term', - 'glossary_terms#term-some-term']) - assert_elem_text_refs( + texts=['LINK TO', 'SOME OTHER NEW TERM', 'AND', 'SOME NEW TERM', + '.'], + refs=['glossary_terms#term-some-other-term', + 'glossary_terms#term-some-term']) + assert_elem( para2[1], - ['LINK TO', 'SAME TYPE LINKS', 'AND', "I18N ROCK'N ROLE XREF", '.'], - ['same-type-links', 'i18n-role-xref']) - assert_elem_text_refs( + texts=['LINK TO', 'SAME TYPE LINKS', 'AND', + "I18N ROCK'N ROLE XREF", '.'], + refs=['same-type-links', 'i18n-role-xref']) + assert_elem( para2[2], - ['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', '.'], - ['glossary_terms', 'contents']) - assert_elem_text_refs( + texts=['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', + '.'], + refs=['glossary_terms', 'contents']) + assert_elem( para2[3], - ['LINK TO', '--module', 'AND', '-m', '.'], - ['cmdoption--module', 'cmdoption-m']) - assert_elem_text_refs( + texts=['LINK TO', '--module', 'AND', '-m', '.'], + refs=['cmdoption--module', 'cmdoption-m']) + assert_elem( para2[4], - ['LINK TO', 'env2', 'AND', 'env1', '.'], - ['envvar-env2', 'envvar-env1']) - assert_elem_text_refs( + texts=['LINK TO', 'env2', 'AND', 'env1', '.'], + refs=['envvar-env2', 'envvar-env1']) + assert_elem( para2[5], - ['LINK TO', 'token2', 'AND', 'token1', '.'], - []) #TODO: how do I link token role to productionlist? - assert_elem_text_refs( + texts=['LINK TO', 'token2', 'AND', 'token1', '.'], + refs=[]) #TODO: how do I link token role to productionlist? + assert_elem( para2[6], - ['LINK TO', 'same-type-links', 'AND', "i18n-role-xref", '.'], - ['same-type-links', 'i18n-role-xref']) + texts=['LINK TO', 'same-type-links', 'AND', "i18n-role-xref", '.'], + refs=['same-type-links', 'i18n-role-xref']) #warnings warnings = warnfile.getvalue().replace(os.sep, '/') @@ -393,37 +420,35 @@ def test_i18n_label_target(app): et = ElementTree.parse(app.outdir / 'label_target.xml') secs = et.findall('section') - #debug - print (app.outdir / 'label_target.xml').text() - para0 = secs[0].findall('paragraph') - assert_elem_text_refs( + assert_elem( para0[0], - ['X SECTION AND LABEL', 'POINT TO', 'implicit-target', 'AND', - 'X SECTION AND LABEL', 'POINT TO', 'section-and-label', '.'], - ['implicit-target', 'section-and-label']) + texts=['X SECTION AND LABEL', 'POINT TO', 'implicit-target', 'AND', + 'X SECTION AND LABEL', 'POINT TO', 'section-and-label', '.'], + refs=['implicit-target', 'section-and-label']) para1 = secs[1].findall('paragraph') - assert_elem_text_refs( + assert_elem( para1[0], - ['X EXPLICIT-TARGET', 'POINT TO', 'explicit-target', 'AND', - 'X EXPLICIT-TARGET', 'POINT TO DUPLICATED ID LIKE', 'id1', '.'], - ['explicit-target', 'id1']) + texts=['X EXPLICIT-TARGET', 'POINT TO', 'explicit-target', 'AND', + 'X EXPLICIT-TARGET', 'POINT TO DUPLICATED ID LIKE', 'id1', + '.'], + refs=['explicit-target', 'id1']) para2 = secs[2].findall('paragraph') - assert_elem_text_refs( + assert_elem( para2[0], - ['X IMPLICIT SECTION NAME', 'POINT TO', 'implicit-section-name', - '.'], - ['implicit-section-name']) + texts=['X IMPLICIT SECTION NAME', 'POINT TO', + 'implicit-section-name', '.'], + refs=['implicit-section-name']) sec2 = secs[2].findall('section') para2_0 = sec2[0].findall('paragraph') - assert_elem_text_refs( + assert_elem( para2_0[0], - ['`X DUPLICATED SUB SECTION`_', 'IS BROKEN LINK.'], - []) + texts=['`X DUPLICATED SUB SECTION`_', 'IS BROKEN LINK.'], + refs=[]) @with_intl_app(buildername='text', warning=warnfile) -- cgit v1.2.1 From 2a5619b21e130d74710c717340ca52ffc516e793 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Fri, 21 Jun 2013 03:28:32 +0000 Subject: Fix i18n: footnote reference number missing for auto numbered named footnote and auto symbol footnote. Closes #1176 --- tests/roots/test-intl/footnote.po | 7 +++++-- tests/roots/test-intl/footnote.txt | 3 ++- tests/test_intl.py | 37 +++++++++++++++++++++---------------- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/roots/test-intl/footnote.po b/tests/roots/test-intl/footnote.po index 47f8d3db..b3876f51 100644 --- a/tests/roots/test-intl/footnote.po +++ b/tests/roots/test-intl/footnote.po @@ -19,8 +19,8 @@ msgstr "" msgid "i18n with Footnote" msgstr "I18N WITH FOOTNOTE" -msgid "[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_" -msgstr "`I18N WITH FOOTNOTE`_ INCLUDE THIS CONTENTS [ref]_ [#]_ [100]_" +msgid "[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ [#named]_." +msgstr "`I18N WITH FOOTNOTE`_ INCLUDE THIS CONTENTS [#named]_ [ref]_ [#]_ [100]_." msgid "This is a auto numbered footnote." msgstr "THIS IS A AUTO NUMBERED FOOTNOTE." @@ -31,3 +31,6 @@ msgstr "THIS IS A NAMED FOOTNOTE." msgid "This is a numbered footnote." msgstr "THIS IS A NUMBERED FOOTNOTE." +msgid "This is a auto numbered named footnote." +msgstr "THIS IS A AUTO NUMBERED NAMED FOOTNOTE." + diff --git a/tests/roots/test-intl/footnote.txt b/tests/roots/test-intl/footnote.txt index 3ef76bba..55da9c6d 100644 --- a/tests/roots/test-intl/footnote.txt +++ b/tests/roots/test-intl/footnote.txt @@ -4,8 +4,9 @@ i18n with Footnote ================== .. #955 cant-build-html-with-footnotes-when-using -[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ +[100]_ Contents [#]_ for `i18n with Footnote`_ [ref]_ [#named]_. .. [#] This is a auto numbered footnote. .. [ref] This is a named footnote. .. [100] This is a numbered footnote. +.. [#named] This is a auto numbered named footnote. diff --git a/tests/test_intl.py b/tests/test_intl.py index 4c792176..ef412c1d 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -149,7 +149,7 @@ def test_i18n_footnote_break_refid(app): @with_intl_app(buildername='xml', warning=warnfile) def test_i18n_footnote_regression(app): - # regression test for fix #955 + # regression test for fix #955, #1176 app.builddir.rmtree(True) app.builder.build(['footnote']) et = ElementTree.parse(app.outdir / 'footnote.xml') @@ -159,7 +159,7 @@ def test_i18n_footnote_regression(app): assert_elem( para0[0], texts=['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', - '[ref]', '1', '100'], + '2', '[ref]', '1', '100', '.'], refs=['i18n-with-footnote', 'ref']) footnote0 = secs[0].findall('footnote') @@ -171,6 +171,10 @@ def test_i18n_footnote_regression(app): footnote0[1], texts=['100','THIS IS A NUMBERED FOOTNOTE.'], names=['100']) + assert_elem( + footnote0[2], + texts=['2','THIS IS A AUTO NUMBERED NAMED FOOTNOTE.'], + names=['named']) citation0 = secs[0].findall('citation') assert_elem( @@ -183,22 +187,23 @@ def test_i18n_footnote_regression(app): assert not re.search(warning_expr, warnings) -@with_intl_app(buildername='html', cleanenv=True) +@with_intl_app(buildername='xml', cleanenv=True) def test_i18n_footnote_backlink(app): - """i18n test for #1058""" + # i18n test for #1058 app.builder.build(['footnote']) - result = (app.outdir / 'footnote.html').text(encoding='utf-8') - expects = [ - '[100]', - '[1]', - '[ref]', - '[1]', - '[ref]', - '[100]', - ] - for expect in expects: - matches = re.findall(re.escape(expect), result) - assert len(matches) == 1 + et = ElementTree.parse(app.outdir / 'footnote.xml') + secs = et.findall('section') + + para0 = secs[0].findall('paragraph') + refs0 = para0[0].findall('footnote_reference') + refid2id = dict([ + (r.attrib.get('refid'), r.attrib.get('ids')) for r in refs0]) + + footnote0 = secs[0].findall('footnote') + for footnote in footnote0: + ids = footnote.attrib.get('ids') + backrefs = footnote.attrib.get('backrefs') + assert refid2id[ids] == backrefs @with_intl_app(buildername='text', warning=warnfile, cleanenv=True) -- cgit v1.2.1