'Test getting and setting of preferences, especially with mutable objects'

def test_preferences(self):

    cache = self.init_cache()
    changes = []
    cache.backend.conn.setupdatehook((lambda typ, dbname, tblname, rowid: changes.append(rowid)))
    prefs = cache.backend.prefs
    prefs[u'test    mutable'] = [1, 2, 3]
    self.assertEqual(len(changes), 1)
    a = prefs[u'test    mutable']
    a.append(4)
    self.assertIn(4, prefs[u'test    mutable'])
    prefs[u'test    mutable'] = a
    self.assertEqual(len(changes), 2)
    prefs.load_from_db()
    self.assertIn(4, prefs[u'test    mutable'])
    prefs[u'test    mutable'] = {k: k for k in range(10)}
    self.assertEqual(len(changes), 3)
    prefs[u'test    mutable'] = {k: k for k in reversed(range(10))}
    self.assertEqual(len(changes), 3, u'The    database    was    written    to    despite    there    being    no    change    in    value')
