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
--- 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)