355
355
self.assertEqual(1, len(builder._nodes))
356
356
self.assertEqual(1, len(builder._keys))
357
self.assertEqual({}, builder._nodes_by_key)
357
self.assertIs(None, builder._nodes_by_key)
358
358
builder.add_node(*nodes[1])
359
359
self.assertEqual(0, len(builder._nodes))
360
360
self.assertEqual(0, len(builder._keys))
361
self.assertEqual({}, builder._nodes_by_key)
361
self.assertIs(None, builder._nodes_by_key)
362
362
self.assertEqual(1, len(builder._backing_indices))
363
363
self.assertEqual(2, builder._backing_indices[0].key_count())
364
364
# now back to memory
365
365
builder.add_node(*nodes[2])
366
366
self.assertEqual(1, len(builder._nodes))
367
367
self.assertEqual(1, len(builder._keys))
368
self.assertEqual({}, builder._nodes_by_key)
368
self.assertIs(None, builder._nodes_by_key)
369
369
# And spills to a second backing index combing all
370
370
builder.add_node(*nodes[3])
371
371
self.assertEqual(0, len(builder._nodes))
372
372
self.assertEqual(0, len(builder._keys))
373
self.assertEqual({}, builder._nodes_by_key)
373
self.assertIs(None, builder._nodes_by_key)
374
374
self.assertEqual(2, len(builder._backing_indices))
375
375
self.assertEqual(None, builder._backing_indices[0])
376
376
self.assertEqual(4, builder._backing_indices[1].key_count())
379
379
builder.add_node(*nodes[5])
380
380
self.assertEqual(0, len(builder._nodes))
381
381
self.assertEqual(0, len(builder._keys))
382
self.assertEqual({}, builder._nodes_by_key)
382
self.assertIs(None, builder._nodes_by_key)
383
383
self.assertEqual(2, len(builder._backing_indices))
384
384
self.assertEqual(2, builder._backing_indices[0].key_count())
385
385
self.assertEqual(4, builder._backing_indices[1].key_count())
443
443
# Test the parts of the index that take up memory are doing so
445
445
self.assertEqual(1, len(builder._keys))
446
self.assertEqual(2, len(builder._nodes))
447
self.assertNotEqual({}, builder._nodes_by_key)
446
self.assertEqual(1, len(builder._nodes))
447
self.assertIs(None, builder._nodes_by_key)
448
448
builder.add_node(*nodes[1])
449
449
self.assertEqual(0, len(builder._keys))
450
450
self.assertEqual(0, len(builder._nodes))
451
self.assertEqual({}, builder._nodes_by_key)
451
self.assertIs(None, builder._nodes_by_key)
452
452
self.assertEqual(1, len(builder._backing_indices))
453
453
self.assertEqual(2, builder._backing_indices[0].key_count())
454
454
# now back to memory
455
old = dict(builder._get_nodes_by_key()) #Build up the nodes by key dict
455
456
builder.add_node(*nodes[2])
456
self.assertEqual(2, len(builder._nodes))
457
self.assertEqual(1, len(builder._nodes))
457
458
self.assertEqual(1, len(builder._keys))
459
self.assertIsNot(None, builder._nodes_by_key)
458
460
self.assertNotEqual({}, builder._nodes_by_key)
461
# We should have a new entry
462
self.assertNotEqual(old, builder._nodes_by_key)
459
463
# And spills to a second backing index combing all
460
464
builder.add_node(*nodes[3])
461
465
self.assertEqual(0, len(builder._nodes))
462
466
self.assertEqual(0, len(builder._keys))
463
self.assertEqual({}, builder._nodes_by_key)
467
self.assertIs(None, builder._nodes_by_key)
464
468
self.assertEqual(2, len(builder._backing_indices))
465
469
self.assertEqual(None, builder._backing_indices[0])
466
470
self.assertEqual(4, builder._backing_indices[1].key_count())
469
473
builder.add_node(*nodes[5])
470
474
self.assertEqual(0, len(builder._nodes))
471
475
self.assertEqual(0, len(builder._keys))
472
self.assertEqual({}, builder._nodes_by_key)
476
self.assertIs(None, builder._nodes_by_key)
473
477
self.assertEqual(2, len(builder._backing_indices))
474
478
self.assertEqual(2, builder._backing_indices[0].key_count())
475
479
self.assertEqual(4, builder._backing_indices[1].key_count())