Mercurial > hg
comparison tests/test-lrucachedict.py @ 39565:2dcc68c7d25b
util: ability to change capacity when copying lrucachedict
This will allow us to easily replace an lrucachedict with one
with a higher or lower capacity as consumers deem necessary.
IMO it is easier to just create a new cache instance than to
muck with the capacity of an existing cache. Mutating an existing
cache's capacity feels more prone to bugs.
Differential Revision: https://phab.mercurial-scm.org/D4500
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 06 Sep 2018 11:40:20 -0700 |
parents | 5d75a3c16193 |
children | bd9d3a89f07b |
comparison
equal
deleted
inserted
replaced
39564:5d75a3c16193 | 39565:2dcc68c7d25b |
---|---|
116 | 116 |
117 self.assertEqual(list(iter(d)), ['d', 'c', 'b', 'a']) | 117 self.assertEqual(list(iter(d)), ['d', 'c', 'b', 'a']) |
118 for key in ('a', 'b', 'c', 'd'): | 118 for key in ('a', 'b', 'c', 'd'): |
119 self.assertEqual(d[key], 'v%s' % key) | 119 self.assertEqual(d[key], 'v%s' % key) |
120 | 120 |
121 def testcopydecreasecapacity(self): | |
122 d = util.lrucachedict(5) | |
123 d['a'] = 'va' | |
124 d['b'] = 'vb' | |
125 d['c'] = 'vc' | |
126 d['d'] = 'vd' | |
127 | |
128 dc = d.copy(2) | |
129 for key in ('a', 'b'): | |
130 self.assertNotIn(key, dc) | |
131 for key in ('c', 'd'): | |
132 self.assertIn(key, dc) | |
133 self.assertEqual(dc[key], 'v%s' % key) | |
134 | |
135 dc['e'] = 've' | |
136 self.assertNotIn('c', dc) | |
137 for key in ('d', 'e'): | |
138 self.assertIn(key, dc) | |
139 self.assertEqual(dc[key], 'v%s' % key) | |
140 | |
141 # Original should remain unchanged. | |
142 for key in ('a', 'b', 'c', 'd'): | |
143 self.assertIn(key, d) | |
144 self.assertEqual(d[key], 'v%s' % key) | |
145 | |
146 def testcopyincreasecapacity(self): | |
147 d = util.lrucachedict(5) | |
148 d['a'] = 'va' | |
149 d['b'] = 'vb' | |
150 d['c'] = 'vc' | |
151 d['d'] = 'vd' | |
152 | |
153 dc = d.copy(6) | |
154 for key in ('a', 'b', 'c', 'd'): | |
155 self.assertIn(key, dc) | |
156 self.assertEqual(dc[key], 'v%s' % key) | |
157 | |
158 dc['e'] = 've' | |
159 dc['f'] = 'vf' | |
160 for key in ('a', 'b', 'c', 'd', 'e', 'f'): | |
161 self.assertIn(key, dc) | |
162 self.assertEqual(dc[key], 'v%s' % key) | |
163 | |
164 dc['g'] = 'vg' | |
165 self.assertNotIn('a', dc) | |
166 for key in ('b', 'c', 'd', 'e', 'f', 'g'): | |
167 self.assertIn(key, dc) | |
168 self.assertEqual(dc[key], 'v%s' % key) | |
169 | |
170 # Original should remain unchanged. | |
171 for key in ('a', 'b', 'c', 'd'): | |
172 self.assertIn(key, d) | |
173 self.assertEqual(d[key], 'v%s' % key) | |
174 | |
121 if __name__ == '__main__': | 175 if __name__ == '__main__': |
122 silenttestrunner.main(__name__) | 176 silenttestrunner.main(__name__) |