Fix transform_abstracy + tests.
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 1 Aug 2019 08:49:49 +0000 (10:49 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 1 Aug 2019 08:51:05 +0000 (10:51 +0200)
CHANGELOG.md
librarian/html.py
tests/files/text/abstrakt.xml [new file with mode: 0644]
tests/test_html_transform_abstrakt.py [new file with mode: 0644]
tests/test_picture.py

index c392530..009faf9 100644 (file)
@@ -3,6 +3,13 @@
 This document records all notable changes to Librarian.
 
 
+## 1.7.4 (2019-08-01)
+
+### Fixed
+- `html.tranform_abstract` bytes vs text confusion.
+- Tests.
+
+
 ## 1.7.3 (2019-07-31)
 
 ### Added
index 67f0061..ed7b4d6 100644 (file)
@@ -38,10 +38,10 @@ def html_has_content(text):
 def transform_abstrakt(abstrakt_element):
     style_filename = get_stylesheet('legacy')
     style = etree.parse(style_filename)
-    xml = etree.tostring(abstrakt_element)
-    document = etree.parse(six.BytesIO(xml.replace('abstrakt', 'dlugi_cytat')))  # HACK
+    xml = etree.tostring(abstrakt_element, encoding='unicode')
+    document = etree.parse(six.StringIO(xml.replace('abstrakt', 'dlugi_cytat')))  # HACK
     result = document.xslt(style)
-    html = re.sub('<a name="sec[0-9]*"/>', '', etree.tostring(result))
+    html = re.sub('<a name="sec[0-9]*"/>', '', etree.tostring(result, encoding='unicode'))
     return re.sub('</?blockquote[^>]*>', '', html)
 
 
diff --git a/tests/files/text/abstrakt.xml b/tests/files/text/abstrakt.xml
new file mode 100644 (file)
index 0000000..7a468a1
--- /dev/null
@@ -0,0 +1,6 @@
+<utwor>
+       <opowiadanie>
+               <abstrakt>
+               </abstrakt>
+       </opowiadanie>
+</utwor>
diff --git a/tests/test_html_transform_abstrakt.py b/tests/test_html_transform_abstrakt.py
new file mode 100644 (file)
index 0000000..dbe22c0
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from __future__ import unicode_literals
+
+from librarian.parser import WLDocument
+from librarian.html import transform_abstrakt
+from nose.tools import *
+from .utils import get_fixture
+
+
+def test_fragments():
+    transform_abstrakt(
+        WLDocument.from_file(
+            get_fixture('text', 'abstrakt.xml'),
+            parse_dublincore=False
+        ).edoc.getroot().find('.//abstrakt')
+    )
index f97609b..7d12b1d 100644 (file)
@@ -36,7 +36,7 @@ def test_wlpicture():
 
     assert path.exists(wlp.image_path)
     
-    f = wlp.image_file('r')
+    f = wlp.image_file()
     f.close()