1 # -*- coding: utf-8 -*-
3 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from __future__ import unicode_literals
9 from librarian import NoDublinCore
10 from librarian.builders import builders
11 from librarian.parser import WLDocument as LegacyWLDocument
12 from librarian.document import WLDocument
13 from nose.tools import *
14 from .utils import get_fixture
17 class TextTests(unittest.TestCase):
20 def test_transform_legacy(self):
21 expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
23 text = LegacyWLDocument.from_file(
24 get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
25 ).as_text().get_bytes().decode('utf-8')
27 with open(expected_output_file_path, 'rb') as f:
28 self.assertEqual(text, f.read().decode('utf-8'))
30 def test_transform(self):
31 expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
34 filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
35 ).build(builders['txt']).get_bytes().decode('utf-8')
37 with open(expected_output_file_path, 'rb') as f:
38 self.assertEqual(text, f.read().decode('utf-8'))
41 def test_transform_raw(self):
42 expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected_raw.txt')
44 text = LegacyWLDocument.from_file(
45 get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
46 ).as_text(flags=['raw-text']).get_bytes().decode('utf-8')
48 with open(expected_output_file_path, 'rb') as f:
49 self.assertEqual(text, f.read().decode('utf-8'))
53 def test_no_dublincore():
54 LegacyWLDocument.from_file(
55 get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
59 def test_passing_parse_dublincore_to_transform():
60 """Passing parse_dublincore=False to the constructor omits DublinCore parsing."""
61 LegacyWLDocument.from_file(
62 get_fixture('text', 'asnyk_miedzy_nami_nodc.xml'),
63 parse_dublincore=False,