def test_grid_index(): grid = Grid() grid.column['id'] = {} grid.column['val'] = {} grid.insert(0, {'id': Ref('idx1')}) assert Ref('idx1') in grid._index assert grid[Ref('idx1')] assert grid.get(Ref('idx1')) grid.insert(1, {'id': Ref('idx2')}) assert Ref('idx1') in grid._index assert Ref('idx2') in grid._index assert grid.get(Ref('idx2')) grid[0] = {'id': Ref('idx3')} assert Ref('idx1') not in grid._index assert Ref('idx3') in grid._index assert grid.get(Ref('idx3')) del grid[1] assert Ref('idx2') not in grid._index grid.extend([ { 'id': Ref('idx5') }, { 'id': Ref('idx6') }, ]) assert Ref('idx5') in grid._index assert Ref('idx6') in grid._index grid[0]['id'] = Ref('idx4') grid.reindex() assert Ref('idx4') in grid._index assert grid.get(Ref('idx4'))
def test_grid_insert(): grid = Grid() rows = [{'test': 1}, {'test': 2}, {'test': 3}] grid.column['test'] = {} grid.extend(rows) assert len(grid) == 3 new_row = {'test': 'new'} grid.insert(1, new_row) assert len(grid) == 4 assert grid[0] is rows[0] assert grid[1] is new_row assert grid[2] is rows[1] assert grid[3] is rows[2]