'Test moving of library'

def test_library_move(self):

    from calibre.ptempfile import TemporaryDirectory
    cache = self.init_cache()
    self.assertIn(u'metadata.db', cache.get_top_level_move_items()[0])
    all_ids = cache.all_book_ids()
    fmt1 = cache.format(1, u'FMT1')
    cov = cache.cover(1)
    odir = cache.backend.library_path
    with TemporaryDirectory(u'moved_lib') as tdir:
        cache.move_library_to(tdir)
        self.assertIn(u'moved_lib', cache.backend.library_path)
        self.assertIn(u'moved_lib', cache.backend.dbpath)
        self.assertEqual(fmt1, cache.format(1, u'FMT1'))
        self.assertEqual(cov, cache.cover(1))
        cache.reload_from_db()
        self.assertEqual(all_ids, cache.all_book_ids())
        cache.backend.close()
        self.assertFalse(os.path.exists(odir))
        os.mkdir(odir)
