1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
5 from unittest import TestCase
6 from librarian import NoDublinCore
7 from librarian.builders import builders
8 from librarian.document import WLDocument
9 from librarian.parser import WLDocument as LegacyWLDocument
10 from .utils import get_fixture
13 class TransformTest(TestCase):
16 def test_transform_legacy(self):
17 expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.legacy.html')
19 html = LegacyWLDocument.from_file(
20 get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
21 ).as_html().get_bytes().decode('utf-8')
23 html = re.sub(r'idm\d+', 'idmNNN', html)
24 with open(expected_output_file_path) as f:
25 self.assertEqual(f.read(), html)
27 def test_transform(self):
28 expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.html')
30 filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
31 ).build(builders['html']).get_bytes().decode('utf-8')
33 with open(expected_output_file_path) as f:
34 self.assertEqual(html, f.read())
36 def test_no_dublincore(self):
37 with self.assertRaises(NoDublinCore):
38 LegacyWLDocument.from_file(
39 get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
42 def test_passing_parse_dublincore_to_transform(self):
43 """Passing parse_dublincore=False to transform omits DublinCore parsing."""
44 LegacyWLDocument.from_file(
45 get_fixture('text', 'asnyk_miedzy_nami_nodc.xml'),
46 parse_dublincore=False,
51 LegacyWLDocument.from_bytes(
53 parse_dublincore=False,