'Test the setting of the dirtied flag and the last_modified column'

def test_dirtied(self):

    cl = self.cloned_library
    cache = self.init_cache(cl)
    (ae, af, sf) = (self.assertEqual, self.assertFalse, cache.set_field)
    cache.dump_metadata()
    af(cache.dirtied_cache)
    af(self.init_cache(cl).dirtied_cache)
    prev = cache.field_for(u'last_modified', 3)
    import calibre.db.cache as c
    from datetime import timedelta
    utime = (prev + timedelta(days=1))
    onowf = c.nowf
    c.nowf = (lambda : utime)
    try:
        ae(sf(u'title', {3: u'xxx'}), set([3]))
        self.assertTrue((3 in cache.dirtied_cache))
        ae(cache.field_for(u'last_modified', 3), utime)
        cache.dump_metadata()
        raw = cache.read_backup(3)
        from calibre.ebooks.metadata.opf2 import OPF
        opf = OPF(BytesIO(raw))
        ae(opf.title, u'xxx')
    finally:
        c.nowf = onowf
