'Test read-only methods that are directly equivalent in the old and new interface'

def test_legacy_direct(self):

    from calibre.ebooks.metadata.book.base import Metadata
    from datetime import timedelta
    ndb = self.init_legacy(self.cloned_library)
    db = self.init_old()
    newstag = ndb.new_api.get_item_id(u'tags', u'news')
    self.assertEqual(dict(db.prefs), dict(ndb.prefs))
    for (meth, args) in {u'find_identical_books': [(Metadata(u'title    one', [u'author    one']),), (Metadata(u'unknown'),), (Metadata(u'xxxx'),)], u'get_books_for_category': [(u'tags', newstag), (u'#formats', u'FMT1')], u'get_next_series_num_for': [(u'A    Series    One',)], u'get_id_from_uuid': [(u'ddddd',), (db.uuid(1, True),)], u'cover': [(0,), (1,), (2,)], u'get_author_id': [(u'author    one',), (u'unknown',), (u'xxxxx',)], u'series_id': [(0,), (1,), (2,)], u'publisher_id': [(0,), (1,), (2,)], u'@tags_older_than': [(u'News', None), (u'Tag    One', None), (u'xxxx', None), (u'Tag    One', None, u'News'), (u'News', None, u'xxxx'), (u'News', None, None, [u'xxxxxxx']), (u'News', None, u'Tag    One', [u'Author    Two', u'Author    One']), (u'News', timedelta(0), None, None), (u'News', timedelta(100000))], u'format': [(1, u'FMT1', True), (2, u'FMT1', True), (0, u'xxxxxx')], u'has_format': [(1, u'FMT1', True), (2, u'FMT1', True), (0, u'xxxxxx')], u'sizeof_format': [(1, u'FMT1', True), (2, u'FMT1', True), (0, u'xxxxxx')], u'@format_files': [(0,), (1,), (2,)], u'formats': [(0,), (1,), (2,)], u'max_size': [(0,), (1,), (2,)], u'format_hash': [(1, u'FMT1'), (1, u'FMT2'), (2, u'FMT1')], u'author_sort_from_authors': [([u'Author    One', u'Author    Two', u'Unknown'],)], u'has_book': [(Metadata(u'title    one'),), (Metadata(u'xxxx1111'),)], u'has_id': [(1,), (2,), (3,), (9999,)], u'id': [(1,), (2,), (0,)], u'index': [(1,), (2,), (3,)], u'row': [(1,), (2,), (3,)], u'is_empty': [()], u'count': [()], u'all_author_names': [()], u'all_tag_names': [()], u'all_series_names': [()], u'all_publisher_names': [()], u'!all_authors': [()], u'!all_tags2': [()], u'@all_tags': [()], u'@get_all_identifier_types': [()], u'!all_publishers': [()], u'!all_titles': [()], u'!all_series': [()], u'standard_field_keys': [()], u'all_field_keys': [()], u'searchable_fields': [()], u'search_term_to_field_key': [(u'author',), (u'tag',)], u'metadata_for_field': [(u'title',), (u'tags',)], u'sortable_field_keys': [()], u'custom_field_keys': [(True,), (False,)], u'!get_usage_count_by_id': [(u'authors',), (u'tags',), (u'series',), (u'publisher',), (u'#tags',), (u'languages',)], u'get_field': [(1, u'title'), (2, u'tags'), (0, u'rating'), (1, u'authors'), (2, u'series'), (1, u'#tags')], u'all_formats': [()], u'get_authors_with_ids': [()], u'!get_tags_with_ids': [()], u'!get_series_with_ids': [()], u'!get_publishers_with_ids': [()], u'!get_ratings_with_ids': [()], u'!get_languages_with_ids': [()], u'tag_name': [(3,)], u'author_name': [(3,)], u'series_name': [(3,)], u'authors_sort_strings': [(0,), (1,), (2,)], u'author_sort_from_book': [(0,), (1,), (2,)], u'authors_with_sort_strings': [(0,), (1,), (2,)], u'book_on_device_string': [(1,), (2,), (3,)], u'books_in_series_of': [(0,), (1,), (2,)], u'books_with_same_title': [(Metadata(db.title(0)),), (Metadata(db.title(1)),), (Metadata(u'1234'),)]}.iteritems():
        fmt = (lambda x: x)
        if (meth[0] in {u'!', u'@'}):
            fmt = {u'!': dict, u'@': frozenset}[meth[0]]
            meth = meth[1:]
        elif (meth == u'get_authors_with_ids'):
            fmt = (lambda val: {x[0]: tuple(x[1:]) for x in val})
        for a in args:
            self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)), (u'The    method:    %s()    returned    different    results    for    argument    %s' % (meth, a)))
    def f(x, y):
        x.discard(u'metadata_db_prefs_backup.json')
        return (x, y)
    self.assertEqual(f(*db.get_top_level_move_items()), f(*ndb.get_top_level_move_items()))
    (d1, d2) = (BytesIO(), BytesIO())
    db.copy_cover_to(1, d1, True)
    ndb.copy_cover_to(1, d2, True)
    self.assertTrue((d1.getvalue() == d2.getvalue()))
    (d1, d2) = (BytesIO(), BytesIO())
    db.copy_format_to(1, u'FMT1', d1, True)
    ndb.copy_format_to(1, u'FMT1', d2, True)
    self.assertTrue((d1.getvalue() == d2.getvalue()))
    old = db.get_data_as_dict(prefix=u'test-prefix')
    new = ndb.get_data_as_dict(prefix=u'test-prefix')
    for (o, n) in zip(old, new):
        o = {(type(u'')(k) if isinstance(k, bytes) else k): (set(v) if isinstance(v, list) else v) for (k, v) in o.iteritems()}
        n = {k: (set(v) if isinstance(v, list) else v) for (k, v) in n.iteritems()}
        self.assertEqual(o, n)
    ndb.search(u'title:Unknown')
    db.search(u'title:Unknown')
    self.assertEqual(db.row(3), ndb.row(3))
    self.assertRaises(ValueError, ndb.row, 2)
    self.assertRaises(ValueError, db.row, 2)
    db.close()
