Mercurial > hg-stable
changeset 39587:8f2c0d1b454c
util: update lrucachedict order during get()
get() should have the same semantics as __getitem__ for item
retrieval.
Differential Revision: https://phab.mercurial-scm.org/D4506
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 07 Sep 2018 10:18:20 -0700 |
parents | f296c0b366c8 |
children | b6b9488aae4c |
files | mercurial/util.py tests/test-lrucachedict.py |
diffstat | 2 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Thu Sep 06 18:04:27 2018 -0700 +++ b/mercurial/util.py Fri Sep 07 10:18:20 2018 -0700 @@ -1332,7 +1332,7 @@ def get(self, k, default=None): try: - return self._cache[k].value + return self.__getitem__(k) except KeyError: return default
--- a/tests/test-lrucachedict.py Thu Sep 06 18:04:27 2018 -0700 +++ b/tests/test-lrucachedict.py Fri Sep 07 10:18:20 2018 -0700 @@ -67,6 +67,18 @@ for key in ('a', 'b'): self.assertIn(key, d) + def testget(self): + d = util.lrucachedict(4) + d['a'] = 'va' + d['b'] = 'vb' + d['c'] = 'vc' + + self.assertIsNone(d.get('missing')) + self.assertEqual(list(d), ['c', 'b', 'a']) + + self.assertEqual(d.get('a'), 'va') + self.assertEqual(list(d), ['a', 'c', 'b']) + def testcopypartial(self): d = util.lrucachedict(4) d.insert('a', 'va', cost=4)