def test_grid_not_equal__with_new_col(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff = copy.deepcopy(ref) diff.column["added"] = {} assert ref != diff
def test_grid_not_equal_with_updated_value(): ref = Grid() ref.column['test'] = {"a": 1} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff = copy.deepcopy(ref) diff.column['test'] = {"a": ""} assert ref != diff
def test_grid_not_equal_col_with_new_metadata(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff: Grid = copy.deepcopy(ref) diff.column.add_item(key='test', value='add') # type: ignore assert ref != diff
def test_grid_new_row(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff = copy.deepcopy(ref) diff.append({'test': 4}) assert ref != diff
def test_grid_equal_with_complex_datas(): ref = Grid() ref.column['test'] = {} ref.extend([ { 'test': datetime.datetime(2010, 11, 28, 7, 23, 2, 600000) }, { 'test': Quantity(500, 'kg') }, { 'test': Coordinate(100, 100) }, { 'test': 1.0 }, ]) similar = Grid() similar.column['test'] = {} similar.extend([ { 'test': datetime.datetime(2010, 11, 28, 7, 23, 2, 500000) }, { 'test': Quantity(500.000001, 'kg') }, { 'test': Coordinate(100.000001, 100.000001) }, { 'test': 1.000001 }, ]) assert ref == similar
def test_grid_equal_with_none(): ref = Grid() ref.column['test', 'none'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) other = copy.deepcopy(ref) other[0]['none'] = None assert ref == other
def test_grid_not_equal_row(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff = copy.deepcopy(ref) diff[0] = {'test': 4} assert ref != diff
def test_grid_not_equal_col_with_updated_metadata(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff = copy.deepcopy(ref) diff.column['test']['test'] = None assert ref != diff
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_not_equal_col_with_change_col_name(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff: Grid = copy.deepcopy(ref) diff.column.pop('test') diff.column.add_item(key='new', value='add') # type: ignore assert ref != diff
def test_grid_equal_with_other_order(): left = Grid() left.column['test'] = {} left.extend([{'test': 1}, {'test': 2}, {'test': 3}]) right = Grid() right.column['test'] = {} right.extend([{'test': 2}, {'test': 1}, {'test': 3}]) assert left == copy.deepcopy(right)
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
def test_grid_copy(): grid = Grid(columns=['test']) rows = [{'test': 1}, {'test': 2}, {'test': 3}] grid.extend(rows) grid_2 = grid.copy() assert len(grid_2) == 3 del grid[1] assert len(grid) == 2 assert len(grid_2) == 3
def test_grid_del(): grid = Grid(columns=['id', 'test']) rows = [{'test': 1}, {'test': 2}, {'test': 3}, {'id': Ref('myid')}] grid.extend(rows) assert len(grid) == 4 del grid[1] del grid[Ref('myid')] assert len(grid) == 2 assert grid[0] is rows[0] assert grid[1] is rows[2]
def test_grid_not_equal_metadata(): ref = Grid(metadata={"x": {}}) ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) diff = copy.deepcopy(ref) diff.metadata.append('add') assert ref != diff diff = copy.deepcopy(ref) diff.metadata["x"] = 1 assert ref != diff
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]
def test_grid_str(): grid = Grid(version=VER_3_0) rows = [{'test': 1}, {'test': 2}, {'test': 3}] grid.column['test'] = {} grid.extend(rows) assert repr(grid) == 'Grid\n' + \ '\tVersion: 3.0\n' + \ '\tColumns:\n' + \ '\t\ttest\n' + \ '\t---- Row 0:\n' + \ '\ttest=1\n' + \ '\t---- Row 1:\n' + \ '\ttest=2\n' + \ '\t---- Row 2:\n' + \ '\ttest=3\n'
def test_grid_equal(): ref = Grid() ref.column['test'] = {} ref.extend([{'test': 1}, {'test': 2}, {'test': 3}]) assert ref == copy.deepcopy(ref)