Add test for serialization of field metadata

This commit is contained in:
Kovid Goyal 2017-05-01 13:45:43 +05:30
parent c5dd2977eb
commit a8b29afc50
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 2 deletions

View File

@ -239,7 +239,12 @@ class ReadingTest(BaseTest):
def test_serialize_metadata(self): # {{{
from calibre.utils.serialize import json_dumps, json_loads, msgpack_dumps, msgpack_loads
from calibre.library.field_metadata import fm_as_dict
cache = self.init_cache(self.library_path)
fm = cache.field_metadata
for d, l in ((json_dumps, json_loads), (msgpack_dumps, msgpack_loads)):
fm2 = l(d(fm))
self.assertEqual(fm_as_dict(fm), fm_as_dict(fm2))
for i in xrange(1, 4):
mi = cache.get_metadata(i, get_cover=True, cover_as_data=True)
rmi = msgpack_loads(msgpack_dumps(mi))

View File

@ -433,10 +433,10 @@ class FieldMetadata(object):
def __eq__(self, other):
if not isinstance(other, FieldMetadata):
return False
for attr in ('_tb_cats', '_tb_custom_fields', '_search_term_map', 'custom_label_to_key_map', 'custom_field_prefix'):
for attr in ('_tb_custom_fields', '_search_term_map', 'custom_label_to_key_map', 'custom_field_prefix'):
if getattr(self, attr) != getattr(other, attr):
return False
return True
return dict(self._tb_cats) == dict(other._tb_cats)
def __ne__(self, other):
return not self.__eq__(other)