Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def test_grid_add():
    left = Grid(columns=["id", "a", "b"])
    left.append({"id": Ref("my_id"), "a": 1, "b": 2})
    right = Grid(columns={"id": {}, "a": {}, "b": {}})
    right.append({"id": Ref("my_id"), "a": 3, "c": 4})

    add_grid = left + right
    assert isinstance(add_grid, Grid)
    assert len(add_grid) == 1
Ejemplo n.º 4
0
def test_grid_sub():
    left = Grid(columns=["id", "a", "b"])
    left.append({"id": Ref("my_id"), "a": 1})
    right = Grid(columns={"id": {}, "a": {}, "b": {}})
    right.append({"id": Ref("my_id"), "a": 3, "b": 4})

    diff = right - left
    assert isinstance(diff, Grid)
    assert len(diff) == 1

    diff = left - right
    assert isinstance(diff, Grid)
    assert len(diff) == 1
Ejemplo n.º 5
0
def test_pop_invalid_pos():
    grid = Grid(columns=["id", "a"])
    row = {"id": Ref("myid"), "a": 1, "b": 2}
    grid.append(row)
    old = grid.pop(-1)
    assert grid
    assert not old
Ejemplo n.º 6
0
def test_pop_multiple_pos():
    grid = Grid(columns=["id", "a"])
    row = {"id": Ref("id2"), "a": 1, "b": 2}
    grid.append(row)
    old = grid.pop(0, 1)
    assert not grid
    assert id(old) == id(row)
Ejemplo n.º 7
0
def test_pop_key():
    grid = Grid(columns=["id", "a"])
    row = {"id": Ref("myid"), "a": 1, "b": 2}
    grid.append(row)
    old = grid.pop(Ref("myid"))
    assert not grid
    assert id(old) == id(row)
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
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'))
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
def test_grid_given_column_dict():
    cols = SortableDict([('col1', [('c1m1', None), ('c1m2', None)]),
                         ('col2', [('c2m1', None), ('c2m2', None)])])
    grid = Grid(columns=cols)
    assert list(grid.column.keys()) == ['col1', 'col2']
    for col, meta in cols.items():
        assert list(grid.column[col].items()) == meta
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
def test_grid_getitem():
    grid = Grid()
    grid.column['test'] = {}

    row = {'test': 'This is a test'}
    grid.append(row)
    assert grid[0] is row
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
def test_grid_given_column_list():
    col_list = [('col1', [('c1m1', None), ('c1m2', None)]),
                ('col2', [('c2m1', None), ('c2m2', None)])]
    grid = Grid(columns=col_list)
    assert list(grid.column.keys()) == ['col1', 'col2']
    for col, meta in col_list:
        assert list(grid.column[col].items()) == meta
Ejemplo n.º 19
0
def test_grid_getitem_with_id():
    grid = Grid()
    grid.column['id'] = {}
    grid.column['test'] = {}

    row = {'id': Ref('myid'), 'test': 'This is a test'}
    grid.append(row)
    assert grid[Ref('myid')] is row
Ejemplo n.º 20
0
def test_select_grid():
    grid = Grid(columns=["id", "a", "b"])
    grid.append({"id": Ref("myid1"), "a": 1, "b": 2})
    grid.append({"id": Ref("myid2"), "a": 1, "b": 2})
    assert grid.select("id,a").column == {"id": {}, 'a': {}}
    assert grid.select("id,b").column == {"id": {}, 'b': {}}
    assert grid.select("!a").column == {"id": {}, 'b': {}}
    assert grid.select("!id,!b").column == {'a': {}}
Ejemplo n.º 21
0
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
Ejemplo n.º 22
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
Ejemplo n.º 23
0
def test_pop_multiple_keys():
    grid = Grid(columns=["id", "a"])
    row1 = {"id": Ref("id1"), "a": 1, "b": 2}
    row2 = {"id": Ref("id2"), "a": 1, "b": 2}
    grid.append(row1)
    grid.append(row2)
    old = grid.pop(Ref("id1"), Ref("id2"))
    assert not grid
    assert id(old) == id(row1)
Ejemplo n.º 24
0
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
Ejemplo n.º 25
0
def test_grid_setitem():
    grid = Grid()
    grid.column['test'] = {}

    row_1 = {'test': 'This is a test'}
    row_2 = {'test': 'This is another test'}
    grid.append(row_1)
    grid[0] = row_2
    assert grid[0] is row_2
Ejemplo n.º 26
0
def test_grid_contain():
    grid = Grid(columns=['id', 'site'])
    grid.append({
        'id': Ref('id1'),
    })
    grid.append({'id': Ref('id2')})
    grid.append({'id': Ref('id3')})

    assert Ref('id1') in grid
    assert Ref('id2') in grid
Ejemplo n.º 27
0
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]
Ejemplo n.º 28
0
def test_grid_keys():
    grid = Grid(columns=['id', 'site'])
    grid.append({
        'id': Ref('id1'),
    })
    grid.append({'id': Ref('id2')})
    grid.append({'id': Ref('id3')})

    assert sorted(list(grid.keys())) == sorted(
        [Ref('id1'), Ref('id2'), Ref('id3')])
Ejemplo n.º 29
0
def test_grid_append_nover_list():
    grid = Grid(version=None)
    assert grid.version == Version('3.0')
    grid.column['test'] = {}

    row_1 = {'test': 'This is a test'}
    row_2 = {'test': ['This should fail']}
    grid.append(row_1)
    assert grid.version == Version('3.0')
    grid.append(row_2)
    assert grid.version == Version('3.0')
Ejemplo n.º 30
0
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