def test_qthelp_escaped(app, status, warning): app.builder.build_all() et = etree_parse(app.outdir / 'needbescapedbproject.qhp') customFilter = et.find('.//customFilter') assert len(customFilter) == 2 assert customFilter.attrib == {'name': 'need <b>"escaped"</b> project '} assert customFilter[0].text == 'needbescapedbproject' assert customFilter[1].text is None toc = et.find('.//toc') assert len(toc) == 1 assert toc[0].attrib == {'title': 'need <b>"escaped"</b> project documentation', 'ref': 'index.html'} assert len(toc[0]) == 4 assert toc[0][0].attrib == {'title': '<foo>', 'ref': 'foo.html'} assert toc[0][0][0].attrib == {'title': 'quux', 'ref': 'quux.html'} assert toc[0][0][1].attrib == {'title': 'foo "1"', 'ref': 'foo.html#foo-1'} assert toc[0][0][1][0].attrib == {'title': 'foo.1-1', 'ref': 'foo.html#foo-1-1'} assert toc[0][0][2].attrib == {'title': 'foo.2', 'ref': 'foo.html#foo-2'} assert toc[0][1].attrib == {'title': 'bar', 'ref': 'bar.html'} assert toc[0][2].attrib == {'title': 'http://sphinx-doc.org/', 'ref': 'http://sphinx-doc.org/'} assert toc[0][3].attrib == {'title': 'baz', 'ref': 'baz.html'} keywords = et.find('.//keywords') assert len(keywords) == 2 assert keywords[0].attrib == {'name': '<subsection>', 'ref': 'index.html#index-0'} assert keywords[1].attrib == {'name': '"subsection"', 'ref': 'index.html#index-0'}
def test_literal_include(app, status, warning): app.builder.build(['index']) et = etree_parse(app.outdir / 'index.xml') secs = et.findall('./section/section') literal_include = secs[1].findall('literal_block') literal_src = (app.srcdir / 'literal.inc').text(encoding='utf-8') assert len(literal_include) > 0 actual = literal_include[0].text assert actual == literal_src
def test_literal_include(app, status, warning): app.builder.build(['index']) et = etree_parse(app.outdir / 'index.xml') secs = et.findall('./section/section') literal_include = secs[1].findall('literal_block') literal_src = (app.srcdir / 'literal.inc').text() assert len(literal_include) > 0 actual = literal_include[0].text assert actual == literal_src
def test_code_block(app, status, warning): app.builder.build('index') et = etree_parse(app.outdir / 'index.xml') secs = et.findall('./section/section') code_block = secs[0].findall('literal_block') assert len(code_block) > 0 actual = code_block[0].text expect = (" def ruby?\n" + " false\n" + " end") assert actual == expect
def test_xml_role_xref(app): app.build() # --- role xref: regression test for #1090, #1193 et = etree_parse(app.outdir / 'role_xref.xml') sec1, sec2 = et.findall('section') para1, = sec1.findall('paragraph') if sphinx_version_info < (3,): p1_expected_anchor = 'term-some-term' else: p1_expected_anchor = 'term-Some-term' assert_elem( para1, ['LINK TO', "I18N ROCK'N ROLE XREF", ',', 'CONTENTS', ',', 'SOME NEW TERM', '.'], ['i18n-role-xref', 'index', 'glossary_terms#{}'.format(p1_expected_anchor)]) para2 = sec2.findall('paragraph') if sphinx_version_info < (3,): p2_0_expected_anchor_1 = 'term-some-other-term' p2_0_expected_anchor_2 = 'term-some-term' else: p2_0_expected_anchor_1 = 'term-Some-other-term' p2_0_expected_anchor_2 = 'term-Some-term' assert_elem( para2[0], ['LINK TO', 'SOME OTHER NEW TERM', 'AND', 'SOME NEW TERM', '.'], ['glossary_terms#{}'.format(p2_0_expected_anchor_1), 'glossary_terms#{}'.format(p2_0_expected_anchor_2)]) if sphinx_version_info >= (3, 2): assert_elem( para2[1], ['LINK TO', 'LABEL', 'AND', 'SAME TYPE LINKS', 'AND', 'SAME TYPE LINKS', '.'], ['i18n-role-xref', 'same-type-links', 'same-type-links']) assert_elem( para2[2], ['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', '.'], ['glossary_terms', 'index']) assert_elem( para2[3], ['LINK TO', '--module', 'AND', '-m', '.'], ['cmdoption-module', 'cmdoption-m']) assert_elem( para2[4], ['LINK TO', 'env2', 'AND', 'env1', '.'], ['envvar-env2', 'envvar-env1']) assert_elem( para2[5], ['LINK TO', 'token2', 'AND', 'token1', '.'], []) # 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'])
def test_returns_warning_without_extension(app: Sphinx, status: StringIO, warning: StringIO) -> None: """It returns a warning if the extension is not added to the config.""" app.builder.build_all() assert 'Unknown directive type "samp"' in warning.getvalue() et = etree_parse(app.outdir / "index.xml") # type: ignore blocks = et.findall("./section/literal_block") assert len(blocks) == 0
def test_escaping(app, status, warning): app.builder.build_all() outdir = app.builder.outdir docpage = outdir / 'underscore_module_.xml' assert docpage.exists() title = etree_parse(docpage).find('section/title') assert str_content(title) == 'underscore_module_'
def test_escaping(app, status, warning): app.builder.build_all() outdir = app.builder.outdir docpage = outdir / 'underscore_module_.xml' assert docpage.exists() title = etree_parse(docpage).find('section/title') assert str_content(title) == 'underscore_module_'
def test_xml_refs_in_python_domain(app): app.build() # --- refs in the Python domain et = etree_parse(app.outdir / 'refs_python_domain.xml') secs = et.findall('section') # regression test for fix #1363 para0 = secs[0].findall('paragraph') assert_elem(para0[0], ['SEE THIS DECORATOR:', 'sensitive_variables()', '.'], ['sensitive.sensitive_variables'])
def test_xml_refs_in_python_domain(app): app.build() # --- refs in the Python domain et = etree_parse(app.outdir / 'refs_python_domain.xml') secs = et.findall('section') # regression test for fix #1363 para0 = secs[0].findall('paragraph') assert_elem( para0[0], ['SEE THIS DECORATOR:', 'sensitive_variables()', '.'], ['sensitive.sensitive_variables'])
def test_xml_keep_external_links(app): app.build() # --- keep external links: regression test for #1044 et = etree_parse(app.outdir / 'external_links.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') # external link check assert_elem( para0[0], ['EXTERNAL LINK TO', 'Python', '.'], ['http://python.org/index.html']) # internal link check assert_elem( para0[1], ['EXTERNAL LINKS', 'IS INTERNAL LINK.'], ['i18n-with-external-links']) # inline link check assert_elem( para0[2], ['INLINE LINK BY', 'THE SPHINX SITE', '.'], ['http://sphinx-doc.org']) # unnamed link check assert_elem( para0[3], ['UNNAMED', 'LINK', '.'], ['http://google.com']) # link target swapped translation para1 = secs[1].findall('paragraph') assert_elem( para1[0], ['LINK TO', 'external2', 'AND', 'external1', '.'], ['https://www.google.com/external2', 'https://www.google.com/external1']) assert_elem( para1[1], ['LINK TO', 'THE PYTHON SITE', 'AND', 'THE SPHINX SITE', '.'], ['http://python.org', 'http://sphinx-doc.org']) # multiple references in the same line para2 = secs[2].findall('paragraph') 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'])
def test_xml_keep_external_links(app): app.build() # --- keep external links: regression test for #1044 et = etree_parse(app.outdir / 'external_links.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') # external link check assert_elem( para0[0], ['EXTERNAL LINK TO', 'Python', '.'], ['http://python.org/index.html']) # internal link check assert_elem( para0[1], ['EXTERNAL LINKS', 'IS INTERNAL LINK.'], ['i18n-with-external-links']) # inline link check assert_elem( para0[2], ['INLINE LINK BY', 'THE SPHINX SITE', '.'], ['http://sphinx-doc.org']) # unnamed link check assert_elem( para0[3], ['UNNAMED', 'LINK', '.'], ['http://google.com']) # link target swapped translation para1 = secs[1].findall('paragraph') assert_elem( para1[0], ['LINK TO', 'external2', 'AND', 'external1', '.'], ['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']) # multiple references in the same line para2 = secs[2].findall('paragraph') 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'])
def test_xml_label_targets(app): app.build() # --- label targets: regression test for #1193, #1265 et = etree_parse(app.outdir / 'label_target.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') 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']) para1 = secs[1].findall('paragraph') assert_elem( para1[0], ['X EXPLICIT-TARGET', 'POINT TO', 'explicit-target', 'AND', 'X EXPLICIT-TARGET', 'POINT TO DUPLICATED ID LIKE', 'id1', '.'], ['explicit-target', 'id1']) para2 = secs[2].findall('paragraph') assert_elem( para2[0], ['X IMPLICIT SECTION NAME', 'POINT TO', 'implicit-section-name', '.'], ['implicit-section-name']) sec2 = secs[2].findall('section') para2_0 = sec2[0].findall('paragraph') assert_elem( para2_0[0], ['`X DUPLICATED SUB SECTION`_', 'IS BROKEN LINK.'], []) para3 = secs[3].findall('paragraph') assert_elem( para3[0], ['X', 'bridge label', 'IS NOT TRANSLATABLE BUT LINKED TO TRANSLATED ' + 'SECTION TITLE.'], ['label-bridged-target-section']) assert_elem( para3[1], ['X', 'bridge label', 'POINT TO', 'LABEL BRIDGED TARGET SECTION', 'AND', 'bridge label2', 'POINT TO', 'SECTION AND LABEL', '. THE SECOND APPEARED', 'bridge label2', 'POINT TO CORRECT TARGET.'], ['label-bridged-target-section', 'section-and-label', 'section-and-label'])
def test_xml_label_targets(app): app.build() # --- label targets: regression test for #1193, #1265 et = etree_parse(app.outdir / 'label_target.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') 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']) para1 = secs[1].findall('paragraph') assert_elem( para1[0], ['X EXPLICIT-TARGET', 'POINT TO', 'explicit-target', 'AND', 'X EXPLICIT-TARGET', 'POINT TO DUPLICATED ID LIKE', 'id1', '.'], ['explicit-target', 'id1']) para2 = secs[2].findall('paragraph') assert_elem( para2[0], ['X IMPLICIT SECTION NAME', 'POINT TO', 'implicit-section-name', '.'], ['implicit-section-name']) sec2 = secs[2].findall('section') para2_0 = sec2[0].findall('paragraph') assert_elem( para2_0[0], ['`X DUPLICATED SUB SECTION`_', 'IS BROKEN LINK.'], []) para3 = secs[3].findall('paragraph') assert_elem( para3[0], ['X', 'bridge label', 'IS NOT TRANSLATABLE BUT LINKED TO TRANSLATED ' + 'SECTION TITLE.'], ['label-bridged-target-section']) assert_elem( para3[1], ['X', 'bridge label', 'POINT TO', 'LABEL BRIDGED TARGET SECTION', 'AND', 'bridge label2', 'POINT TO', 'SECTION AND LABEL', '. THE SECOND APPEARED', 'bridge label2', 'POINT TO CORRECT TARGET.'], ['label-bridged-target-section', 'section-and-label', 'section-and-label'])
def test_finds_samp_directives(app: Sphinx) -> None: """It finds all samp directives.""" app.builder.build_all() et = etree_parse(app.outdir / "index.xml") # type: ignore blocks = et.findall("./section/literal_block") assert len(blocks) == 1 prompts = blocks[0].findall("inline") assert len(prompts) == 2 assert prompts[0].get("classes") == "gp" emph = blocks[0].findall("emphasis") assert len(emph) == 1 assert emph[0].get("classes") == "var"
def test_does_not_assign_id_in_xml(app: Sphinx) -> None: """It does not assign an ID automatically in XML.""" app.build() et = etree_parse(app.outdir / "index.xml") notes = et.findall(".//note") assert len(notes) == 3 assert "ids" not in notes[0].attrib assert "ids" not in notes[1].attrib assert "ids" in notes[2].attrib # explicitly referenced notes should have an id though assert notes[2].attrib["ids"] == "foo"
def test_code_block(app, status, warning): app.builder.build('index') et = etree_parse(app.outdir / 'index.xml') secs = et.findall('./section/section') code_block = secs[0].findall('literal_block') assert len(code_block) > 0 actual = code_block[0].text expect = ( " def ruby?\n" + " false\n" + " end" ) assert actual == expect
def test_literalinclude_classes(app, status, warning): app.builder.build(['classes']) et = etree_parse(app.outdir / 'classes.xml') secs = et.findall('./section/section') code_block = secs[0].findall('literal_block') assert len(code_block) > 0 assert 'foo bar' == code_block[0].get('classes') assert 'code_block' == code_block[0].get('names') literalinclude = secs[1].findall('literal_block') assert len(literalinclude) > 0 assert 'bar baz' == literalinclude[0].get('classes') assert 'literal_include' == literalinclude[0].get('names')
def test_literalinclude_classes(app, status, warning): app.builder.build(['classes']) et = etree_parse(app.outdir / 'classes.xml') secs = et.findall('./section/section') code_block = secs[0].findall('literal_block') assert len(code_block) > 0 assert 'foo bar' == code_block[0].get('classes') assert 'code_block' == code_block[0].get('names') literalinclude = secs[1].findall('literal_block') assert len(literalinclude) > 0 assert 'bar baz' == literalinclude[0].get('classes') assert 'literal_include' == literalinclude[0].get('names')
def test_xml_footnotes(app, warning): app.build() # --- footnotes: regression test for fix #955, #1176 et = etree_parse(app.outdir / 'footnote.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') assert_elem( para0[0], ['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', '2', '[ref]', '1', '100', '*', '. SECOND FOOTNOTE_REF', '100', '.'], ['i18n-with-footnote', 'ref']) # check node_id for footnote_references which refer same footnote (refs: #3002) assert para0[0][4].text == para0[0][6].text == '100' assert para0[0][4].attrib['ids'] != para0[0][6].attrib['ids'] footnote0 = secs[0].findall('footnote') assert_elem( footnote0[0], ['1', 'THIS IS A AUTO NUMBERED FOOTNOTE.'], None, ['1']) assert_elem( footnote0[1], ['100', 'THIS IS A NUMBERED FOOTNOTE.'], None, ['100']) assert_elem( footnote0[2], ['2', 'THIS IS A AUTO NUMBERED NAMED FOOTNOTE.'], None, ['named']) assert_elem( footnote0[3], ['*', 'THIS IS A AUTO SYMBOL FOOTNOTE.'], None, None) citation0 = secs[0].findall('citation') assert_elem( citation0[0], ['ref', 'THIS IS A NAMED FOOTNOTE.'], None, ['ref']) warnings = getwarning(warning) warning_expr = u'.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n' assert_not_re_search(warning_expr, warnings)
def test_xml_footnotes(app, warning): app.build() # --- footnotes: regression test for fix #955, #1176 et = etree_parse(app.outdir / 'footnote.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') assert_elem( para0[0], ['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', '2', '[ref]', '1', '100', '*', '. SECOND FOOTNOTE_REF', '100', '.'], ['i18n-with-footnote', 'ref']) # check node_id for footnote_references which refer same footnote (refs: #3002) assert para0[0][4].text == para0[0][6].text == '100' assert para0[0][4].attrib['ids'] != para0[0][6].attrib['ids'] footnote0 = secs[0].findall('footnote') assert_elem( footnote0[0], ['1', 'THIS IS A AUTO NUMBERED FOOTNOTE.'], None, ['1']) assert_elem( footnote0[1], ['100', 'THIS IS A NUMBERED FOOTNOTE.'], None, ['100']) assert_elem( footnote0[2], ['2', 'THIS IS A AUTO NUMBERED NAMED FOOTNOTE.'], None, ['named']) assert_elem( footnote0[3], ['*', 'THIS IS A AUTO SYMBOL FOOTNOTE.'], None, None) citation0 = secs[0].findall('citation') assert_elem( citation0[0], ['ref', 'THIS IS A NAMED FOOTNOTE.'], None, ['ref']) warnings = getwarning(warning) warning_expr = '.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n' assert_not_re_search(warning_expr, warnings)
def test_xml_footnote_backlinks(app): app.build() # --- footnote backlinks: i18n test for #1058 et = etree_parse(app.outdir / 'footnote.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') refs0 = para0[0].findall('footnote_reference') refid2id = {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').split() assert refid2id[ids] in backrefs
def test_literal_include_block_start_with_comment_or_brank( app, status, warning): app.builder.build(['python']) et = etree_parse(app.outdir / 'python.xml') secs = et.findall('./section/section') literal_include = secs[0].findall('literal_block') assert len(literal_include) > 0 actual = literal_include[0].text expect = ('def block_start_with_comment():\n' ' # Comment\n' ' return 1\n') assert actual == expect actual = literal_include[1].text expect = ('def block_start_with_blank():\n' '\n' ' return 1\n') assert actual == expect
def test_xml_footnote_backlinks(app): app.build() # --- footnote backlinks: i18n test for #1058 et = etree_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').split() assert refid2id[ids] in backrefs
def test_xml_footnotes(app, warning): app.build() # --- footnotes: regression test for fix #955, #1176 et = etree_parse(app.outdir / 'footnote.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') assert_elem( para0[0], ['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', '2', '[ref]', '1', '100', '*', '.'], ['i18n-with-footnote', 'ref']) footnote0 = secs[0].findall('footnote') assert_elem( footnote0[0], ['1', 'THIS IS A AUTO NUMBERED FOOTNOTE.'], None, ['1']) assert_elem( footnote0[1], ['100', 'THIS IS A NUMBERED FOOTNOTE.'], None, ['100']) assert_elem( footnote0[2], ['2', 'THIS IS A AUTO NUMBERED NAMED FOOTNOTE.'], None, ['named']) assert_elem( footnote0[3], ['*', 'THIS IS A AUTO SYMBOL FOOTNOTE.'], None, None) citation0 = secs[0].findall('citation') assert_elem( citation0[0], ['ref', 'THIS IS A NAMED FOOTNOTE.'], None, ['ref']) warnings = getwarning(warning) warning_expr = u'.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n' assert_not_re_search(warning_expr, warnings)
def test_xml_role_xref(app): app.build() # --- role xref: regression test for #1090, #1193 et = etree_parse(app.outdir / 'role_xref.xml') sec1, sec2 = et.findall('section') para1, = sec1.findall('paragraph') assert_elem( para1, ['LINK TO', "I18N ROCK'N ROLE XREF", ',', 'CONTENTS', ',', 'SOME NEW TERM', '.'], ['i18n-role-xref', 'index', 'glossary_terms#term-some-term']) para2 = sec2.findall('paragraph') 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( para2[1], ['LINK TO', 'SAME TYPE LINKS', 'AND', "I18N ROCK'N ROLE XREF", '.'], ['same-type-links', 'i18n-role-xref']) assert_elem( para2[2], ['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', '.'], ['glossary_terms', 'index']) assert_elem( para2[3], ['LINK TO', '--module', 'AND', '-m', '.'], ['cmdoption-module', 'cmdoption-m']) assert_elem( para2[4], ['LINK TO', 'env2', 'AND', 'env1', '.'], ['envvar-env2', 'envvar-env1']) assert_elem( para2[5], ['LINK TO', 'token2', 'AND', 'token1', '.'], []) # 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'])
def test_xml_role_xref(app): app.build() # --- role xref: regression test for #1090, #1193 et = etree_parse(app.outdir / 'role_xref.xml') sec1, sec2 = et.findall('section') para1, = sec1.findall('paragraph') assert_elem( para1, ['LINK TO', "I18N ROCK'N ROLE XREF", ',', 'CONTENTS', ',', 'SOME NEW TERM', '.'], ['i18n-role-xref', 'contents', 'glossary_terms#term-some-term']) para2 = sec2.findall('paragraph') 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( para2[1], ['LINK TO', 'SAME TYPE LINKS', 'AND', "I18N ROCK'N ROLE XREF", '.'], ['same-type-links', 'i18n-role-xref']) assert_elem( para2[2], ['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', '.'], ['glossary_terms', 'contents']) assert_elem( para2[3], ['LINK TO', '--module', 'AND', '-m', '.'], ['cmdoption-module', 'cmdoption-m']) assert_elem( para2[4], ['LINK TO', 'env2', 'AND', 'env1', '.'], ['envvar-env2', 'envvar-env1']) assert_elem( para2[5], ['LINK TO', 'token2', 'AND', 'token1', '.'], []) # 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'])
def test_qthelp_escaped(app, status, warning): app.builder.build_all() et = etree_parse(app.outdir / 'needbescapedbproject.qhp') customFilter = et.find('.//customFilter') assert len(customFilter) == 2 assert customFilter.attrib == {'name': 'need <b>"escaped"</b> project '} assert customFilter[0].text == 'needbescapedbproject' assert customFilter[1].text is None toc = et.find('.//toc') assert len(toc) == 1 assert toc[0].attrib == { 'title': 'need <b>"escaped"</b> project documentation', 'ref': 'index.html' } assert len(toc[0]) == 4 assert toc[0][0].attrib == {'title': '<foo>', 'ref': 'foo.html'} assert toc[0][0][0].attrib == {'title': 'quux', 'ref': 'quux.html'} assert toc[0][0][1].attrib == {'title': 'foo "1"', 'ref': 'foo.html#foo-1'} assert toc[0][0][1][0].attrib == { 'title': 'foo.1-1', 'ref': 'foo.html#foo-1-1' } assert toc[0][0][2].attrib == {'title': 'foo.2', 'ref': 'foo.html#foo-2'} assert toc[0][1].attrib == {'title': 'bar', 'ref': 'bar.html'} assert toc[0][2].attrib == { 'title': 'http://sphinx-doc.org/', 'ref': 'http://sphinx-doc.org/' } assert toc[0][3].attrib == {'title': 'baz', 'ref': 'baz.html'} keywords = et.find('.//keywords') assert len(keywords) == 2 assert keywords[0].attrib == { 'name': '<subsection>', 'ref': 'index.html#index-0' } assert keywords[1].attrib == { 'name': '"subsection"', 'ref': 'index.html#index-0' }
def test_literal_include_block_start_with_comment_or_brank(app, status, warning): app.builder.build(['python']) et = etree_parse(app.outdir / 'python.xml') secs = et.findall('./section/section') literal_include = secs[0].findall('literal_block') assert len(literal_include) > 0 actual = literal_include[0].text expect = ( 'def block_start_with_comment():\n' ' # Comment\n' ' return 1\n' ) assert actual == expect actual = literal_include[1].text expect = ( 'def block_start_with_blank():\n' '\n' ' return 1\n' ) assert actual == expect
def test_xml_footnotes(app, warning): app.build() # --- footnotes: regression test for fix #955, #1176 et = etree_parse(app.outdir / 'footnote.xml') secs = et.findall('section') para0 = secs[0].findall('paragraph') assert_elem( para0[0], ['I18N WITH FOOTNOTE', 'INCLUDE THIS CONTENTS', '2', '[ref]', '1', '100', '.'], ['i18n-with-footnote', 'ref']) footnote0 = secs[0].findall('footnote') assert_elem( footnote0[0], ['1', 'THIS IS A AUTO NUMBERED FOOTNOTE.'], None, ['1']) assert_elem( footnote0[1], ['100', 'THIS IS A NUMBERED FOOTNOTE.'], None, ['100']) assert_elem( footnote0[2], ['2', 'THIS IS A AUTO NUMBERED NAMED FOOTNOTE.'], None, ['named']) citation0 = secs[0].findall('citation') assert_elem( citation0[0], ['ref', 'THIS IS A NAMED FOOTNOTE.'], None, ['ref']) warnings = getwarning(warning) warning_expr = u'.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n' assert_not_re_search(warning_expr, warnings)
def test_literalinclude_pydecorators(app, status, warning): app.builder.build(['py-decorators']) et = etree_parse(app.outdir / 'py-decorators.xml') secs = et.findall('./section/section') literal_include = secs[0].findall('literal_block') assert len(literal_include) == 3 actual = literal_include[0].text expect = ( '@class_decorator\n' '@other_decorator()\n' 'class TheClass(object):\n' '\n' ' @method_decorator\n' ' @other_decorator()\n' ' def the_method():\n' ' pass\n' ) assert actual == expect actual = literal_include[1].text expect = ( ' @method_decorator\n' ' @other_decorator()\n' ' def the_method():\n' ' pass\n' ) assert actual == expect actual = literal_include[2].text expect = ( '@function_decorator\n' '@other_decorator()\n' 'def the_function():\n' ' pass\n' ) assert actual == expect
def test_literalinclude_pydecorators(app, status, warning): app.builder.build(['py-decorators']) et = etree_parse(app.outdir / 'py-decorators.xml') secs = et.findall('./section/section') literal_include = secs[0].findall('literal_block') assert len(literal_include) == 3 actual = literal_include[0].text expect = ( '@class_decorator\n' '@other_decorator()\n' 'class TheClass(object):\n' '\n' ' @method_decorator\n' ' @other_decorator()\n' ' def the_method():\n' ' pass\n' ) assert actual == expect actual = literal_include[1].text expect = ( ' @method_decorator\n' ' @other_decorator()\n' ' def the_method():\n' ' pass\n' ) assert actual == expect actual = literal_include[2].text expect = ( '@function_decorator\n' '@other_decorator()\n' 'def the_function():\n' ' pass\n' ) assert actual == expect
def test_qthelp_escaped(app, status, warning): app.builder.build_all() et = etree_parse(app.outdir / 'needbescapedbproject.qhp') customFilter = et.find('.//customFilter') assert len(customFilter) == 2 assert customFilter.attrib == {'name': 'need <b>"escaped"</b> project '} assert customFilter[0].text == 'needbescapedbproject' assert customFilter[1].text is None toc = et.find('.//toc') assert len(toc) == 1 assert toc[0].attrib == { 'title': 'need <b>"escaped"</b> project documentation', 'ref': 'index.html' } assert len(toc[0]) == 4 assert toc[0][0].attrib == {'title': '<foo>', 'ref': 'foo.html'} assert toc[0][0][0].attrib == {'title': 'quux', 'ref': 'quux.html'} assert toc[0][0][1].attrib == {'title': 'foo "1"', 'ref': 'foo.html#foo-1'} assert toc[0][0][1][0].attrib == { 'title': 'foo.1-1', 'ref': 'foo.html#foo-1-1' } assert toc[0][0][2].attrib == {'title': 'foo.2', 'ref': 'foo.html#foo-2'} assert toc[0][1].attrib == {'title': 'bar', 'ref': 'bar.html'} assert toc[0][2].attrib == { 'title': 'http://sphinx-doc.org/', 'ref': 'http://sphinx-doc.org/' } assert toc[0][3].attrib == {'title': 'baz', 'ref': 'baz.html'} keywords = et.find('.//keywords') assert len(keywords) == 8 assert keywords[0].attrib == { 'name': '<subsection>', 'ref': 'index.html#index-0' } assert keywords[1].attrib == { 'name': '& (ampersand)', 'id': 'ampersand.&', 'ref': 'index.html#index-0' } assert keywords[2].attrib == { 'name': '< (less)', 'id': 'less.<', 'ref': 'index.html#index-0' } assert keywords[3].attrib == { 'name': '"subsection"', 'ref': 'index.html#index-0' } assert keywords[4].attrib == { 'name': '> (greater)', 'id': 'greater.>', 'ref': 'index.html#index-0' } assert keywords[5].attrib == { 'name': 'keyword1 (class in ID)', 'id': 'ID.keyword1', 'ref': 'index.html#index-0' } assert keywords[6].attrib == { 'name': 'keyword2 (foo bar baz)', 'ref': 'index.html#index-0' } assert keywords[7].attrib == { 'name': 'Sphinx (document generator)', 'id': 'document.Sphinx', 'ref': 'index.html#index-0' }
def test_doctree_awesome_theme(app: Sphinx) -> None: """It tests the correct structure of the doctree.""" app.build() tree = etree_parse(os.path.join(app.outdir, "index.xml")) code_blocks = tree.findall(".//literal_block") assert len(code_blocks) == 8 # first block is without anything assert code_blocks[0].attrib["language"] == "default" assert "ids" not in code_blocks[0].attrib assert "names" not in code_blocks[0].attrib # second block has an explicit ID assert code_blocks[1].attrib["language"] == "default" assert code_blocks[1].attrib["ids"] == "foo" assert code_blocks[1].attrib["names"] == "foo" # third block is inside a container (test later) assert code_blocks[2].attrib["language"] == "python" assert "ids" not in code_blocks[2].attrib assert "names" not in code_blocks[2].attrib # fourth block is inside container AND has explicit label # the ids are applied to the container, so it looks exactly # like the third block assert code_blocks[3].attrib["language"] == "python" assert "ids" not in code_blocks[2].attrib assert "names" not in code_blocks[2].attrib # fifth block has linenumbers enabled assert code_blocks[4].attrib["linenos"] == "True" # sixth block has emphasized lines assert code_blocks[5].attrib["highlight_args"] == "{'hl_lines': [1]}" # seventh block has added/removed lines assert code_blocks[6].attrib["highlight_args"] == ( "{'hl_added': [1], 'hl_removed': [2]}") # container wrappers containers = tree.findall(".//container") assert len(containers) == 3 assert containers[0].attrib["classes"] == "highlight" assert containers[1].attrib["classes"] == "highlight" assert containers[2].attrib["classes"] == "bogus" assert containers[0].attrib["language"] == "python" assert containers[1].attrib["language"] == "python" assert "language" not in containers[2].attrib assert containers[0].attrib["literal_block"] == "True" assert containers[1].attrib["literal_block"] == "True" assert "literal_block" not in containers[2].attrib assert containers[0].attrib["ids"] == "id1" assert "names" not in containers[0].attrib assert containers[1].attrib["ids"] == "id2 bar" assert containers[1].attrib["names"] == "bar" assert "names" not in containers[2].attrib # should have two children assert len(containers[0]) == len(containers[1]) == 2 assert containers[0][0].tag == "caption" assert containers[0][0].text == "test" assert containers[0][1].tag == "literal_block" assert containers[1][0].tag == "caption" assert containers[1][0].text == "test" assert containers[1][1].tag == "literal_block"