3 from unittest import TestCase
4 from librarian.builders import HtmlBuilder
5 from librarian.document import WLDocument
6 from librarian.elements import WL_ELEMENTS
7 from .utils import get_fixture, get_all_fixtures
10 class HtmlExamplesTests(TestCase):
15 with open(get_fixture('tags', 'base.xml'), 'rb') as f:
16 cls.base_xml = f.read()
18 def test_examples(self):
19 for tag in WL_ELEMENTS:
20 with self.subTest(tag):
22 for path in get_all_fixtures('tags'):
23 if os.path.isdir(path):
24 name = path.rsplit('/', 1)[1]
25 self.assertIn(name, WL_ELEMENTS)
27 def tag_test(self, tag):
28 for fixture in get_all_fixtures(f'tags/{tag}', '*.xml'):
29 with self.subTest(tag=tag, n=fixture.rsplit('/', 1)[-1].rsplit('.', 1)[0]):
30 with open(fixture, 'rb') as f:
32 xml_file = io.BytesIO(self.base_xml.replace(b'<!-- INPUT -->', xml_input))
33 doc = WLDocument(filename=xml_file)
34 html = HtmlBuilder(base_url='/').build(doc).get_bytes().decode('utf-8')
36 with open(fixture.rsplit('.', 1)[0] + '.expected.html', 'r') as f:
37 expected_html = f.read()
39 with open(fixture.rsplit('.', 1)[0] + '.expected.toc.html', 'r') as f:
40 expected_toc = f.read()
44 with open(fixture.rsplit('.', 1)[0] + '.expected.themes.html', 'r') as f:
45 expected_themes = f.read()
49 self.assertEqual(html, expected_html)