#!/usr/bin/env python3 # $Id: test_html4css1_template.py 9425 2023-06-30 14:56:47Z milde $ # Author: David Goodger # Copyright: This module has been placed in the public domain. """ Tests for the HTML writer. """ from pathlib import Path import os import platform 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 # TEST_ROOT is ./test/ from the docutils root TEST_ROOT = os.path.abspath(os.path.join(__file__, '..', '..')) class WriterPublishTestCase(unittest.TestCase): # maxDiff = None def test_publish(self): writer_name = 'html4' template_path = os.path.join(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_name=writer_name, 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 = """\

Section

Some text.

""" body_suffix = """\
""" head_prefix = """\ """ head = """\ Document Title""" stylesheet = """\ """ body_prefix = """\
""" body_pre_docinfo = """\

Document Title

Subtitle

""" docinfo = """\
Author: Me
""" body = """\

Section

Some text.

""" body_suffix = """\
""" title = """\ Document Title""" subtitle = """\ Subtitle""" header = """\ """ footer = """\ """ meta = """\ """ fragment = """\

Section

Some text.

""" html_prolog = """\ """ html_head = """\ Document Title""" html_title = """\

Document Title

""" html_subtitle = """\

Subtitle

""" html_body = """\

Document Title

Subtitle

Author: Me

Section

Some text.

""" '''] ] if __name__ == '__main__': unittest.main()