diff options
Diffstat (limited to 'tests/test_domain_std.py')
-rw-r--r-- | tests/test_domain_std.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py index 56c2d968c..e98384824 100644 --- a/tests/test_domain_std.py +++ b/tests/test_domain_std.py @@ -8,11 +8,15 @@ :license: BSD, see LICENSE for details. """ +import pytest + from unittest import mock from docutils import nodes from docutils.nodes import definition, definition_list, definition_list_item, term +from html5lib import HTMLParser + from sphinx import addnodes from sphinx.addnodes import ( desc, desc_addname, desc_content, desc_name, desc_signature, glossary, index @@ -20,6 +24,7 @@ from sphinx.addnodes import ( from sphinx.domains.std import StandardDomain from sphinx.testing import restructuredtext from sphinx.testing.util import assert_node +from sphinx.util import docutils def test_process_doc_handle_figure_caption(): @@ -172,6 +177,15 @@ def test_glossary_warning(app, status, warning): assert ("case3.rst:4: WARNING: glossary term must be preceded by empty line" in warning.getvalue()) + # duplicated terms + text = (".. glossary::\n" + "\n" + " term-case4\n" + " term-case4\n") + restructuredtext.parse(app, text, "case4") + assert ("case4.txt:3: WARNING: duplicate term description of term-case4, " + "other instance in case4" in warning.getvalue()) + def test_glossary_comment(app): text = (".. glossary::\n" @@ -303,3 +317,59 @@ def test_multiple_cmdoptions(app): assert ('cmd', '--output') in domain.progoptions assert domain.progoptions[('cmd', '-o')] == ('index', 'cmdoption-cmd-o') assert domain.progoptions[('cmd', '--output')] == ('index', 'cmdoption-cmd-o') + + +@pytest.mark.skipif(docutils.__version_info__ < (0, 13), + reason='docutils-0.13 or above is required') +@pytest.mark.sphinx(testroot='productionlist') +def test_productionlist(app, status, warning): + app.builder.build_all() + + warnings = warning.getvalue().split("\n"); + assert len(warnings) == 2 + assert warnings[-1] == '' + assert "Dup2.rst:4: WARNING: duplicate token description of Dup, other instance in Dup1" in warnings[0] + + with (app.outdir / 'index.html').open('rb') as f: + etree = HTMLParser(namespaceHTMLElements=False).parse(f) + ul = list(etree.iter('ul'))[1] + cases = [] + for li in list(ul): + assert len(list(li)) == 1 + p = list(li)[0] + assert p.tag == 'p' + text = str(p.text).strip(' :') + assert len(list(p)) == 1 + a = list(p)[0] + assert a.tag == 'a' + link = a.get('href') + assert len(list(a)) == 1 + code = list(a)[0] + assert code.tag == 'code' + assert len(list(code)) == 1 + span = list(code)[0] + assert span.tag == 'span' + linkText = span.text.strip() + cases.append((text, link, linkText)) + assert cases == [ + ('A', 'Bare.html#grammar-token-_a', 'A'), + ('B', 'Bare.html#grammar-token-_b', 'B'), + ('P1:A', 'P1.html#grammar-token-p1_a', 'P1:A'), + ('P1:B', 'P1.html#grammar-token-p1_b', 'P1:B'), + ('P2:A', 'P1.html#grammar-token-p1_a', 'P1:A'), + ('P2:B', 'P2.html#grammar-token-p2_b', 'P2:B'), + ('Explicit title A, plain', 'Bare.html#grammar-token-_a', 'MyTitle'), + ('Explicit title A, colon', 'Bare.html#grammar-token-_a', 'My:Title'), + ('Explicit title P1:A, plain', 'P1.html#grammar-token-p1_a', 'MyTitle'), + ('Explicit title P1:A, colon', 'P1.html#grammar-token-p1_a', 'My:Title'), + ('Tilde A', 'Bare.html#grammar-token-_a', 'A'), + ('Tilde P1:A', 'P1.html#grammar-token-p1_a', 'A'), + ('Tilde explicit title P1:A', 'P1.html#grammar-token-p1_a', '~MyTitle'), + ('Tilde, explicit title P1:A', 'P1.html#grammar-token-p1_a', 'MyTitle'), + ('Dup', 'Dup2.html#grammar-token-_dup', 'Dup'), + ('FirstLine', 'firstLineRule.html#grammar-token-_firstline', 'FirstLine'), + ('SecondLine', 'firstLineRule.html#grammar-token-_secondline', 'SecondLine'), + ] + + text = (app.outdir / 'LineContinuation.html').read_text() + assert "A</strong> ::= B C D E F G" in text |