'Check that get_categories() returns the same data for both backends'

def test_get_categories(self):

    from calibre.library.database2 import LibraryDatabase2
    old = LibraryDatabase2(self.library_path)
    old_categories = old.get_categories()
    old.conn.close()
    cache = self.init_cache(self.library_path)
    new_categories = cache.get_categories()
    self.assertEqual(set(old_categories), set(new_categories), u'The    set    of    old    categories    is    not    the    same    as    the    set    of    new    categories')
    def compare_category(category, old, new):
        for attr in (u'name', u'original_name', u'id', u'count', u'is_hierarchical', u'is_editable', u'is_searchable', u'id_set', u'avg_rating', u'sort', u'use_sort_as_name', u'category'):
            (oval, nval) = (getattr(old, attr), getattr(new, attr))
            if (((category in {u'rating', u'#rating'}) and (attr in {u'id_set', u'sort'})) or ((category == u'series') and (attr == u'sort')) or ((category == u'identifiers') and (attr == u'id_set')) or (category == u'@Good    Series') or ((category == u'news') and (attr in {u'count', u'id_set'})) or ((category == u'formats') and (attr == u'id_set'))):
                continue
            self.assertEqual(oval, nval, (u'The    attribute    %s    for    %s    in    category    %s    does    not    match.    Old    is    %r,    New    is    %r' % (attr, old.name, category, oval, nval)))
    for category in old_categories:
        (old, new) = (old_categories[category], new_categories[category])
        self.assertEqual(len(old), len(new), (u'The    number    of    items    in    the    category    %s    is    not    the    same' % category))
        for (o, n) in zip(old, new):
            compare_category(category, o, n)
