1 # -*- coding: utf-8 -*-
2 from librarian import dcparser
4 from nose.tools import *
5 from os.path import splitext
6 from tests.utils import get_all_fixtures
10 def check_dcparser(xml_file, result_file):
11 xml = file(xml_file).read()
12 result = codecs.open(result_file, encoding='utf-8').read()
13 info = dcparser.BookInfo.from_string(xml).to_dict()
14 should_be = eval(result)
16 assert_equals(info[key], should_be[key])
20 for fixture in get_all_fixtures('dcparser', '*.xml'):
21 base_name = splitext(fixture)[0]
22 yield check_dcparser, fixture, base_name + '.out'
25 def check_serialize(xml_file):
26 xml = file(xml_file).read()
27 info = dcparser.BookInfo.from_string(xml)
30 serialized = etree.tostring(info.to_etree(), encoding=unicode).encode('utf-8')
32 info_bis = dcparser.BookInfo.from_string(serialized)
34 # check if they are the same
35 for key in vars(info):
36 assert_equals(getattr(info, key), getattr(info_bis, key))
37 for key in vars(info_bis):
38 assert_equals(getattr(info, key), getattr(info_bis, key))
42 for fixture in get_all_fixtures('dcparser', '*.xml'):
43 yield check_serialize, fixture