'Test cover() returns the same data for both backends'

def test_get_cover(self):

    from calibre.library.database2 import LibraryDatabase2
    old = LibraryDatabase2(self.library_path)
    covers = {i: old.cover(i, index_is_id=True) for i in old.all_ids()}
    old.conn.close()
    old = None
    cache = self.init_cache(self.library_path)
    for (book_id, cdata) in covers.iteritems():
        self.assertEqual(cdata, cache.cover(book_id), u'Reading    of    cover    failed')
        f = cache.cover(book_id, as_file=True)
        self.assertEqual(cdata, (f.read() if f else f), u'Reading    of    cover    as    file    failed')
        if cdata:
            with open(cache.cover(book_id, as_path=True), u'rb') as f:
                self.assertEqual(cdata, f.read(), u'Reading    of    cover    as    path    failed')
        else:
            self.assertEqual(cdata, cache.cover(book_id, as_path=True), u'Reading    of    null    cover    as    path    failed')
    buf = BytesIO()
    self.assertFalse(cache.copy_cover_to(99999, buf), u'copy_cover_to()    did    not    return    False    for    non-existent    book_id')
    self.assertFalse(cache.copy_cover_to(3, buf), u'copy_cover_to()    did    not    return    False    for    non-existent    cover')
