summaryrefslogtreecommitdiff
path: root/tests/test_build_html5.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-09-29 21:12:40 +0900
committerGitHub <noreply@github.com>2018-09-29 21:12:40 +0900
commit973c3ffa25f6f14e53382f7a45ffbeee9d252b3c (patch)
treed4d500f2dad3bbdab82820f1f4bb2ae5bc97a6ff /tests/test_build_html5.py
parentabcb5bd5eca6ea46ffcc34a55b663083d03f339c (diff)
parentd2c3d54bb9a46c5e7a0d14c3345e489d7592de9a (diff)
downloadsphinx-git-973c3ffa25f6f14e53382f7a45ffbeee9d252b3c.tar.gz
Merge branch 'master' into change_master_doc_to_index
Diffstat (limited to 'tests/test_build_html5.py')
-rw-r--r--tests/test_build_html5.py55
1 files changed, 52 insertions, 3 deletions
diff --git a/tests/test_build_html5.py b/tests/test_build_html5.py
index d839b9741..fc2c7e8eb 100644
--- a/tests/test_build_html5.py
+++ b/tests/test_build_html5.py
@@ -14,7 +14,9 @@
:license: BSD, see LICENSE for details.
"""
+import re
import xml.etree.cElementTree as ElementTree
+from hashlib import md5
import pytest
from html5lib import getTreeBuilder, HTMLParser
@@ -58,7 +60,7 @@ def cached_etree_parse():
(".//img[@src='../_images/rimg.png']", ''),
],
'subdir/includes.html': [
- (".//a[@href='../_downloads/img.png']", ''),
+ (".//a[@class='reference download internal']", ''),
(".//img[@src='../_images/img.png']", ''),
(".//p", 'This is an include file.'),
(".//pre/span", 'line 1'),
@@ -66,8 +68,7 @@ def cached_etree_parse():
],
'includes.html': [
(".//pre", u'Max Strauß'),
- (".//a[@href='_downloads/img.png']", ''),
- (".//a[@href='_downloads/img1.png']", ''),
+ (".//a[@class='reference download internal']", ''),
(".//pre/span", u'"quotes"'),
(".//pre/span", u"'included'"),
(".//pre/span[@class='s2']", u'üöä'),
@@ -321,3 +322,51 @@ def test_html5_output(app, cached_etree_parse, fname, expect):
app.build()
print(app.outdir / fname)
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
+
+
+@pytest.mark.sphinx('html', tags=['testtag'], confoverrides={
+ 'html_context.hckey_co': 'hcval_co',
+ 'html_experimental_html5_writer': True})
+@pytest.mark.test_params(shared_result='test_build_html_output')
+def test_html_download(app):
+ app.build()
+
+ # subdir/includes.html
+ result = (app.outdir / 'subdir' / 'includes.html').text()
+ pattern = ('<a class="reference download internal" download="" '
+ 'href="../(_downloads/.*/img.png)">')
+ matched = re.search(pattern, result)
+ assert matched
+ assert (app.outdir / matched.group(1)).exists()
+ filename = matched.group(1)
+
+ # includes.html
+ result = (app.outdir / 'includes.html').text()
+ pattern = ('<a class="reference download internal" download="" '
+ 'href="(_downloads/.*/img.png)">')
+ matched = re.search(pattern, result)
+ assert matched
+ assert (app.outdir / matched.group(1)).exists()
+ assert matched.group(1) == filename
+
+
+@pytest.mark.sphinx('html', testroot='roles-download',
+ confoverrides={'html_experimental_html5_writer': True})
+def test_html_download_role(app, status, warning):
+ app.build()
+ digest = md5((app.srcdir / 'dummy.dat').encode('utf-8')).hexdigest()
+ assert (app.outdir / '_downloads' / digest / 'dummy.dat').exists()
+
+ content = (app.outdir / 'index.html').text()
+ assert (('<li><p><a class="reference download internal" download="" '
+ 'href="_downloads/%s/dummy.dat">'
+ '<code class="xref download docutils literal notranslate">'
+ '<span class="pre">dummy.dat</span></code></a></p></li>' % digest)
+ in content)
+ assert ('<li><p><code class="xref download docutils literal notranslate">'
+ '<span class="pre">not_found.dat</span></code></p></li>' in content)
+ assert ('<li><p><a class="reference download external" download="" '
+ 'href="http://www.sphinx-doc.org/en/master/_static/sphinxheader.png">'
+ '<code class="xref download docutils literal notranslate">'
+ '<span class="pre">Sphinx</span> <span class="pre">logo</span>'
+ '</code></a></p></li>' in content)