/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_fifo_cache.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
 
195
195
    def test_cleanup_funcs(self):
196
196
        log = []
197
 
 
198
197
        def logging_cleanup(key, value):
199
198
            log.append((key, value))
200
199
        c = fifo_cache.FIFOCache(5, 4)
201
200
        c.add(1, 2, cleanup=logging_cleanup)
202
201
        c.add(2, 3, cleanup=logging_cleanup)
203
202
        c.add(3, 4, cleanup=logging_cleanup)
204
 
        c.add(4, 5, cleanup=None)  # no cleanup for 4
205
 
        c[5] = 6  # no cleanup for 5
 
203
        c.add(4, 5, cleanup=None) # no cleanup for 4
 
204
        c[5] = 6 # no cleanup for 5
206
205
        self.assertEqual([], log)
207
206
        # Adding another key should cleanup 1 & 2
208
207
        c.add(6, 7, cleanup=logging_cleanup)
226
225
 
227
226
    def test_cleanup_at_deconstruct(self):
228
227
        log = []
229
 
 
230
228
        def logging_cleanup(key, value):
231
229
            log.append((key, value))
232
230
        c = fifo_cache.FIFOCache()
254
252
        self.assertEqual([(1, '2')], sorted(viewitems(c)))
255
253
        self.assertEqual(['2'], sorted(viewvalues(c)))
256
254
        self.assertEqual({1: '2'}, c)
257
 
        self.assertEqual(1024 * 1024, c.cache_size())
 
255
        self.assertEqual(1024*1024, c.cache_size())
258
256
 
259
257
    def test_missing(self):
260
258
        c = fifo_cache.FIFOSizeCache()
275
273
        c[2] = 'cde'
276
274
        c[3] = 'fghi'
277
275
        self.assertEqual({1: 'ab', 2: 'cde', 3: 'fghi'}, c)
278
 
        c[4] = 'jkl'  # Collapse
 
276
        c[4] = 'jkl' # Collapse
279
277
        self.assertEqual({3: 'fghi', 4: 'jkl'}, c)
280
278
        # Replacing an item will bump it to the end of the queue
281
279
        c[3] = 'mnop'
285
283
 
286
284
    def test_adding_large_key(self):
287
285
        c = fifo_cache.FIFOSizeCache(10, 8)
288
 
        c[1] = 'abcdefgh'  # Adding a large key won't get cached at all
 
286
        c[1] = 'abcdefgh' # Adding a large key won't get cached at all
289
287
        self.assertEqual({}, c)
290
288
        c[1] = 'abcdefg'
291
289
        self.assertEqual({1: 'abcdefg'}, c)