#!/usr/bin/env python3
# $Id: test_html5_template.py 9911 2024-08-21 08:05:47Z milde $
# Author: David Goodger
# Copyright: This module has been placed in the public domain.
"""
Tests for the HTML writer.
"""
import os
import platform
from pathlib import Path
import sys
import unittest
if __name__ == '__main__':
# prepend the "docutils root" to the Python library path
# so we import the local `docutils` package.
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
import docutils
from docutils.core import publish_string
from docutils.writers import html5_polyglot
# TEST_ROOT is ./test/ from the docutils root
TEST_ROOT = Path(__file__).parents[1]
class WriterPublishTestCase(unittest.TestCase):
# maxDiff = None
def test_publish(self):
template_path = TEST_ROOT / 'data/full-template.txt'
for name, cases in totest.items():
for casenum, (case_input, case_expected) in enumerate(cases):
with self.subTest(id=f'totest[{name!r}][{casenum}]'):
output = publish_string(
source=case_input,
writer=html5_polyglot.Writer(),
settings_overrides={
'_disable_config': True,
'strict_visitor': True,
'template': template_path,
'stylesheet_path': '/test.css',
'embed_stylesheet': False,
}).decode()
self.assertEqual(case_expected, output)
if platform.system() == "Windows":
drive_prefix = os.path.splitdrive(os.getcwd())[0]
else:
drive_prefix = ""
totest = {}
totest['template'] = [
["""\
================
Document Title
================
----------
Subtitle
----------
:Author: Me
.. footer:: footer text
Section
=======
Some text.
""",
fr'''head_prefix = """\
"""
head = """\
Document Title"""
stylesheet = """\
"""
body_prefix = """\
"""
body_pre_docinfo = """\
Document Title
Subtitle
"""
docinfo = """\
- Author:
Me
"""
body = """\
"""
body_suffix = """\
"""
head_prefix = """\
"""
head = """\
Document Title"""
stylesheet = """\
"""
body_prefix = """\
"""
body_pre_docinfo = """\
Document Title
Subtitle
"""
docinfo = """\
- Author:
Me
"""
body = """\
"""
body_suffix = """\
"""
title = """\
Document Title"""
subtitle = """\
Subtitle"""
header = """\
"""
footer = """\
"""
meta = """\
"""
fragment = """\
"""
html_prolog = """\
"""
html_head = """\
Document Title"""
html_title = """\
Document Title
"""
html_subtitle = """\
Subtitle
"""
html_body = """\
Document Title
Subtitle
- Author:
Me
"""
''']
]
if __name__ == '__main__':
unittest.main()