#!/usr/bin/env python3 # $Id: test_s5.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 S5/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 class WriterPublishTestCase(unittest.TestCase): def test_publish(self): writer_name = 's5' settings = { '_disable_config': True, 'strict_visitor': True, 'stylesheet_path': '/test.css', 'embed_stylesheet': False, 'report_level': 3, # suppress "can't copy themes" warning } for name, cases in totest_1.items(): for casenum, (case_input, case_expected) in enumerate(cases): with self.subTest(id=f'totest_1[{name!r}][{casenum}]'): output = publish_string( source=case_input, writer_name=writer_name, settings_overrides=settings.copy() ).decode() self.assertEqual(case_expected, output) settings['hidden_controls'] = False settings['view_mode'] = 'outline' for name, cases in totest_2.items(): for casenum, (case_input, case_expected) in enumerate(cases): with self.subTest(id=f'totest_2[{name!r}][{casenum}]'): output = publish_string( source=case_input, writer_name=writer_name, settings_overrides=settings.copy() ).decode() self.assertEqual(case_expected, output) if platform.system() == "Windows": drive_prefix = os.path.splitdrive(os.getcwd())[0] else: drive_prefix = "" totest_1 = {} totest_2 = {} totest_1['basics'] = [ ["""\ ============ Show Title ============ Title slide First Slide =========== Slide text. """, f"""\ Show Title

Show Title

Title slide

First Slide

Slide text.

"""] ] totest_2['settings'] = [ ["""\ ================== Bogus Slide Show ================== We're just checking the settings """, f"""\ Bogus Slide Show

Bogus Slide Show

We're just checking the settings

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