From d86efb91927dfd75cd3d02039a3fe9ede2644ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Fdez=2E=20Galv=C3=A1n?= Date: Tue, 17 Mar 2015 15:57:51 +0100 Subject: [PATCH] Test for alternate stylesheets --- .../test-stylesheets/_templates/layout.html | 7 +++ tests/roots/test-stylesheets/conf.py | 12 ++++++ tests/roots/test-stylesheets/index.rst | 4 ++ tests/test_build_html.py | 43 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 tests/roots/test-stylesheets/_templates/layout.html create mode 100644 tests/roots/test-stylesheets/conf.py create mode 100644 tests/roots/test-stylesheets/index.rst diff --git a/tests/roots/test-stylesheets/_templates/layout.html b/tests/roots/test-stylesheets/_templates/layout.html new file mode 100644 index 000000000..3e561619b --- /dev/null +++ b/tests/roots/test-stylesheets/_templates/layout.html @@ -0,0 +1,7 @@ +{% extends "!layout.html" %} +{% set css_files = css_files + ["_static/more_persistent.css", + {"filename": "_static/more_persistent2.css"}, + {"filename": "_static/more_default.css", "title": "Default", "alternate": False}, + {"filename": "_static/more_alternate1.css", "title": "Alternate"}, + {"filename": "_static/more_alternate2.css", "alternate": True}] %} + diff --git a/tests/roots/test-stylesheets/conf.py b/tests/roots/test-stylesheets/conf.py new file mode 100644 index 000000000..8e072de59 --- /dev/null +++ b/tests/roots/test-stylesheets/conf.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + +master_doc = 'index' +html_theme = 'classic' +templates_path = ['_templates'] + +def setup(app): + app.add_stylesheet('persistent.css') + app.add_stylesheet('default.css', title="Default", alternate=False) + app.add_stylesheet('alternate1.css', title="Alternate") + app.add_stylesheet('alternate2.css', alternate=True) + diff --git a/tests/roots/test-stylesheets/index.rst b/tests/roots/test-stylesheets/index.rst new file mode 100644 index 000000000..c5c5766ba --- /dev/null +++ b/tests/roots/test-stylesheets/index.rst @@ -0,0 +1,4 @@ +test-stylesheets +================ + +Lorem ipsum dolor diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3ee89b72b..adefa5c11 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -919,3 +919,46 @@ def test_numfig_with_secnum_depth(app, status, warning): for xpath, check, be_found in paths: yield check_xpath, etree, fname, xpath, check, be_found + +@gen_with_app(buildername='html', testroot='stylesheets') +def test_alternate_stylesheets(app, status, warning): + app.builder.build_all() + + expects = { + 'index.html': [ + (".//link[@href='_static/persistent.css']" + "[@rel='stylesheet']", '', True), + (".//link[@href='_static/default.css']" + "[@rel='stylesheet']" + "[@title='Default']", '', True), + (".//link[@href='_static/alternate1.css']" + "[@rel='alternate stylesheet']" + "[@title='Alternate']", '', True), + (".//link[@href='_static/alternate2.css']" + "[@rel='alternate stylesheet']", '', True), + (".//link[@href='_static/more_persistent.css']" + "[@rel='stylesheet']", '', True), + (".//link[@href='_static/more_persistent2.css']" + "[@rel='stylesheet']", '', True), + (".//link[@href='_static/more_default.css']" + "[@rel='stylesheet']" + "[@title='Default']", '', True), + (".//link[@href='_static/more_alternate1.css']" + "[@rel='alternate stylesheet']" + "[@title='Alternate']", '', True), + (".//link[@href='_static/more_alternate2.css']" + "[@rel='alternate stylesheet']", '', True), + ], + } + + for fname, paths in iteritems(expects): + parser = NslessParser() + parser.entity.update(html_entities.entitydefs) + fp = open(os.path.join(app.outdir, fname), 'rb') + try: + etree = ET.parse(fp, parser) + finally: + fp.close() + + for xpath, check, be_found in paths: + yield check_xpath, etree, fname, xpath, check, be_found