예제 #1
0
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'))
예제 #2
0
def test_grid_extend():
    grid = Grid(columns=['id'])
    grid.reindex()
    rows = [{'id': Ref('id1')}, {'id': Ref('id2')}, {'id': Ref('id3')}]
    grid.extend(rows)
    assert len(grid) == 3
    assert Ref('id1') in grid._index
    assert Ref('id2') in grid._index