2 # -*- coding: utf-8 -*-
7 from utils import get_file_path
8 from librarian import dcparser, html, ParseError
9 from utils import AutoTestMetaclass
11 class TestDCParser(unittest.TestCase):
12 __metaclass__ = AutoTestMetaclass
16 def run_auto_test(self, in_data, out_data):
17 info = dcparser.BookInfo.from_string(in_data).to_dict()
18 should_be = eval(out_data)
20 self.assertEqual( info[key], should_be[key] )
22 class TestDCSerialize(unittest.TestCase):
23 __metaclass__ = AutoTestMetaclass
25 TEST_DIR = 'dcserialize'
27 def run_auto_test(self, in_data, out_data):
29 # first parse the input
30 info = dcparser.BookInfo.from_string(in_data)
33 serialized = lxml.etree.tostring(info.to_etree(), encoding=unicode).encode('utf-8')
36 info_bis = dcparser.BookInfo.from_string(serialized)
38 # check if they are the same
39 for key in vars(info):
40 self.assertEqual( getattr(info, key), getattr(info_bis, key))
42 for key in vars(info_bis):
43 self.assertEqual( getattr(info, key), getattr(info_bis, key))
45 class TestParserErrors(unittest.TestCase):
48 html.transform(get_file_path('erroneous', 'asnyk_miedzy_nami.xml'),
49 get_file_path('erroneous', 'asnyk_miedzy_nami.html'))
53 #self.assertEqual(e.position, (25, 13))
55 if __name__ == '__main__':