~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-11-17 03:20:35 UTC
  • mfrom: (4792.4.3 456036)
  • Revision ID: pqm@pqm.ubuntu.com-20091117032035-s3sgtlixj1lrminn
(Gordon Tyler) Fix IndexError during 'bzr ignore /' (#456036)

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        condition_isinstance(TestBTreeNodes))
44
44
    import bzrlib._btree_serializer_py as py_module
45
45
    scenarios = [('python', {'parse_btree': py_module})]
46
 
    if compiled_btreeparser_feature.available():
47
 
        scenarios.append(('C', {'parse_btree':
48
 
                                compiled_btreeparser_feature.module}))
 
46
    if CompiledBtreeParserFeature.available():
 
47
        # Is there a way to do this that gets missing feature failures rather
 
48
        # than no indication to the user?
 
49
        import bzrlib._btree_serializer_pyx as c_module
 
50
        scenarios.append(('C', {'parse_btree': c_module}))
49
51
    return multiply_tests(node_tests, scenarios, others)
50
52
 
51
53
 
52
 
compiled_btreeparser_feature = tests.ModuleAvailableFeature(
53
 
                                'bzrlib._btree_serializer_pyx')
 
54
class _CompiledBtreeParserFeature(tests.Feature):
 
55
    def _probe(self):
 
56
        try:
 
57
            import bzrlib._btree_serializer_pyx
 
58
        except ImportError:
 
59
            return False
 
60
        return True
 
61
 
 
62
    def feature_name(self):
 
63
        return 'bzrlib._btree_serializer_pyx'
 
64
 
 
65
CompiledBtreeParserFeature = _CompiledBtreeParserFeature()
54
66
 
55
67
 
56
68
class BTreeTestCase(TestCaseWithTransport):
347
359
        # Test the parts of the index that take up memory are doing so
348
360
        # predictably.
349
361
        self.assertEqual(1, len(builder._nodes))
 
362
        self.assertEqual(1, len(builder._keys))
350
363
        self.assertIs(None, builder._nodes_by_key)
351
364
        builder.add_node(*nodes[1])
352
365
        self.assertEqual(0, len(builder._nodes))
 
366
        self.assertEqual(0, len(builder._keys))
353
367
        self.assertIs(None, builder._nodes_by_key)
354
368
        self.assertEqual(1, len(builder._backing_indices))
355
369
        self.assertEqual(2, builder._backing_indices[0].key_count())
356
370
        # now back to memory
357
371
        builder.add_node(*nodes[2])
358
372
        self.assertEqual(1, len(builder._nodes))
 
373
        self.assertEqual(1, len(builder._keys))
359
374
        self.assertIs(None, builder._nodes_by_key)
360
375
        # And spills to a second backing index combing all
361
376
        builder.add_node(*nodes[3])
362
377
        self.assertEqual(0, len(builder._nodes))
 
378
        self.assertEqual(0, len(builder._keys))
363
379
        self.assertIs(None, builder._nodes_by_key)
364
380
        self.assertEqual(2, len(builder._backing_indices))
365
381
        self.assertEqual(None, builder._backing_indices[0])
368
384
        builder.add_node(*nodes[4])
369
385
        builder.add_node(*nodes[5])
370
386
        self.assertEqual(0, len(builder._nodes))
 
387
        self.assertEqual(0, len(builder._keys))
371
388
        self.assertIs(None, builder._nodes_by_key)
372
389
        self.assertEqual(2, len(builder._backing_indices))
373
390
        self.assertEqual(2, builder._backing_indices[0].key_count())
431
448
        # Test the parts of the index that take up memory are doing so
432
449
        # predictably.
433
450
        self.assertEqual(1, len(builder._nodes))
 
451
        self.assertEqual(1, len(builder._keys))
434
452
        self.assertIs(None, builder._nodes_by_key)
435
453
        builder.add_node(*nodes[1])
436
454
        self.assertEqual(0, len(builder._nodes))
 
455
        self.assertEqual(0, len(builder._keys))
437
456
        self.assertIs(None, builder._nodes_by_key)
438
457
        self.assertEqual(1, len(builder._backing_indices))
439
458
        self.assertEqual(2, builder._backing_indices[0].key_count())
440
459
        # now back to memory
441
460
        builder.add_node(*nodes[2])
442
461
        self.assertEqual(1, len(builder._nodes))
 
462
        self.assertEqual(1, len(builder._keys))
443
463
        self.assertIs(None, builder._nodes_by_key)
444
464
        # And spills to a second backing index but doesn't combine
445
465
        builder.add_node(*nodes[3])
446
466
        self.assertEqual(0, len(builder._nodes))
 
467
        self.assertEqual(0, len(builder._keys))
447
468
        self.assertIs(None, builder._nodes_by_key)
448
469
        self.assertEqual(2, len(builder._backing_indices))
449
470
        for backing_index in builder._backing_indices:
452
473
        builder.add_node(*nodes[4])
453
474
        builder.add_node(*nodes[5])
454
475
        self.assertEqual(0, len(builder._nodes))
 
476
        self.assertEqual(0, len(builder._keys))
455
477
        self.assertIs(None, builder._nodes_by_key)
456
478
        self.assertEqual(3, len(builder._backing_indices))
457
479
        for backing_index in builder._backing_indices:
516
538
        builder.add_node(*nodes[0])
517
539
        # Test the parts of the index that take up memory are doing so
518
540
        # predictably.
 
541
        self.assertEqual(1, len(builder._keys))
519
542
        self.assertEqual(1, len(builder._nodes))
520
543
        self.assertIs(None, builder._nodes_by_key)
521
544
        builder.add_node(*nodes[1])
 
545
        self.assertEqual(0, len(builder._keys))
522
546
        self.assertEqual(0, len(builder._nodes))
523
547
        self.assertIs(None, builder._nodes_by_key)
524
548
        self.assertEqual(1, len(builder._backing_indices))
527
551
        old = dict(builder._get_nodes_by_key()) #Build up the nodes by key dict
528
552
        builder.add_node(*nodes[2])
529
553
        self.assertEqual(1, len(builder._nodes))
 
554
        self.assertEqual(1, len(builder._keys))
530
555
        self.assertIsNot(None, builder._nodes_by_key)
531
556
        self.assertNotEqual({}, builder._nodes_by_key)
532
557
        # We should have a new entry
534
559
        # And spills to a second backing index combing all
535
560
        builder.add_node(*nodes[3])
536
561
        self.assertEqual(0, len(builder._nodes))
 
562
        self.assertEqual(0, len(builder._keys))
537
563
        self.assertIs(None, builder._nodes_by_key)
538
564
        self.assertEqual(2, len(builder._backing_indices))
539
565
        self.assertEqual(None, builder._backing_indices[0])
542
568
        builder.add_node(*nodes[4])
543
569
        builder.add_node(*nodes[5])
544
570
        self.assertEqual(0, len(builder._nodes))
 
571
        self.assertEqual(0, len(builder._keys))
545
572
        self.assertIs(None, builder._nodes_by_key)
546
573
        self.assertEqual(2, len(builder._backing_indices))
547
574
        self.assertEqual(2, builder._backing_indices[0].key_count())
1281
1308
    def test_exists(self):
1282
1309
        # This is just to let the user know if they don't have the feature
1283
1310
        # available
1284
 
        self.requireFeature(compiled_btreeparser_feature)
 
1311
        self.requireFeature(CompiledBtreeParserFeature)
1285
1312
 
1286
1313
 
1287
1314
class TestMultiBisectRight(tests.TestCase):