summaryrefslogtreecommitdiff
path: root/tests/test_build_htmlhelp.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_build_htmlhelp.py')
-rw-r--r--tests/test_build_htmlhelp.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/tests/test_build_htmlhelp.py b/tests/test_build_htmlhelp.py
index 18acca921..4ad244a4e 100644
--- a/tests/test_build_htmlhelp.py
+++ b/tests/test_build_htmlhelp.py
@@ -11,10 +11,9 @@
import re
import pytest
+from html5lib import HTMLParser
-from sphinx.builders.htmlhelp import chm_htmlescape
-
-from sphinx.builders.htmlhelp import default_htmlhelp_basename
+from sphinx.builders.htmlhelp import chm_htmlescape, default_htmlhelp_basename
from sphinx.config import Config
@@ -72,6 +71,52 @@ def test_chm(app):
assert m is None, 'Hex escaping exists in .hhk file: ' + str(m.group(0))
+@pytest.mark.sphinx('htmlhelp', testroot='htmlhelp-hhc')
+def test_htmlhelp_hhc(app):
+ app.build()
+
+ def assert_sitemap(node, name, filename):
+ assert node.tag == 'object'
+ assert len(node) == 2
+ assert node[0].tag == 'param'
+ assert node[0].attrib == {'name': 'Name', 'value': name}
+ assert node[1].tag == 'param'
+ assert node[1].attrib == {'name': 'Local', 'value': filename}
+
+ # .hhc file
+ hhc = (app.outdir / 'pythondoc.hhc').text()
+ tree = HTMLParser(namespaceHTMLElements=False).parse(hhc)
+ items = tree.find('.//body/ul')
+ assert len(items) == 4
+
+ # index
+ assert items[0].tag == 'li'
+ assert len(items[0]) == 1
+ assert_sitemap(items[0][0], "Sphinx's documentation", 'index.html')
+
+ # py-modindex
+ assert items[1].tag == 'li'
+ assert len(items[1]) == 1
+ assert_sitemap(items[1][0], 'Python Module Index', 'py-modindex.html')
+
+ # toctree
+ assert items[2].tag == 'li'
+ assert len(items[2]) == 2
+ assert_sitemap(items[2][0], 'foo', 'foo.html')
+
+ assert items[2][1].tag == 'ul'
+ assert len(items[2][1]) == 1
+ assert items[2][1][0].tag == 'li'
+ assert_sitemap(items[2][1][0][0], 'bar', 'bar.html')
+
+ assert items[3].tag == 'li'
+ assert len(items[3]) == 1
+ assert_sitemap(items[3][0], 'baz', 'baz.html')
+
+ # single quotes should be escaped as decimal (')
+ assert "Sphinx's documentation" in hhc
+
+
def test_chm_htmlescape():
assert chm_htmlescape('Hello world') == 'Hello world'
assert chm_htmlescape(u'Unicode 文字') == u'Unicode 文字'