def test_cannot_remove_all_rows(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T08:15", "2019-07-23T09:10"], [2.3, -5.0, 7.0], True, False)) self.assertTrue(model.removeRows(0, 3)) self.assertEqual( model.value, TimeSeriesVariableResolution(["2019-07-05T12:00"], [2.3], True, False))
def test_insertRows_at_the_beginning_with_only_one_value(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution(["2019-07-05T12:00"], [-5.0], True, False)) self.assertTrue(model.insertRows(0, 1)) self.assertEqual( model.value, TimeSeriesVariableResolution( ["2019-07-05T11:00", "2019-07-05T12:00"], [0.0, -5.0], True, False), )
def test_flags(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T08:15"], [-5.0, 7.0], True, False)) for row in range(2): for column in range(2): model_index = model.index(row, column) self.assertEqual( model.flags(model_index), Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)
def test_data(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T08:15"], [-5.0, 7.0], True, False)) for role in [Qt.DisplayRole, Qt.EditRole]: model_index = model.index(0, 0) self.assertEqual(model.data(model_index, role), "2019-07-05T12:00:00") model_index = model.index(0, 1) self.assertEqual(model.data(model_index, role), -5.0)
def test_removeRows_from_the_middle(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T08:15", "2019-07-23T09:10"], [2.3, -5.0, 7.0], True, False)) self.assertTrue(model.removeRows(1, 1)) self.assertEqual( model.value, TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-23T09:10"], [2.3, 7.0], True, False))
def test_insertRows_in_the_end_with_only_one_value(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution(["2019-07-05T12:00"], [-5.0], True, False)) self.assertTrue(model.insertRows(1, 1)) self.assertEqual( model.value, TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-05T13:00"], [-5.0, 0.0], True, False), )
def test_insertRows_single_row_in_the_middle(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T12:00"], [-5.0, 7.0], True, False)) self.assertTrue(model.insertRows(1, 1)) self.assertEqual( model.value, TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-13T12:00", "2019-07-21T12:00"], [-5.0, 0.0, 7.0], True, False), )
def test_batch_set_data(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T08:15", "2019-07-23T09:10"], [2.3, -5.0, 7.0], True, False)) indexes = [model.index(0, 0), model.index(1, 1), model.index(2, 1)] values = ["2018-07-05T12:00", 55.5, -55.5] model.batch_set_data(indexes, values) expected = TimeSeriesVariableResolution( ["2018-07-05T12:00", "2019-07-21T08:15", "2019-07-23T09:10"], [2.3, 55.5, -55.5], True, False) self.assertEqual(model.value, expected)
def test_insertRows_in_the_end(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T12:00"], [-5.0, 7.0], True, False)) self.assertTrue(model.insertRows(2, 1)) self.assertEqual( model.value, TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T12:00", "2019-08-06T12:00"], [-5.0, 7.0, 0.0], True, False), )
def test_setData(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["1991-01-01T13:30", "1992-01-01T13:30"], [2.3, -5.0], True, False)) model_index = model.index(0, 1) model.setData(model_index, -4.0) self.assertEqual( model.value, TimeSeriesVariableResolution( ["1991-01-01T13:30", "1992-01-01T13:30"], [-4.0, -5.0], True, False), )
def setUp(self): QApplication.clipboard().clear() self._table_view = IndexedValueTableView(parent=None) series = TimeSeriesVariableResolution( [ "2019-08-08T12:00", "2019-08-08T13:00", "2019-08-08T14:00", "2019-08-08T15:00" ], [1.1, 2.2, 3.3, 4.4], False, False, ) model = TimeSeriesModelVariableResolution(series) self._table_view.setModel(model)
def test_reset_updates_indexes(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution( ["2019-07-05T12:00", "2019-07-21T08:15"], [2.3, -5.0], True, False)) model.reset( TimeSeriesVariableResolution( ["1991-01-01T13:30", "1992-01-01T13:30"], [7.0, -4.0], False, True)) self.assertEqual( model.value, TimeSeriesVariableResolution( ["1991-01-01T13:30", "1992-01-01T13:30"], [7.0, -4.0], False, True), )
def test_removing_last_row_fails(self): model = TimeSeriesModelVariableResolution( TimeSeriesVariableResolution(["2019-07-05T12:00"], [2.3], True, False)) self.assertFalse(model.removeRows(0, 1))