def test_value_shortening_rows(self): original = Map( ["a", "b", "c"], [0.0, Map(["bb"], [Map(["bbb"], [Array([-1.0])])]), Array([-2.0])]) model = MapModel(original) map_ = model.value() self.assertEqual(map_, original)
def test_removeRows_remove_all_rows(self): model = ArrayModel() model.reset(Array([5.0, 3.0, 7.0])) self.assertTrue(model.removeRows(0, 3)) self.assertEqual(model.rowCount(), 1) index = model.index(0, 0) self.assertIsNone(index.data())
def test_setData_on_last_row_extends_array(self): model = ArrayModel() model.reset(Array([5.0])) self.assertTrue(model.setData(model.index(1, 0), 2.3)) self.assertEqual(model.rowCount(), 3) self.assertEqual(model.index(0, 0).data(), 5.0) self.assertEqual(model.index(1, 0).data(), 2.3)
def test_show_value_editor(self): editor = ArrayEditor() editor.set_value(Array([-1.0])) table_view = editor._ui.array_table_view model = table_view.model() rect = table_view.visualRect(model.index(0, 0)) editor.open_value_editor = MagicMock() menu = ArrayTableContextMenu(editor, table_view, rect.center()) open_action = _find_action(menu, "Open value editor...") self.assertIsNotNone(open_action) open_action.trigger() editor.open_value_editor.assert_called_once_with(model.index(0, 0))
def test_remove_rows(self): editor = ArrayEditor() editor.set_value(Array([-1.0, -2.0])) table_view = editor._ui.array_table_view table_view.selectRow(0) model = table_view.model() rect = table_view.visualRect(model.index(0, 0)) menu = ArrayTableContextMenu(editor, table_view, rect.center()) remove_action = _find_action(menu, "Remove rows") self.assertIsNotNone(remove_action) remove_action.trigger() self.assertEqual(model.rowCount(), 1 + 1) self.assertEqual(model.index(0, 0).data(), -2.0)
def test_insert_row_before(self): editor = ArrayEditor() editor.set_value(Array([-1.0])) table_view = editor._ui.array_table_view table_view.selectRow(0) model = table_view.model() rect = table_view.visualRect(model.index(0, 0)) menu = ArrayTableContextMenu(editor, table_view, rect.center()) insert_action = _find_action(menu, "Insert row before") self.assertIsNotNone(insert_action) insert_action.trigger() self.assertEqual(model.rowCount(), 2 + 1) self.assertEqual(model.index(0, 0).data(), 0.0) self.assertEqual(model.index(1, 0).data(), -1.0)
def test_columnCount(self): model = ArrayModel() self.assertEqual(model.columnCount(), 1) model.reset(Array([3, 5, 1])) self.assertEqual(model.columnCount(), 1)
def array(self): """Returns the array modeled by this model.""" return Array(self._data, self._data_type)
def test_setData(self): model = ArrayModel() model.reset(Array([5.0])) self.assertTrue(model.setData(model.index(0, 0), 2.3)) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.index(0, 0).data(), 2.3)
def test_set_array_type_converts_existing_data(self): model = ArrayModel() model.reset(Array([5.0])) model.set_array_type(str) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.index(0, 0).data(), "5.0")
def test_batch_set_data_on_last_row_extends_table(self): model = ArrayModel() model.reset(Array([5.0])) model.batch_set_data([model.index(1, 0)], ["2.3"]) self.assertEqual(model.rowCount(), 3) self.assertEqual(model.index(0, 0).data(), 5.0)
def test_batch_set_data(self): model = ArrayModel() model.reset(Array([5.0])) model.batch_set_data([model.index(0, 0)], ["2.3"]) self.assertEqual(model.rowCount(), 2) self.assertEqual(model.index(0, 0).data(), 2.3)