def test_data_for_first_row_returns_none_with_empty_array(self): model = ArrayModel() roles = [Qt.DisplayRole, Qt.ToolTip] index = model.index(0, 0) self.assertTrue(index.isValid()) for role in roles: self.assertIsNone(model.data(index, role))
def test_insertRows_when_empty_array(self): model = ArrayModel() self.assertTrue(model.insertRows(0, 2)) self.assertEqual(model.rowCount(), 3) expected_data = [0.0, 0.0, 0.0] for row, expected in enumerate(expected_data): index = model.index(row, 0) self.assertEqual(index.data(), expected)
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_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_errors_in_cells_are_marked_by_ErrorCell(self): model = ArrayModel() index = model.index(0, 0) self.assertTrue(model.setData(index, "This won't work")) self.assertEqual(model.data(index, Qt.DisplayRole), "Error") self.assertEqual( model.data(index, Qt.ToolTipRole), "Cannot parse: Could not decode the value: Expecting value: line 1 column 1 (char 0)", ) self.assertEqual(model.data(index, Qt.EditRole), "This won't work")
def test_removeRows_when_empty_array(self): model = ArrayModel() self.assertFalse(model.removeRows(0, 1))
def test_row_count_with_empty_array_is_still_one(self): model = ArrayModel() self.assertEqual(model.rowCount(), 1)
def test_columnCount(self): model = ArrayModel() self.assertEqual(model.columnCount(), 1) model.reset(Array([3, 5, 1])) self.assertEqual(model.columnCount(), 1)
def test_data_in_edit_role_for_first_row_returns_default_float_with_empty_array(self): model = ArrayModel() index = model.index(0, 0) self.assertTrue(index.isValid()) self.assertEqual(model.data(index, Qt.EditRole), 0.0)
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)