| @@ -26,6 +26,7 @@ class TagCache: | |||||
| @count.setter | @count.setter | ||||
| def count(self, v): | def count(self, v): | ||||
| self._count = v | self._count = v | ||||
| self._modified = True | |||||
| self._limit_count() | self._limit_count() | ||||
| @@ -105,6 +106,7 @@ class _TestTagCache(unittest.TestCase): | |||||
| tc.add(('foo', 'foo')) | tc.add(('foo', 'foo')) | ||||
| # that modified flag is set | |||||
| self.assertTrue(tc.modified) | self.assertTrue(tc.modified) | ||||
| tc.add(('bar', 'bar')) | tc.add(('bar', 'bar')) | ||||
| @@ -117,13 +119,17 @@ class _TestTagCache(unittest.TestCase): | |||||
| tc.add(('foo', 'foo')) | tc.add(('foo', 'foo')) | ||||
| # that only the two most recent tags are present | |||||
| self.assertEqual(tc.tags(), [ ('baz', 'baz'), ('foo', 'foo') ]) | self.assertEqual(tc.tags(), [ ('baz', 'baz'), ('foo', 'foo') ]) | ||||
| # that it can be stored | |||||
| cachefile = self.tempdir / 'somecache' | cachefile = self.tempdir / 'somecache' | ||||
| tc.store(cachefile) | tc.store(cachefile) | ||||
| # and it clears the modified flag | |||||
| self.assertFalse(tc.modified) | self.assertFalse(tc.modified) | ||||
| # that it can be loaded | |||||
| ntc = TagCache.load(cachefile) | ntc = TagCache.load(cachefile) | ||||
| self.assertFalse(ntc.modified) | self.assertFalse(ntc.modified) | ||||
| @@ -134,16 +140,29 @@ class _TestTagCache(unittest.TestCase): | |||||
| self.assertEqual(ntc.tags(), [ ('foo', 'foo'), ('whee', 'whee') ]) | self.assertEqual(ntc.tags(), [ ('foo', 'foo'), ('whee', 'whee') ]) | ||||
| # that when the modified flag is cleared | |||||
| ntc.store(cachefile) | |||||
| ntc = TagCache.load(cachefile) | |||||
| # that the count can be modified | |||||
| ntc.count = 3 | ntc.count = 3 | ||||
| # that modified flag is set after count change | |||||
| self.assertTrue(ntc.modified) | |||||
| ntc.add(('a', 'a')) | ntc.add(('a', 'a')) | ||||
| ntc.add(('b', 'b')) | ntc.add(('b', 'b')) | ||||
| # and the count did change | |||||
| self.assertEqual(ntc.tags(), [ ('a', 'a'), ('b', 'b'), ('whee', 'whee') ]) | self.assertEqual(ntc.tags(), [ ('a', 'a'), ('b', 'b'), ('whee', 'whee') ]) | ||||
| ntc.store(cachefile) | |||||
| ntc.add(('whee', 'whee')) | ntc.add(('whee', 'whee')) | ||||
| # that reducing the count works | |||||
| ntc.count = 2 | ntc.count = 2 | ||||
| # and immediately gets rid of extra tags | |||||
| self.assertEqual(ntc.tags(), [ ('b', 'b'), ('whee', 'whee') ]) | self.assertEqual(ntc.tags(), [ ('b', 'b'), ('whee', 'whee') ]) | ||||