'Test removal of formats from book records'

def test_remove_formats(self):

    (af, ae, at) = (self.assertFalse, self.assertEqual, self.assertTrue)
    cache = self.init_cache()
    formats = {bid: tuple(cache.formats(bid)) for bid in (1, 2, 3)}
    cache.remove_formats({1: {u'NF'}, 2: {u'NF'}, 3: {u'NF'}})
    nformats = {bid: tuple(cache.formats(bid)) for bid in (1, 2, 3)}
    ae(formats, nformats)
    af((cache.format(1, u'FMT1') is None))
    at(cache.has_format(1, u'FMT1'))
    ap = cache.format_abspath(1, u'FMT1')
    at(os.path.exists(ap))
    cache.remove_formats({1: {u'FMT1'}})
    at((cache.format(1, u'FMT1') is None))
    af(bool(cache.format_metadata(1, u'FMT1')))
    af(bool(cache.format_metadata(1, u'FMT1', allow_cache=False)))
    af((u'FMT1' in cache.formats(1)))
    af(cache.has_format(1, u'FMT1'))
    af(os.path.exists(ap))
    at(cache.has_format(1, u'FMT2'))
    ap = cache.format_abspath(1, u'FMT2')
    if (ap and os.path.exists(ap)):
        cache.remove_formats({1: {u'FMT2'}}, db_only=True)
        af(bool(cache.format_metadata(1, u'FMT2')))
        af(cache.has_format(1, u'FMT2'))
        at(os.path.exists(ap))
    db = self.init_old()
    at((db.format(1, u'FMT1', index_is_id=True) is None))
    db.close()
    del db
