1 # -*- coding: utf-8 -*-
3 # Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska
5 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
6 # For full license text see COPYING or <http://www.gnu.org/licenses/agpl.html>
9 from librarian import dcparser
10 from lxml import etree
11 from nose.tools import *
12 from os.path import splitext
13 from tests.utils import get_all_fixtures
17 def check_dcparser(xml_file, result_file):
18 xml = file(xml_file).read()
19 result = codecs.open(result_file, encoding='utf-8').read()
20 info = dcparser.BookInfo.from_string(xml).to_dict()
21 should_be = eval(result)
23 assert_equals(info[key], should_be[key])
27 for fixture in get_all_fixtures('dcparser', '*.xml'):
28 base_name = splitext(fixture)[0]
29 yield check_dcparser, fixture, base_name + '.out'
32 def check_serialize(xml_file):
33 xml = file(xml_file).read()
34 info = dcparser.BookInfo.from_string(xml)
37 serialized = etree.tostring(info.to_etree(), encoding=unicode).encode('utf-8')
39 info_bis = dcparser.BookInfo.from_string(serialized)
41 # check if they are the same
42 for key in vars(info):
43 assert_equals(getattr(info, key), getattr(info_bis, key))
44 for key in vars(info_bis):
45 assert_equals(getattr(info, key), getattr(info_bis, key))
49 for fixture in get_all_fixtures('dcparser', '*.xml'):
50 yield check_serialize, fixture