class TestDataArray(object): """Unit tests for DataArray""" def setup_method(self, method): """Creates empty DataArray""" self.data_array = DataArray((100, 100, 100)) def test_iter(self): """Unit test for __iter__""" assert list(iter(self.data_array)) == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(list(iter(self.data_array))) == [(1, 2, 3), (1, 2, 4)] def test_keys(self): """Unit test for keys""" assert self.data_array.keys() == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(self.data_array.keys()) == [(1, 2, 3), (1, 2, 4)] @undotest_model def test_pop(self): """Unit test for pop""" self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert "12" == self.data_array.pop((1, 2, 3)) assert sorted(self.data_array.keys()) == [(1, 2, 4)] def test_get_shape(self): """Unit test for _get_shape""" assert self.data_array.shape == (100, 100, 100) @undotest_model def test_set_shape(self): """Unit test for _set_shape""" self.data_array.shape = (10000, 100, 100) assert self.data_array.shape == (10000, 100, 100) param_get_last_filled_cell = [ {'content': {(0, 0, 0): "2"}, 'table': 0, 'res': (0, 0)}, {'content': {(2, 0, 2): "2"}, 'table': 0, 'res': (0, 0)}, {'content': {(2, 0, 2): "2"}, 'table': None, 'res': (2, 0)}, {'content': {(2, 0, 2): "2"}, 'table': 2, 'res': (2, 0)}, {'content': {(32, 30, 0): "432"}, 'table': 0, 'res': (32, 30)}, ] @params(param_get_last_filled_cell) def test_get_last_filled_cell(self, content, table, res): """Unit test for get_last_filled_cellet_end""" for key in content: self.data_array[key] = content[key] assert self.data_array.get_last_filled_cell(table)[:2] == res def test_getstate(self): """Unit test for __getstate__ (pickle support)""" assert "dict_grid" in self.data_array.__getstate__() def test_slicing(self): """Unit test for __getitem__ and __setitem__""" self.data_array[0, 0, 0] = "'Test'" self.data_array[0, 0, 0] = "'Tes'" assert self.data_array[0, 0, 0] == "'Tes'" def test_cell_array_generator(self): """Unit test for cell_array_generator""" cell_array = self.data_array[:5, 0, 0] assert list(cell_array) == [None] * 5 cell_array = self.data_array[:5, :5, 0] assert [list(c) for c in cell_array] == [[None] * 5] * 5 cell_array = self.data_array[:5, :5, :5] assert [[list(e) for e in c] for c in cell_array] == \ [[[None] * 5] * 5] * 5 def test_set_cell_attributes(self): """Unit test for _set_cell_attributes""" cell_attributes = ["Test"] self.data_array._set_cell_attributes(cell_attributes) assert self.data_array.cell_attributes == cell_attributes param_get_adjusted_merge_area = [ {'attrs': {}, 'insertion_point': 0, 'no_to_insert': 1, 'axis': 0, 'res': None, }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 5, 'no_to_insert': 1, 'axis': 0, 'res': (2, 2, 3, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': 1, 'axis': 0, 'res': (3, 2, 4, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': 10, 'axis': 0, 'res': (12, 2, 13, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 2, 'no_to_insert': 1, 'axis': 0, 'res': (2, 2, 4, 4), }, {'attrs': {'merge_area': (992, 2, 993, 4)}, 'insertion_point': 5, 'no_to_insert': 10, 'axis': 0, 'res': None, }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': -1, 'axis': 0, 'res': (1, 2, 2, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 5, 'no_to_insert': -1, 'axis': 0, 'res': (2, 2, 3, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 2, 'no_to_insert': -1, 'axis': 0, 'res': (2, 2, 2, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': -2, 'axis': 0, 'res': (0, 2, 1, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': -3, 'axis': 0, 'res': (0, 2, 0, 4), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': 1, 'axis': 1, 'res': (2, 3, 3, 5), }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': 200, 'axis': 1, 'res': None, }, {'attrs': {'merge_area': (2, 2, 3, 4)}, 'insertion_point': 0, 'no_to_insert': -2, 'axis': 1, 'res': (2, 0, 3, 2), }, ] @params(param_get_adjusted_merge_area) def test_get_adjusted_merge_area(self, attrs, insertion_point, no_to_insert, axis, res): """Unit test for _get_adjusted_merge_area""" merge_area = self.data_array._get_adjusted_merge_area(attrs, insertion_point, no_to_insert, axis) assert merge_area == res param_adjust_cell_attributes = [ {'inspoint': 0, 'noins': 5, 'axis': 0, 'src': (4, 3, 0), 'target': (9, 3, 0)}, {'inspoint': 34, 'noins': 5, 'axis': 0, 'src': (4, 3, 0), 'target': (4, 3, 0)}, {'inspoint': 0, 'noins': 0, 'axis': 0, 'src': (4, 3, 0), 'target': (4, 3, 0)}, {'inspoint': 1, 'noins': 5, 'axis': 1, 'src': (4, 3, 0), 'target': (4, 8, 0)}, {'inspoint': 1, 'noins': 5, 'axis': 1, 'src': (4, 3, 1), 'target': (4, 8, 1)}, {'inspoint': 0, 'noins': -1, 'axis': 2, 'src': (4, 3, 1), 'target': None}, {'inspoint': 0, 'noins': -1, 'axis': 2, 'src': (4, 3, 2), 'target': (4, 3, 1)}, ] @params(param_adjust_cell_attributes) def test_adjust_cell_attributes(self, inspoint, noins, axis, src, target): """Unit test for _adjust_cell_attributes""" row, col, tab = src val = {"angle": 0.2} attrs = [(Selection([], [], [], [], [(row, col)]), tab, val)] self.data_array._set_cell_attributes(attrs) self.data_array._adjust_cell_attributes(inspoint, noins, axis) if target is None: for key in val: # Should be at default value cell_attributes = self.data_array.cell_attributes default_ca = cell_attributes.default_cell_attributes[key] assert cell_attributes[src][key] == default_ca else: for key in val: assert self.data_array.cell_attributes[target][key] == val[key] param_test_insert = [ { "data": {(2, 3, 0): "42"}, "inspoint": 1, "notoins": 1, "axis": 0, "tab": None, "res": {(2, 3, 0): None, (3, 3, 0): "42"}, }, { "data": {(0, 0, 0): "0", (0, 0, 2): "2"}, "inspoint": 1, "notoins": 1, "axis": 2, "tab": None, "res": {(0, 0, 3): "2", (0, 0, 4): None}, }, ] @params(param_test_insert) def test_insert(self, data, inspoint, notoins, axis, tab, res): """Unit test for insert operation""" self.data_array.dict_grid.update(data) self.data_array.insert(inspoint, notoins, axis, tab) for key in res: assert self.data_array[key] == res[key] param_test_delete = [ { "data": {(2, 3, 4): "42"}, "delpoint": 1, "notodel": 1, "axis": 0, "tab": None, "res": {(1, 3, 4): "42"}, }, { "data": {(0, 0, 0): "1"}, "delpoint": 0, "notodel": 1, "axis": 0, "tab": 0, "res": {(0, 0, 0): None}, }, { "data": {(0, 0, 1): "1"}, "delpoint": 0, "notodel": 1, "axis": 2, "tab": None, "res": {(0, 0, 0): "1"}, }, { "data": {(3, 3, 2): "3"}, "delpoint": 0, "notodel": 2, "axis": 2, "tab": None, "res": {(3, 3, 0): "3"}, }, { "data": {(4, 2, 1): "3"}, "delpoint": 2, "notodel": 1, "axis": 1, "tab": 1, "res": {(4, 2, 1): None}, }, { "data": {(10, 0, 0): "1"}, "delpoint": 0, "notodel": 10, "axis": 0, "tab": 0, "res": {(0, 0, 0): "1"}, }, ] @params(param_test_delete) def test_delete(self, data, delpoint, notodel, axis, tab, res): """Tests delete operation""" self.data_array.dict_grid.update(data) self.data_array.delete(delpoint, notodel, axis, tab) for key in res: assert self.data_array[key] == res[key] def test_delete_error(self): """Tests delete operation error""" self.data_array[2, 3, 4] = "42" try: self.data_array.delete(1, 1000, 0) assert False except ValueError: pass def test_set_row_height(self): """Unit test for set_row_height""" self.data_array.set_row_height(7, 1, 22.345) assert self.data_array.row_heights[7, 1] == 22.345 def test_set_col_width(self): """Unit test for set_col_width""" self.data_array.set_col_width(7, 1, 22.345) assert self.data_array.col_widths[7, 1] == 22.345
class TestDataArray(object): """Unit tests for DataArray""" def setup_method(self, method): """Creates empty DataArray""" self.data_array = DataArray((100, 100, 100)) def test_iter(self): """Unit test for __iter__""" assert list(iter(self.data_array)) == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(list(iter(self.data_array))) == [(1, 2, 3), (1, 2, 4)] def test_keys(self): """Unit test for keys""" assert self.data_array.keys() == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(self.data_array.keys()) == [(1, 2, 3), (1, 2, 4)] def test_pop(self): """Unit test for pop""" self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert "12" == self.data_array.pop((1, 2, 3)) assert sorted(self.data_array.keys()) == [(1, 2, 4)] def test_shape(self): """Unit test for _get_shape and _set_shape""" assert self.data_array.shape == (100, 100, 100) self.data_array.shape = (10000, 100, 100) assert self.data_array.shape == (10000, 100, 100) param_get_last_filled_cell = [ {'content': {(0, 0, 0): "2"}, 'table': 0, 'res': (0, 0)}, {'content': {(2, 0, 2): "2"}, 'table': 0, 'res': (0, 0)}, {'content': {(2, 0, 2): "2"}, 'table': None, 'res': (2, 0)}, {'content': {(2, 0, 2): "2"}, 'table': 2, 'res': (2, 0)}, {'content': {(32, 30, 0): "432"}, 'table': 0, 'res': (32, 30)}, ] @params(param_get_last_filled_cell) def test_get_last_filled_cell(self, content, table, res): """Unit test for get_last_filled_cellet_end""" for key in content: self.data_array[key] = content[key] assert self.data_array.get_last_filled_cell(table)[:2] == res def test_getstate(self): """Unit test for __getstate__ (pickle support)""" assert "dict_grid" in self.data_array.__getstate__() def test_slicing(self): """Unit test for __getitem__ and __setitem__""" self.data_array[0, 0, 0] = "'Test'" self.data_array[0, 0, 0] = "'Tes'" assert self.data_array[0, 0, 0] == "'Tes'" def test_cell_array_generator(self): """Unit test for cell_array_generator""" cell_array = self.data_array[:5, 0, 0] assert list(cell_array) == [None] * 5 cell_array = self.data_array[:5, :5, 0] assert [list(c) for c in cell_array] == [[None] * 5] * 5 cell_array = self.data_array[:5, :5, :5] assert [[list(e) for e in c] for c in cell_array] == \ [[[None] * 5] * 5] * 5 def test_set_cell_attributes(self): """Unit test for _set_cell_attributes""" cell_attributes = ["Test"] self.data_array._set_cell_attributes(cell_attributes) assert self.data_array.cell_attributes == cell_attributes param_adjust_cell_attributes = [ {'inspoint': 0, 'noins': 5, 'axis': 0, 'src': (4, 3, 0), 'target': (9, 3, 0)}, {'inspoint': 34, 'noins': 5, 'axis': 0, 'src': (4, 3, 0), 'target': (4, 3, 0)}, {'inspoint': 0, 'noins': 0, 'axis': 0, 'src': (4, 3, 0), 'target': (4, 3, 0)}, {'inspoint': 1, 'noins': 5, 'axis': 1, 'src': (4, 3, 0), 'target': (4, 8, 0)}, {'inspoint': 1, 'noins': 5, 'axis': 1, 'src': (4, 3, 1), 'target': (4, 8, 1)}, ] @params(param_adjust_cell_attributes) def test_adjust_cell_attributes(self, inspoint, noins, axis, src, target): """Unit test for _adjust_cell_attributes""" row, col, tab = src val = {"angle": 0.2} attrs = [(Selection([], [], [], [], [(row, col)]), tab, val)] self.data_array._set_cell_attributes(attrs) self.data_array._adjust_cell_attributes(inspoint, noins, axis) for key in val: assert self.data_array.cell_attributes[target][key] == val[key] def test_insert(self): """Unit test for insert operation""" self.data_array[2, 3, 0] = 42 self.data_array.insert(1, 1, 0) assert self.data_array[2, 3, 0] is None assert self.data_array[3, 3, 0] == 42 def test_delete(self): """Tests delete operation""" self.data_array[2, 3, 4] = "42" self.data_array.delete(1, 1, 0) assert self.data_array[2, 3, 4] is None assert self.data_array[1, 3, 4] == "42" try: self.data_array.delete(1, 1000, 0) assert False except ValueError: pass def test_set_row_height(self): """Unit test for set_row_height""" self.data_array.set_row_height(7, 1, 22.345) assert self.data_array.row_heights[7, 1] == 22.345 def test_set_col_width(self): """Unit test for set_col_width""" self.data_array.set_col_width(7, 1, 22.345) assert self.data_array.col_widths[7, 1] == 22.345
class TestDataArray(object): """Unit tests for DataArray""" def setup_method(self, method): """Creates empty DataArray""" self.data_array = DataArray((100, 100, 100), Settings()) def test_iter(self): """Unit test for __iter__""" assert list(iter(self.data_array)) == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(list(iter(self.data_array))) == [(1, 2, 3), (1, 2, 4)] def test_keys(self): """Unit test for keys""" assert list(self.data_array.keys()) == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(self.data_array.keys()) == [(1, 2, 3), (1, 2, 4)] def test_pop(self): """Unit test for pop""" self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert "12" == self.data_array.pop((1, 2, 3)) assert sorted(self.data_array.keys()) == [(1, 2, 4)] def test_get_shape(self): """Unit test for _get_shape""" assert self.data_array.shape == (100, 100, 100) def test_set_shape(self): """Unit test for _set_shape""" self.data_array.shape = (10000, 100, 100) assert self.data_array.shape == (10000, 100, 100) param_get_last_filled_cell = [ ({ (0, 0, 0): "2" }, 0, (0, 0)), ({ (2, 0, 2): "2" }, 0, (0, 0)), ({ (2, 0, 2): "2" }, None, (2, 0)), ({ (2, 0, 2): "2" }, 2, (2, 0)), ({ (32, 30, 0): "432" }, 0, (32, 30)), ] @pytest.mark.parametrize("content,table,res", param_get_last_filled_cell) def test_get_last_filled_cell(self, content, table, res): """Unit test for get_last_filled_cellet_end""" for key in content: self.data_array[key] = content[key] assert self.data_array.get_last_filled_cell(table)[:2] == res def test_getstate(self): """Unit test for __getstate__ (pickle support)""" assert "dict_grid" in self.data_array.__getstate__() def test_slicing(self): """Unit test for __getitem__ and __setitem__""" self.data_array[0, 0, 0] = "'Test'" self.data_array[0, 0, 0] = "'Tes'" assert self.data_array[0, 0, 0] == "'Tes'" def test_cell_array_generator(self): """Unit test for cell_array_generator""" cell_array = self.data_array[:5, 0, 0] assert list(cell_array) == [None] * 5 cell_array = self.data_array[:5, :5, 0] assert [list(c) for c in cell_array] == [[None] * 5] * 5 cell_array = self.data_array[:5, :5, :5] assert [[list(e) for e in c] for c in cell_array] == \ [[[None] * 5] * 5] * 5 def test_set_cell_attributes(self): """Unit test for _set_cell_attributes""" cell_attributes = ["Test"] self.data_array.cell_attributes[:] = cell_attributes assert self.data_array.cell_attributes == cell_attributes param_adjust_cell_attributes = [ (0, 5, 0, (4, 3, 0), (9, 3, 0)), (34, 5, 0, (4, 3, 0), (4, 3, 0)), (0, 0, 0, (4, 3, 0), (4, 3, 0)), (1, 5, 1, (4, 3, 0), (4, 8, 0)), (1, 5, 1, (4, 3, 1), (4, 8, 1)), (0, -1, 2, (4, 3, 1), None), (0, -1, 2, (4, 3, 2), (4, 3, 1)), ] @pytest.mark.parametrize("inspoint, noins, axis, src, target", param_adjust_cell_attributes) def test_adjust_cell_attributes(self, inspoint, noins, axis, src, target): """Unit test for _adjust_cell_attributes""" row, col, tab = src val = {"angle": 0.2} attrs = [(Selection([], [], [], [], [(row, col)]), tab, val)] self.data_array.cell_attributes[:] = attrs self.data_array._adjust_cell_attributes(inspoint, noins, axis) if target is None: for key in val: # Should be at default value cell_attributes = self.data_array.cell_attributes default_ca = cell_attributes.default_cell_attributes[key] assert cell_attributes[src][key] == default_ca else: for key in val: assert self.data_array.cell_attributes[target][key] == val[key] param_test_insert = [ ({ (2, 3, 0): "42" }, 1, 1, 0, None, { (2, 3, 0): None, (3, 3, 0): "42" }), ({ (0, 0, 0): "0", (0, 0, 2): "2" }, 1, 1, 2, None, { (0, 0, 3): "2", (0, 0, 4): None }), ] @pytest.mark.parametrize("data, inspoint, notoins, axis, tab, res", param_test_insert) def test_insert(self, data, inspoint, notoins, axis, tab, res): """Unit test for insert operation""" self.data_array.dict_grid.update(data) self.data_array.insert(inspoint, notoins, axis, tab) for key in res: assert self.data_array[key] == res[key] param_test_delete = [ ({ (2, 3, 4): "42" }, 1, 1, 0, None, { (1, 3, 4): "42" }), ({ (0, 0, 0): "1" }, 0, 1, 0, 0, { (0, 0, 0): None }), ({ (0, 0, 1): "1" }, 0, 1, 2, None, { (0, 0, 0): "1" }), ({ (3, 3, 2): "3" }, 0, 2, 2, None, { (3, 3, 0): "3" }), ({ (4, 2, 1): "3" }, 2, 1, 1, 1, { (4, 2, 1): None }), ({ (10, 0, 0): "1" }, 0, 10, 0, 0, { (0, 0, 0): "1" }), ] @pytest.mark.parametrize("data, delpoint, notodel, axis, tab, res", param_test_delete) def test_delete(self, data, delpoint, notodel, axis, tab, res): """Tests delete operation""" self.data_array.dict_grid.update(data) self.data_array.delete(delpoint, notodel, axis, tab) for key in res: assert self.data_array[key] == res[key] def test_delete_error(self): """Tests delete operation error""" self.data_array[2, 3, 4] = "42" try: self.data_array.delete(1, 1000, 0) assert False except ValueError: pass def test_set_row_height(self): """Unit test for set_row_height""" self.data_array.set_row_height(7, 1, 22.345) assert self.data_array.row_heights[7, 1] == 22.345 def test_set_col_width(self): """Unit test for set_col_width""" self.data_array.set_col_width(7, 1, 22.345) assert self.data_array.col_widths[7, 1] == 22.345
class TestDataArray(object): """Unit tests for DataArray""" def setup_method(self, method): """Creates empty DataArray""" self.data_array = DataArray((100, 100, 100)) def test_iter(self): """Unit test for __iter__""" assert list(iter(self.data_array)) == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(list(iter(self.data_array))) == [(1, 2, 3), (1, 2, 4)] def test_keys(self): """Unit test for keys""" assert self.data_array.keys() == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(self.data_array.keys()) == [(1, 2, 3), (1, 2, 4)] @undotest_model def test_pop(self): """Unit test for pop""" self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert "12" == self.data_array.pop((1, 2, 3)) assert sorted(self.data_array.keys()) == [(1, 2, 4)] def test_get_shape(self): """Unit test for _get_shape""" assert self.data_array.shape == (100, 100, 100) @undotest_model def test_set_shape(self): """Unit test for _set_shape""" self.data_array.shape = (10000, 100, 100) assert self.data_array.shape == (10000, 100, 100) param_get_last_filled_cell = [ { 'content': { (0, 0, 0): "2" }, 'table': 0, 'res': (0, 0) }, { 'content': { (2, 0, 2): "2" }, 'table': 0, 'res': (0, 0) }, { 'content': { (2, 0, 2): "2" }, 'table': None, 'res': (2, 0) }, { 'content': { (2, 0, 2): "2" }, 'table': 2, 'res': (2, 0) }, { 'content': { (32, 30, 0): "432" }, 'table': 0, 'res': (32, 30) }, ] @params(param_get_last_filled_cell) def test_get_last_filled_cell(self, content, table, res): """Unit test for get_last_filled_cellet_end""" for key in content: self.data_array[key] = content[key] assert self.data_array.get_last_filled_cell(table)[:2] == res def test_getstate(self): """Unit test for __getstate__ (pickle support)""" assert "dict_grid" in self.data_array.__getstate__() def test_slicing(self): """Unit test for __getitem__ and __setitem__""" self.data_array[0, 0, 0] = "'Test'" self.data_array[0, 0, 0] = "'Tes'" assert self.data_array[0, 0, 0] == "'Tes'" def test_cell_array_generator(self): """Unit test for cell_array_generator""" cell_array = self.data_array[:5, 0, 0] assert list(cell_array) == [None] * 5 cell_array = self.data_array[:5, :5, 0] assert [list(c) for c in cell_array] == [[None] * 5] * 5 cell_array = self.data_array[:5, :5, :5] assert [[list(e) for e in c] for c in cell_array] == \ [[[None] * 5] * 5] * 5 def test_set_cell_attributes(self): """Unit test for _set_cell_attributes""" cell_attributes = ["Test"] self.data_array._set_cell_attributes(cell_attributes) assert self.data_array.cell_attributes == cell_attributes param_get_adjusted_merge_area = [ { 'attrs': {}, 'insertion_point': 0, 'no_to_insert': 1, 'axis': 0, 'res': None, }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 5, 'no_to_insert': 1, 'axis': 0, 'res': (2, 2, 3, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': 1, 'axis': 0, 'res': (3, 2, 4, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': 10, 'axis': 0, 'res': (12, 2, 13, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 2, 'no_to_insert': 1, 'axis': 0, 'res': (2, 2, 4, 4), }, { 'attrs': { 'merge_area': (992, 2, 993, 4) }, 'insertion_point': 5, 'no_to_insert': 10, 'axis': 0, 'res': None, }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': -1, 'axis': 0, 'res': (1, 2, 2, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 5, 'no_to_insert': -1, 'axis': 0, 'res': (2, 2, 3, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 2, 'no_to_insert': -1, 'axis': 0, 'res': (2, 2, 2, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': -2, 'axis': 0, 'res': (0, 2, 1, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': -3, 'axis': 0, 'res': (0, 2, 0, 4), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': 1, 'axis': 1, 'res': (2, 3, 3, 5), }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': 200, 'axis': 1, 'res': None, }, { 'attrs': { 'merge_area': (2, 2, 3, 4) }, 'insertion_point': 0, 'no_to_insert': -2, 'axis': 1, 'res': (2, 0, 3, 2), }, ] @params(param_get_adjusted_merge_area) def test_get_adjusted_merge_area(self, attrs, insertion_point, no_to_insert, axis, res): """Unit test for _get_adjusted_merge_area""" merge_area = self.data_array._get_adjusted_merge_area( attrs, insertion_point, no_to_insert, axis) assert merge_area == res param_adjust_cell_attributes = [ { 'inspoint': 0, 'noins': 5, 'axis': 0, 'src': (4, 3, 0), 'target': (9, 3, 0) }, { 'inspoint': 34, 'noins': 5, 'axis': 0, 'src': (4, 3, 0), 'target': (4, 3, 0) }, { 'inspoint': 0, 'noins': 0, 'axis': 0, 'src': (4, 3, 0), 'target': (4, 3, 0) }, { 'inspoint': 1, 'noins': 5, 'axis': 1, 'src': (4, 3, 0), 'target': (4, 8, 0) }, { 'inspoint': 1, 'noins': 5, 'axis': 1, 'src': (4, 3, 1), 'target': (4, 8, 1) }, { 'inspoint': 0, 'noins': -1, 'axis': 2, 'src': (4, 3, 1), 'target': None }, { 'inspoint': 0, 'noins': -1, 'axis': 2, 'src': (4, 3, 2), 'target': (4, 3, 1) }, ] @params(param_adjust_cell_attributes) def test_adjust_cell_attributes(self, inspoint, noins, axis, src, target): """Unit test for _adjust_cell_attributes""" row, col, tab = src val = {"angle": 0.2} attrs = [(Selection([], [], [], [], [(row, col)]), tab, val)] self.data_array._set_cell_attributes(attrs) self.data_array._adjust_cell_attributes(inspoint, noins, axis) if target is None: for key in val: # Should be at default value cell_attributes = self.data_array.cell_attributes default_ca = cell_attributes.default_cell_attributes[key] assert cell_attributes[src][key] == default_ca else: for key in val: assert self.data_array.cell_attributes[target][key] == val[key] param_test_insert = [ { "data": { (2, 3, 0): "42" }, "inspoint": 1, "notoins": 1, "axis": 0, "tab": None, "res": { (2, 3, 0): None, (3, 3, 0): "42" }, }, { "data": { (0, 0, 0): "0", (0, 0, 2): "2" }, "inspoint": 1, "notoins": 1, "axis": 2, "tab": None, "res": { (0, 0, 3): "2", (0, 0, 4): None }, }, ] @params(param_test_insert) def test_insert(self, data, inspoint, notoins, axis, tab, res): """Unit test for insert operation""" self.data_array.dict_grid.update(data) self.data_array.insert(inspoint, notoins, axis, tab) for key in res: assert self.data_array[key] == res[key] param_test_delete = [ { "data": { (2, 3, 4): "42" }, "delpoint": 1, "notodel": 1, "axis": 0, "tab": None, "res": { (1, 3, 4): "42" }, }, { "data": { (0, 0, 0): "1" }, "delpoint": 0, "notodel": 1, "axis": 0, "tab": 0, "res": { (0, 0, 0): None }, }, { "data": { (0, 0, 1): "1" }, "delpoint": 0, "notodel": 1, "axis": 2, "tab": None, "res": { (0, 0, 0): "1" }, }, { "data": { (3, 3, 2): "3" }, "delpoint": 0, "notodel": 2, "axis": 2, "tab": None, "res": { (3, 3, 0): "3" }, }, { "data": { (4, 2, 1): "3" }, "delpoint": 2, "notodel": 1, "axis": 1, "tab": 1, "res": { (4, 2, 1): None }, }, { "data": { (10, 0, 0): "1" }, "delpoint": 0, "notodel": 10, "axis": 0, "tab": 0, "res": { (0, 0, 0): "1" }, }, ] @params(param_test_delete) def test_delete(self, data, delpoint, notodel, axis, tab, res): """Tests delete operation""" self.data_array.dict_grid.update(data) self.data_array.delete(delpoint, notodel, axis, tab) for key in res: assert self.data_array[key] == res[key] def test_delete_error(self): """Tests delete operation error""" self.data_array[2, 3, 4] = "42" try: self.data_array.delete(1, 1000, 0) assert False except ValueError: pass def test_set_row_height(self): """Unit test for set_row_height""" self.data_array.set_row_height(7, 1, 22.345) assert self.data_array.row_heights[7, 1] == 22.345 def test_set_col_width(self): """Unit test for set_col_width""" self.data_array.set_col_width(7, 1, 22.345) assert self.data_array.col_widths[7, 1] == 22.345
class TestDataArray(object): """Unit tests for DataArray""" def setup_method(self, method): """Creates empty DataArray""" self.data_array = DataArray((100, 100, 100)) def test_iter(self): """Unit test for __iter__""" assert list(iter(self.data_array)) == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(list(iter(self.data_array))) == [(1, 2, 3), (1, 2, 4)] def test_keys(self): """Unit test for keys""" assert self.data_array.keys() == [] self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert sorted(self.data_array.keys()) == [(1, 2, 3), (1, 2, 4)] def test_pop(self): """Unit test for pop""" self.data_array[(1, 2, 3)] = "12" self.data_array[(1, 2, 4)] = "13" assert "12" == self.data_array.pop((1, 2, 3)) assert sorted(self.data_array.keys()) == [(1, 2, 4)] def test_shape(self): """Unit test for _get_shape and _set_shape""" assert self.data_array.shape == (100, 100, 100) self.data_array.shape = (10000, 100, 100) assert self.data_array.shape == (10000, 100, 100) def test_getstate(self): """Unit test for __getstate__ (pickle support)""" assert "dict_grid" in self.data_array.__getstate__() def test_str(self): """Unit test for __str__""" self.data_array[(1, 2, 3)] = "12" data_array_str = str(self.data_array) assert data_array_str == "{(1, 2, 3): '12'}" def test_slicing(self): """Unit test for __getitem__ and __setitem__""" self.data_array[0, 0, 0] = "'Test'" ##assert len(self.grid.unredo.undolist) == 1 self.data_array[0, 0, 0] = "'Tes'" ##assert len(self.grid.unredo.undolist) == 2 assert self.data_array[0, 0, 0] == "'Tes'" def test_cell_array_generator(self): """Unit test for cell_array_generator""" cell_array = self.data_array[:5, 0, 0] assert list(cell_array) == [None] * 5 cell_array = self.data_array[:5, :5, 0] assert [list(c) for c in cell_array] == [[None] * 5] * 5 cell_array = self.data_array[:5, :5, :5] assert [[list(e) for e in c] for c in cell_array] == \ [[[None] * 5] * 5] * 5 def test_adjust_shape(self): """Unit test for _adjust_shape""" self.data_array._adjust_shape(2, 0) res = list(self.data_array.shape) assert res == [102, 100, 100] def test_set_cell_attributes(self): """Unit test for _set_cell_attributes""" pass def test_adjust_cell_attributes(self): """Unit test for _adjust_cell_attributes""" pass def test_insert(self): """Unit test for insert operation""" self.data_array[2, 3, 4] = 42 self.data_array.insert(1, 100, 0) assert self.data_array.shape == (200, 100, 100) assert self.data_array[2, 3, 4] is None assert self.data_array[102, 3, 4] == 42 def test_delete(self): """Tests delete operation""" self.data_array[2, 3, 4] = "42" self.data_array.delete(1, 1, 0) assert self.data_array[2, 3, 4] is None assert self.data_array[1, 3, 4] == "42" print self.data_array.shape assert self.data_array.shape == (99, 100, 100) def test_set_row_height(self): """Unit test for set_row_height""" pass def test_set_col_width(self): """Unit test for set_col_width""" pass