1560
1560
child.map(None, ("baz",), "val")
1561
1561
node.add_node("b", child)
1563
key_filter = (('foo',), ('fob',), ('bar',), ('baz',))
1563
# Note that 'ram' doesn't match anything, so it should be freely
1565
key_filter = (('foo',), ('fob',), ('bar',), ('baz',), ('ram',))
1564
1566
for child, node_key_filter in node._iter_nodes(None,
1565
1567
key_filter=key_filter):
1566
# each child could matches two key filters, so make sure they were
1568
# each child could match two key filters, so make sure they were
1567
1569
# both included.
1568
1570
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))
1570
1623
def test_iteritems_empty_new(self):
1571
1624
node = InternalNode()
1572
1625
self.assertEqual([], sorted(node.iteritems(None)))