Add support for predesigned covers to Marquise. Remove support for changing cover...
[librarian.git] / tests / test_text.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 from __future__ import unicode_literals
7
8 import unittest
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
15
16
17 class TextTests(unittest.TestCase):
18     maxDiff = None
19
20     def test_transform_legacy(self):
21         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
22
23         text = LegacyWLDocument.from_file(
24             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
25         ).as_text().get_bytes().decode('utf-8')
26
27         with open(expected_output_file_path, 'rb') as f:
28             self.assertEqual(text, f.read().decode('utf-8'))
29
30     def test_transform(self):
31         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
32
33         text = WLDocument(
34             filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
35         ).build(builders['txt']).get_bytes().decode('utf-8')
36
37         with open(expected_output_file_path, 'rb') as f:
38             self.assertEqual(text, f.read().decode('utf-8'))
39
40     
41     def test_transform_raw(self):
42         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected_raw.txt')
43
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')
47
48         with open(expected_output_file_path, 'rb') as f:
49             self.assertEqual(text, f.read().decode('utf-8'))
50
51
52 @raises(NoDublinCore)
53 def test_no_dublincore():
54     LegacyWLDocument.from_file(
55             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
56         ).as_text()
57
58
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,
64         ).as_text()