Mercurial > public > mercurial-scm > hg
diff tests/test-lrucachedict.py @ 40880:7cda0cacbbf6
util: implement pop() on lrucachedict
This moves __delitem__() to pop() as the requirement is pretty much the same,
and reimplement __delitem__() by using pop().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 04 Nov 2018 16:57:05 +0900 |
parents | 0c638ff69f5c |
children | 2372284d9457 |
line wrap: on
line diff
--- a/tests/test-lrucachedict.py Wed Oct 31 22:29:05 2018 +0900 +++ b/tests/test-lrucachedict.py Sun Nov 04 16:57:05 2018 +0900 @@ -94,6 +94,21 @@ self.assertEqual(d.peek('a'), 'va') self.assertEqual(list(d), ['c', 'b', 'a']) + def testpop(self): + d = util.lrucachedict(4) + d['a'] = 'va' + d['b'] = 'vb' + d['c'] = 'vc' + + with self.assertRaises(KeyError): + d.pop('missing') + self.assertEqual(list(d), ['c', 'b', 'a']) + self.assertIsNone(d.pop('missing', None)) + self.assertEqual(list(d), ['c', 'b', 'a']) + + self.assertEqual(d.pop('b'), 'vb') + self.assertEqual(list(d), ['c', 'a']) + def testcopypartial(self): d = util.lrucachedict(4) d.insert('a', 'va', cost=4)