1 # -*- coding: utf-8 -*-
3 # This file is part of Librarian.
5 # Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org.pl>
7 # For full list of contributors see AUTHORS file.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU Affero General Public License for more details.
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from librarian import dcparser
24 from lxml import etree
25 from nose.tools import *
26 from os.path import splitext
27 from tests.utils import get_all_fixtures
31 def check_dcparser(xml_file, result_file):
32 xml = file(xml_file).read()
33 result = codecs.open(result_file, encoding='utf-8').read()
34 info = dcparser.BookInfo.from_string(xml).to_dict()
35 should_be = eval(result)
37 assert_equals(info[key], should_be[key])
41 for fixture in get_all_fixtures('dcparser', '*.xml'):
42 base_name = splitext(fixture)[0]
43 yield check_dcparser, fixture, base_name + '.out'
46 def check_serialize(xml_file):
47 xml = file(xml_file).read()
48 info = dcparser.BookInfo.from_string(xml)
51 serialized = etree.tostring(info.to_etree(), encoding=unicode).encode('utf-8')
53 info_bis = dcparser.BookInfo.from_string(serialized)
55 # check if they are the same
56 for key in vars(info):
57 assert_equals(getattr(info, key), getattr(info_bis, key))
58 for key in vars(info_bis):
59 assert_equals(getattr(info, key), getattr(info_bis, key))
63 for fixture in get_all_fixtures('dcparser', '*.xml'):
64 yield check_serialize, fixture