78
78
root_key = CHKMap.from_dict(chk_bytes, a_dict,
79
79
maximum_size=maximum_size, key_width=key_width,
80
80
search_key_func=search_key_func)
81
root_key2 = CHKMap._create_via_map(chk_bytes, a_dict,
82
maximum_size=maximum_size, key_width=key_width,
83
search_key_func=search_key_func)
84
self.assertEqual(root_key, root_key2, "CHKMap.from_dict() did not"
85
" match CHKMap._create_via_map")
86
81
chkmap = CHKMap(chk_bytes, root_key, search_key_func=search_key_func)
1565
1560
child.map(None, ("baz",), "val")
1566
1561
node.add_node("b", child)
1568
# Note that 'ram' doesn't match anything, so it should be freely
1570
key_filter = (('foo',), ('fob',), ('bar',), ('baz',), ('ram',))
1563
key_filter = (('foo',), ('fob',), ('bar',), ('baz',))
1571
1564
for child, node_key_filter in node._iter_nodes(None,
1572
1565
key_filter=key_filter):
1573
# each child could match two key filters, so make sure they were
1566
# each child could matches two key filters, so make sure they were
1574
1567
# both included.
1575
1568
self.assertEqual(2, len(node_key_filter))
1577
def make_fo_fa_node(self):
1578
node = InternalNode('f')
1580
child.set_maximum_size(100)
1581
child.map(None, ("foo",), "val")
1582
child.map(None, ("fob",), "val")
1583
node.add_node('fo', child)
1585
child.set_maximum_size(100)
1586
child.map(None, ("far",), "val")
1587
child.map(None, ("faz",), "val")
1588
node.add_node("fa", child)
1591
def test__iter_nodes_single_entry(self):
1592
node = self.make_fo_fa_node()
1593
key_filter = [('foo',)]
1594
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1595
self.assertEqual(1, len(nodes))
1596
self.assertEqual(key_filter, nodes[0][1])
1598
def test__iter_nodes_single_entry_misses(self):
1599
node = self.make_fo_fa_node()
1600
key_filter = [('bar',)]
1601
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1602
self.assertEqual(0, len(nodes))
1604
def test__iter_nodes_mixed_key_width(self):
1605
node = self.make_fo_fa_node()
1606
key_filter = [('foo', 'bar'), ('foo',), ('fo',), ('b',)]
1607
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1608
self.assertEqual(1, len(nodes))
1609
matches = key_filter[:]
1610
matches.remove(('b',))
1611
self.assertEqual(sorted(matches), sorted(nodes[0][1]))
1613
def test__iter_nodes_match_all(self):
1614
node = self.make_fo_fa_node()
1615
key_filter = [('foo', 'bar'), ('foo',), ('fo',), ('f',)]
1616
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1617
self.assertEqual(2, len(nodes))
1619
def test__iter_nodes_fixed_widths_and_misses(self):
1620
node = self.make_fo_fa_node()
1621
# foo and faa should both match one child, baz should miss
1622
key_filter = [('foo',), ('faa',), ('baz',)]
1623
nodes = list(node._iter_nodes(None, key_filter=key_filter))
1624
self.assertEqual(2, len(nodes))
1625
for node, matches in nodes:
1626
self.assertEqual(1, len(matches))
1628
1570
def test_iteritems_empty_new(self):
1629
1571
node = InternalNode()
1630
1572
self.assertEqual([], sorted(node.iteritems(None)))