Images: image@src is a URL, and image sizes are limited.
[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 from librarian import NoDublinCore
9 from librarian.builders import builders
10 from librarian.parser import WLDocument as LegacyWLDocument
11 from librarian.document import WLDocument
12 from nose.tools import *
13 from .utils import get_fixture
14
15
16 def test_transform_legacy():
17     expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
18
19     text = LegacyWLDocument.from_file(
20             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
21         ).as_text().get_bytes()
22
23     assert_equal(text, open(expected_output_file_path, 'rb').read())
24
25
26 def test_transform():
27     expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
28
29     text = WLDocument(
30         filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
31     ).build(builders['txt']).get_bytes()
32
33     assert_equal(text, open(expected_output_file_path, 'rb').read())
34
35     
36 def test_transform_raw():
37     expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected_raw.txt')
38
39     text = LegacyWLDocument.from_file(
40             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
41         ).as_text(flags=['raw-text']).get_bytes()
42
43     assert_equal(text, open(expected_output_file_path, 'rb').read())
44
45
46 @raises(NoDublinCore)
47 def test_no_dublincore():
48     LegacyWLDocument.from_file(
49             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
50         ).as_text()
51
52
53 def test_passing_parse_dublincore_to_transform():
54     """Passing parse_dublincore=False to the constructor omits DublinCore parsing."""
55     LegacyWLDocument.from_file(
56             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml'),
57             parse_dublincore=False,
58         ).as_text()