Python 3.4-3.7 support;
[librarian.git] / tests / test_epub.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 zipfile import ZipFile
9 from lxml import html
10 from nose.tools import *
11 from librarian import DirDocProvider
12 from librarian.parser import WLDocument
13 from tests.utils import get_fixture
14
15
16 def test_transform():
17     epub = WLDocument.from_file(
18             get_fixture('text', 'asnyk_zbior.xml'),
19             provider=DirDocProvider(get_fixture('text', ''))
20         ).as_epub(flags=['without_fonts']).get_file()
21     zipf = ZipFile(epub)
22
23     # Check contributor list.
24     last = zipf.open('OPS/last.html')
25     tree = html.parse(last)
26     editors_attribution = False
27     for par in tree.findall("//p"):
28         if par.text.startswith(u'Opracowanie redakcyjne i przypisy:'):
29             editors_attribution = True
30             assert_equal(
31                 par.text.rstrip(),
32                 u'Opracowanie redakcyjne i przypisy: '
33                 u'Adam Fikcyjny, Aleksandra Sekuła, Olga Sutkowska.')
34     assert_true(editors_attribution)
35
36
37 def test_transform_hyphenate():
38     epub = WLDocument.from_file(
39             get_fixture('text', 'asnyk_zbior.xml'),
40             provider=DirDocProvider(get_fixture('text', ''))
41         ).as_epub(
42             flags=['without_fonts'],
43             hyphenate=True
44         ).get_file()