From f7548e6c0ce14556cb9b4d7ef97a17b9e5f2ec46 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Wed, 14 Sep 2022 10:26:50 -0700 Subject: [PATCH] add comments to tests, make sure modifying count counts as modifying.. --- ui/medashare/tags.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ui/medashare/tags.py b/ui/medashare/tags.py index d815d0e..7bbdafa 100644 --- a/ui/medashare/tags.py +++ b/ui/medashare/tags.py @@ -26,6 +26,7 @@ class TagCache: @count.setter def count(self, v): self._count = v + self._modified = True self._limit_count() @@ -105,6 +106,7 @@ class _TestTagCache(unittest.TestCase): tc.add(('foo', 'foo')) + # that modified flag is set self.assertTrue(tc.modified) tc.add(('bar', 'bar')) @@ -117,13 +119,17 @@ class _TestTagCache(unittest.TestCase): tc.add(('foo', 'foo')) + # that only the two most recent tags are present self.assertEqual(tc.tags(), [ ('baz', 'baz'), ('foo', 'foo') ]) + # that it can be stored cachefile = self.tempdir / 'somecache' tc.store(cachefile) + # and it clears the modified flag self.assertFalse(tc.modified) + # that it can be loaded ntc = TagCache.load(cachefile) self.assertFalse(ntc.modified) @@ -134,16 +140,29 @@ class _TestTagCache(unittest.TestCase): 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 + # that modified flag is set after count change + self.assertTrue(ntc.modified) + ntc.add(('a', 'a')) ntc.add(('b', 'b')) + # and the count did change self.assertEqual(ntc.tags(), [ ('a', 'a'), ('b', 'b'), ('whee', 'whee') ]) + ntc.store(cachefile) + ntc.add(('whee', 'whee')) + # that reducing the count works ntc.count = 2 + # and immediately gets rid of extra tags self.assertEqual(ntc.tags(), [ ('b', 'b'), ('whee', 'whee') ])