d75228e483fbbd97af88e121e68ff5a43f597f99
[librarian.git] / tests / test_ref.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from unittest import TestCase
5 from librarian.builders import builders
6 from librarian.document import WLDocument
7 from tests.utils import get_fixture
8 from lxml import etree
9
10
11 class RefTests(TestCase):
12     def test_snippet(self):
13         doc = WLDocument(filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml'))
14
15         hb = builders['html']()
16         hb.assign_ids(doc.tree)
17
18         refs = []
19         for ref in doc.references():
20             snippet = ref.get_snippet()
21             b = builders['html-snippet']()
22
23             for s in snippet:
24                 s.html_build(b)
25             refs.append(
26                 '\n'.join((
27                     ref.get_link(),
28                     b.output().get_bytes().decode('utf-8')
29                 ))
30             )
31         output = '\n\n'.join(refs)
32         with open(get_fixture('text', 'asnyk_miedzy_nami_refs.html')) as f:
33             self.assertEqual(output, f.read())
34