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