Mercurial > public > mercurial-scm > hg-stable
diff tests/test-lrucachedict.py @ 40897:0c638ff69f5c
util: add method to peek item in lrucachedict
I want a function that doesn't unnecessarily update the internal state of
the cache dict after fork().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 31 Oct 2018 22:29:05 +0900 |
parents | 8f2c0d1b454c |
children | 7cda0cacbbf6 |
line wrap: on
line diff
--- a/tests/test-lrucachedict.py Wed Oct 31 22:05:45 2018 +0900 +++ b/tests/test-lrucachedict.py Wed Oct 31 22:29:05 2018 +0900 @@ -79,6 +79,21 @@ self.assertEqual(d.get('a'), 'va') self.assertEqual(list(d), ['a', 'c', 'b']) + def testpeek(self): + d = util.lrucachedict(4) + d['a'] = 'va' + d['b'] = 'vb' + d['c'] = 'vc' + + with self.assertRaises(KeyError): + d.peek('missing') + self.assertEqual(list(d), ['c', 'b', 'a']) + self.assertIsNone(d.peek('missing', None)) + self.assertEqual(list(d), ['c', 'b', 'a']) + + self.assertEqual(d.peek('a'), 'va') + self.assertEqual(list(d), ['c', 'b', 'a']) + def testcopypartial(self): d = util.lrucachedict(4) d.insert('a', 'va', cost=4)