1560
1555
child.map(None, ("baz",), "val")
1561
1556
node.add_node("b", child)
1563
# Note that 'ram' doesn't match anything, so it should be freely
1565
key_filter = (('foo',), ('fob',), ('bar',), ('baz',), ('ram',))
1558
key_filter = (('foo',), ('fob',), ('bar',), ('baz',))
1566
1559
for child, node_key_filter in node._iter_nodes(None,
1567
1560
key_filter=key_filter):
1568
# each child could match two key filters, so make sure they were
1561
# each child could matches two key filters, so make sure they were
1569
1562
# both included.
1570
1563
self.assertEqual(2, len(node_key_filter))
1572
def make_fo_fa_node(self):
1573
node = InternalNode('f')
1575
child.set_maximum_size(100)
1576
child.map(None, ("foo",), "val")
1577
child.map(None, ("fob",), "val")
1578
node.add_node('fo', child)
1580
child.set_maximum_size(100)
1581
child.map(None, ("far",), "val")
1582
child.map(None, ("faz",), "val")
1583
node.add_node("fa", child)
1586
def test__iter_nodes_single_entry(self):
1587
node = self.make_fo_fa_node()
1588
key_filter = [('foo',)]
1589
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1590
self.assertEqual(1, len(nodes))
1591
self.assertEqual(key_filter, nodes[0][1])
1593
def test__iter_nodes_single_entry_misses(self):
1594
node = self.make_fo_fa_node()
1595
key_filter = [('bar',)]
1596
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1597
self.assertEqual(0, len(nodes))
1599
def test__iter_nodes_mixed_key_width(self):
1600
node = self.make_fo_fa_node()
1601
key_filter = [('foo', 'bar'), ('foo',), ('fo',), ('b',)]
1602
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1603
self.assertEqual(1, len(nodes))
1604
matches = key_filter[:]
1605
matches.remove(('b',))
1606
self.assertEqual(sorted(matches), sorted(nodes[0][1]))
1608
def test__iter_nodes_match_all(self):
1609
node = self.make_fo_fa_node()
1610
key_filter = [('foo', 'bar'), ('foo',), ('fo',), ('f',)]
1611
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1612
self.assertEqual(2, len(nodes))
1614
def test__iter_nodes_fixed_widths_and_misses(self):
1615
node = self.make_fo_fa_node()
1616
# foo and faa should both match one child, baz should miss
1617
key_filter = [('foo',), ('faa',), ('baz',)]
1618
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1619
self.assertEqual(2, len(nodes))
1620
for node, matches in nodes:
1621
self.assertEqual(1, len(matches))
1623
1565
def test_iteritems_empty_new(self):
1624
1566
node = InternalNode()
1625
1567
self.assertEqual([], sorted(node.iteritems(None)))