#! /usr/bin/env python
# coding: utf-8
# $Id: test_html5_polyglot_misc.py 8115 2017-06-16 20:50:47Z milde $
# Authors: Lea Wiemann, Dmitry Shachnev, Günter Milde
# Maintainer: docutils-develop@lists.sourceforge.net
# Copyright: This module has been placed in the public domain.
"""
Miscellaneous HTML writer tests.
"""
from __init__ import DocutilsTestSupport
from docutils import core
from docutils._compat import b
import os
class EncodingTestCase(DocutilsTestSupport.StandardTestCase):
def test_xmlcharrefreplace(self):
# Test that xmlcharrefreplace is the default output encoding
# error handler.
settings_overrides={
'output_encoding': 'latin1',
'stylesheet': '',
'_disable_config': True,}
result = core.publish_string(
u'EUR = \u20ac', writer_name='html5_polyglot',
settings_overrides=settings_overrides)
# Encoding a euro sign with latin1 doesn't work, so the
# xmlcharrefreplace handler is used.
self.assertIn(b('EUR = €'), result)
class MovingArgsTestCase(DocutilsTestSupport.StandardTestCase):
settings_overrides={'stylesheet_path': '',
# 'embed_stylesheet': False,
'_disable_config': True,
}
def test_definition_list_item_classes(self):
# Do not drop class arguments for the definition list item.
# Pass them to the term node instead.
data = """\
first term:
fist def
.. class:: for the second item
second term:
second def
"""
result = core.publish_string(data, writer_name='html5_polyglot',
settings_overrides=self.settings_overrides)
self.assertIn(b('
second term:'),
result)
def test_definition_list_item_name(self):
# Do not drop the "name" of the definition list item.
# Pass it to to the term node instead.
data = """\
first term:
first def
.. _second item:
second term:
second def
"""
result = core.publish_string(data, writer_name='html5_polyglot',
settings_overrides=self.settings_overrides)
self.assertIn(b('second term:'),
result)
class SettingsTestCase(DocutilsTestSupport.StandardTestCase):
data = 'test'
def test_default_stylesheet(self):
# default style sheet, embedded
mysettings = {'_disable_config': True,}
styles = core.publish_parts(self.data, writer_name='html5_polyglot',
settings_overrides=mysettings)['stylesheet']
self.assertIn('Minimal style sheet '
'for the HTML output of Docutils.', styles)
def test_default_stylesheet_linked(self):
# default style sheet, linked
mysettings = {'_disable_config': True,
'embed_stylesheet': False}
styles = core.publish_parts(self.data, writer_name='html5_polyglot',
settings_overrides=mysettings)['stylesheet']
self.assertIn('docutils/writers/html5_polyglot/minimal.css', styles)
def test_math_stylesheet_linked(self):
# default + math style sheet, linked
mysettings = {'_disable_config': True,
'embed_stylesheet': False,
'stylesheet_path': 'minimal.css, math.css'}
styles = core.publish_parts(self.data, writer_name='html5_polyglot',
settings_overrides=mysettings)['stylesheet']
self.assertIn('docutils/writers/html5_polyglot/minimal.css', styles)
self.assertIn('docutils/writers/html5_polyglot/math.css', styles)
def test_custom_stylesheet_linked(self):
# default + custom style sheet, linked
mysettings = {'_disable_config': True,
'embed_stylesheet': False,
'stylesheet_path': 'minimal.css, '
'data/ham.css'}
styles = core.publish_parts(self.data, writer_name='html5_polyglot',
settings_overrides=mysettings)['stylesheet']
self.assertIn('docutils/writers/html5_polyglot/minimal.css', styles)
self.assertIn('href="data/ham.css"', styles)
def test_custom_stylesheet_dir(self):
mysettings = {'_disable_config': True,
'embed_stylesheet': False,
'stylesheet_dirs': ('../docutils/writers/html5_polyglot/',
'data'),
'stylesheet_path': 'minimal.css, ham.css'}
styles = core.publish_parts(self.data, writer_name='html5_polyglot',
settings_overrides=mysettings)['stylesheet']
if os.path.isdir('../docutils/writers/html5_polyglot/'):
self.assertIn('docutils/writers/html5_polyglot/minimal.css', styles)
self.assertIn('href="data/ham.css"', styles)
def test_custom_stylesheet_dir_embedded(self):
mysettings = {'_disable_config': True,
'embed_stylesheet': True,
'stylesheet_dirs': ('../docutils/writers/html5_polyglot/',
'data'),
'stylesheet_path': 'ham.css'}
styles = core.publish_parts(self.data, writer_name='html5_polyglot',
settings_overrides=mysettings)['stylesheet']
self.assertIn('dl.docutils dd {\n margin-bottom: 0.5em }', styles)
class MathTestCase(DocutilsTestSupport.StandardTestCase):
"""Attention: This class tests the current implementation of maths support
which is open to change in future Docutils releases. """
mathjax_script = '