~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_map.py

Fix InternalNode._iter_nodes to split the key filter based on matches.
Update LeafNode.iteritems() to use a dict lookup when the key width is correct.
Shaves a reasonable amount of time off of stuff that wants to look at large
portions of the inventory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
                # Internal nodes must have identical references
124
124
                self.assertEqual(sorted(node_one._items.keys()),
125
125
                                 sorted(node_two._items.keys()))
126
 
                node_one_stack.extend(node_one._iter_nodes(map_one._store))
127
 
                node_two_stack.extend(node_two._iter_nodes(map_two._store))
 
126
                node_one_stack.extend([n for n, _ in
 
127
                                       node_one._iter_nodes(map_one._store)])
 
128
                node_two_stack.extend([n for n, _ in
 
129
                                       node_two._iter_nodes(map_two._store)])
128
130
            else:
129
131
                # Leaf nodes must have identical contents
130
132
                self.assertEqual(node_one._items, node_two._items)
1506
1508
#    def test_add_node_two_oversized_third_kept_minimum_fan(self):
1507
1509
#    def test_add_node_one_oversized_second_splits_errors(self):
1508
1510
 
 
1511
    def test__iter_nodes_no_key_filter(self):
 
1512
        node = InternalNode('')
 
1513
        child = LeafNode()
 
1514
        child.set_maximum_size(100)
 
1515
        child.map(None, ("foo",), "bar")
 
1516
        node.add_node("f", child)
 
1517
        child = LeafNode()
 
1518
        child.set_maximum_size(100)
 
1519
        child.map(None, ("bar",), "baz")
 
1520
        node.add_node("b", child)
 
1521
 
 
1522
        for child, node_key_filter in node._iter_nodes(None, key_filter=None):
 
1523
            self.assertEqual(None, node_key_filter)
 
1524
 
 
1525
    def test__iter_nodes_splits_key_filter(self):
 
1526
        node = InternalNode('')
 
1527
        child = LeafNode()
 
1528
        child.set_maximum_size(100)
 
1529
        child.map(None, ("foo",), "bar")
 
1530
        node.add_node("f", child)
 
1531
        child = LeafNode()
 
1532
        child.set_maximum_size(100)
 
1533
        child.map(None, ("bar",), "baz")
 
1534
        node.add_node("b", child)
 
1535
 
 
1536
        # foo and bar both match exactly one leaf node, but 'cat' should not
 
1537
        # match any, and should not be placed in one.
 
1538
        key_filter = (('foo',), ('bar',), ('cat',))
 
1539
        for child, node_key_filter in node._iter_nodes(None,
 
1540
                                                       key_filter=key_filter):
 
1541
            # each child could only match one key filter, so make sure it was
 
1542
            # properly filtered
 
1543
            self.assertEqual(1, len(node_key_filter))
 
1544
 
 
1545
    def test__iter_nodes_with_multiple_matches(self):
 
1546
        node = InternalNode('')
 
1547
        child = LeafNode()
 
1548
        child.set_maximum_size(100)
 
1549
        child.map(None, ("foo",), "val")
 
1550
        child.map(None, ("fob",), "val")
 
1551
        node.add_node("f", child)
 
1552
        child = LeafNode()
 
1553
        child.set_maximum_size(100)
 
1554
        child.map(None, ("bar",), "val")
 
1555
        child.map(None, ("baz",), "val")
 
1556
        node.add_node("b", child)
 
1557
 
 
1558
        key_filter = (('foo',), ('fob',), ('bar',), ('baz',))
 
1559
        for child, node_key_filter in node._iter_nodes(None,
 
1560
                                                       key_filter=key_filter):
 
1561
            # each child could matches two key filters, so make sure they were
 
1562
            # both included.
 
1563
            self.assertEqual(2, len(node_key_filter))
 
1564
 
1509
1565
    def test_iteritems_empty_new(self):
1510
1566
        node = InternalNode()
1511
1567
        self.assertEqual([], sorted(node.iteritems(None)))