Skip to content

Commit

Permalink
[tests] Add intl regression test for term not found warning (#12388)
Browse files Browse the repository at this point in the history
Add test for term not found warning in test_intl to prevent future regressions
  • Loading branch information
n-peugnet committed May 19, 2024
1 parent 6ce4f96 commit ac3f74a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/roots/test-intl/glossary_terms_inconsistency.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ i18n with glossary terms inconsistency
======================================

1. link to :term:`Some term` and :term:`Some other term`.
2. link to :term:`Some term`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ msgstr "I18N WITH GLOSSARY TERMS INCONSISTENCY"

msgid "link to :term:`Some term` and :term:`Some other term`."
msgstr "LINK TO :term:`SOME NEW TERM`."

msgid "link to :term:`Some term`."
msgstr "LINK TO :term:`TERM NOT IN GLOSSARY`."
16 changes: 12 additions & 4 deletions tests/test_intl/test_intl.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@ def test_text_inconsistency_warnings(app, warning):
})
assert re.search(expected_warning_expr, warnings), f'{expected_warning_expr!r} did not match {warnings!r}'

expected_citation_ref_warning_expr = (
'.*/refs_inconsistency.txt:\\d+: WARNING: Citation \\[ref2\\] is not referenced.')
assert re.search(expected_citation_ref_warning_expr, warnings), f'{expected_citation_ref_warning_expr!r} did not match {warnings!r}'

expected_citation_warning_expr = (
'.*/refs_inconsistency.txt:\\d+: WARNING: Citation \\[ref2\\] is not referenced.\n' +
'.*/refs_inconsistency.txt:\\d+: WARNING: citation not found: ref3')
assert re.search(expected_citation_warning_expr, warnings), f'{expected_citation_warning_expr!r} did not match {warnings!r}'

Expand Down Expand Up @@ -286,7 +289,7 @@ def test_text_glossary_term(app, warning):
""")
assert result == expect
warnings = getwarning(warning)
assert 'term not in glossary' not in warnings
assert warnings.count('term not in glossary') == 1


@sphinx_intl
Expand All @@ -298,7 +301,8 @@ def test_text_glossary_term_inconsistencies(app, warning):
result = (app.outdir / 'glossary_terms_inconsistency.txt').read_text(encoding='utf8')
expect = ("19. I18N WITH GLOSSARY TERMS INCONSISTENCY"
"\n******************************************\n"
"\n1. LINK TO *SOME NEW TERM*.\n")
"\n1. LINK TO *SOME NEW TERM*.\n"
"\n2. LINK TO *TERM NOT IN GLOSSARY*.\n")
assert result == expect

warnings = getwarning(warning)
Expand All @@ -308,6 +312,10 @@ def test_text_glossary_term_inconsistencies(app, warning):
" original: \\[':term:`Some term`', ':term:`Some other term`'\\],"
" translated: \\[':term:`SOME NEW TERM`'\\]\n")
assert re.search(expected_warning_expr, warnings), f'{expected_warning_expr!r} did not match {warnings!r}'
expected_warning_expr = (
'.*/glossary_terms_inconsistency.txt:\\d+:<translated>:1: '
"WARNING: term not in glossary: 'TERM NOT IN GLOSSARY'")
assert re.search(expected_warning_expr, warnings), f'{expected_warning_expr!r} did not match {warnings!r}'


@sphinx_intl
Expand Down Expand Up @@ -1240,7 +1248,7 @@ def test_xml_warnings(app, warning):
app.build()
# warnings
warnings = getwarning(warning)
assert 'term not in glossary' not in warnings
assert warnings.count('term not in glossary') == 1
assert 'undefined label' not in warnings
assert 'unknown document' not in warnings

Expand Down

0 comments on commit ac3f74a

Please sign in to comment.