X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/4e329824f40367945de11d3647396859092f5c2c..refs/heads/master:/tests/test_html_annotations.py
diff --git a/tests/test_html_annotations.py b/tests/test_html_annotations.py
index 410577c..ccf8030 100644
--- a/tests/test_html_annotations.py
+++ b/tests/test_html_annotations.py
@@ -1,24 +1,41 @@
-# -*- coding: utf-8
-from __future__ import unicode_literals
-
-from librarian.parser import WLDocument
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
+#
+import io
+import unittest
+from librarian.builders import HtmlBuilder
+from librarian.document import WLDocument
from librarian.html import extract_annotations
-from nose.tools import eq_
-
-
-def _test_annotation(expected, got, name):
- assert got[0].startswith('anchor-'), "%s: Unexpected anchor: '%s', should begin with 'anchor-'" % (name, got[0])
- eq_(expected[0], got[1], "%s: Unexpected type, expected '%s', got '%s'" % (name, expected[0], got[1]))
- eq_(expected[1], got[2], "%s: Unexpected qualifier, expected '%s', got '%s'" % (name, expected[1], got[2]))
- eq_(expected[2], got[3], "%s: Unexpected text representation, expected '%s', got '%s'" %
- (name, expected[2], got[3]))
- exp_html = '
%s
' % (expected[0], expected[3])
- eq_(exp_html, got[4], "%s: Unexpected html representation, expected '%s', got '%s'" % (name, exp_html, got[4]))
-
-def test_annotations():
- annotations = (
+class AnnotationsTests(unittest.TestCase):
+ maxDiff = None
+
+ def _test_annotation(self, expected, got, name):
+ self.assertTrue(
+ got[0].startswith('anchor-'),
+ "%s: Unexpected anchor: '%s', should begin with 'anchor-'" % (name, got[0])
+ )
+ self.assertEqual(
+ expected[0], got[1],
+ "%s: Unexpected type, expected '%s', got '%s'" % (name, expected[0], got[1])
+ )
+ self.assertEqual(
+ expected[1], got[2],
+ "%s: Unexpected qualifier, expected '%s', got '%s'" % (name, expected[1], got[2])
+ )
+ self.assertEqual(
+ expected[2], got[3],
+ "%s: Unexpected text representation, expected '%s', got '%s'" % (name, expected[2], got[3])
+ )
+ exp_html = '%s
' % (expected[0], expected[3])
+ self.assertEqual(
+ exp_html, got[4],
+ "%s: Unexpected html representation, expected '%s', got '%s'" % (name, exp_html, got[4])
+ )
+
+ def test_annotations(self):
+ annotations = (
('', (
'pe',
[],
@@ -95,21 +112,21 @@ def test_annotations():
'czÄÅciej: gemajn, szeregowiec w wojsku polskim cudzoziemskiego autoramentu.', (
'pe',
['daw.', 'niem.'],
- 'gemajna (daw., z niem. gemein: zwykÅy) \u2014 czÄÅciej: gemajn, '
- 'szeregowiec w wojsku polskim cudzoziemskiego autoramentu. [przypis edytorski]',
- 'gemajna (daw., z niem. gemein: zwykÅy) '
- '\u2014 czÄÅciej: gemajn, szeregowiec w wojsku polskim cudzoziemskiego autoramentu. [przypis edytorski]
'
+ 'gemajna (daw., z\u00A0niem. gemein: zwykÅy) \u2014 czÄÅciej: gemajn, '
+ 'szeregowiec w\u00A0wojsku polskim cudzoziemskiego autoramentu. [przypis edytorski]',
+ 'gemajna (daw., z\u00A0niem. gemein: zwykÅy) '
+ '\u2014 czÄÅciej: gemajn, szeregowiec w\u00A0wojsku polskim cudzoziemskiego autoramentu. [przypis edytorski]
'
),
'Footnote with multiple and qualifiers and emphasis.'),
-
- )
-
- xml_src = ''' %s ''' % "".join(
- t[0] for t in annotations)
- html = WLDocument.from_bytes(
- xml_src.encode('utf-8'),
- parse_dublincore=False).as_html().get_file()
- res_annotations = list(extract_annotations(html))
-
- for i, (src, expected, name) in enumerate(annotations):
- yield _test_annotation, expected, res_annotations[i], name
+ )
+
+ xml_src = ''' %s ''' % "".join(
+ t[0] for t in annotations)
+ html = WLDocument(
+ filename=io.BytesIO(xml_src.encode('utf-8'))
+ ).build(HtmlBuilder, base_url='/').get_file()
+ res_annotations = list(extract_annotations(html))
+
+ for i, (src, expected, name) in enumerate(annotations):
+ with self.subTest(i=i):
+ self._test_annotation(expected, res_annotations[i], name)