Esempio n. 1
0
 def test_data_EditRole(self):
     map_value = Map(["a", "b"], [1.1, 2.2])
     model = MapModel(map_value)
     self.assertEqual(model.index(0, 0).data(Qt.EditRole), "a")
     self.assertEqual(model.index(1, 0).data(Qt.EditRole), "b")
     self.assertEqual(model.index(0, 1).data(Qt.EditRole), 1.1)
     self.assertEqual(model.index(1, 1).data(Qt.EditRole), 2.2)
Esempio n. 2
0
 def test_setData_does_not_clear_value_if_it_is_zero(self):
     model = MapModel(Map([], [], str))
     model.setData(model.index(0, 0), "idx")
     model.setData(model.index(0, 1), 0.0)
     self.assertEqual(model.rowCount(), 1 + 1)
     self.assertEqual(model.columnCount(), 2 + 1)
     self.assertEqual(model.index(0, 0).data(), "idx")
     self.assertEqual(model.index(0, 1).data(), 0.0)
Esempio n. 3
0
 def test_data_FontRole(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     self.assertEqual(model.index(0, 0).data(Qt.FontRole), None)
     self.assertEqual(model.index(1, 0).data(Qt.FontRole), None)
     self.assertTrue(model.index(0, 1).data(Qt.FontRole).bold())
     self.assertEqual(model.index(1, 1).data(Qt.FontRole), None)
     self.assertEqual(model.index(0, 2).data(Qt.FontRole), None)
     self.assertEqual(model.index(1, 2).data(Qt.FontRole), None)
Esempio n. 4
0
 def test_data_BackgroundRole(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     expected = QColor(245, 245, 245)
     self.assertEqual(model.index(0, 0).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(1, 0).data(Qt.BackgroundRole), expected)
     self.assertEqual(model.index(0, 1).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(1, 1).data(Qt.BackgroundRole), expected)
     self.assertEqual(model.index(0, 2).data(Qt.BackgroundRole), expected)
     self.assertEqual(model.index(1, 2).data(Qt.BackgroundRole), expected)
Esempio n. 5
0
 def test_insertRows_to_end(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     self.assertTrue(model.insertRows(1, 1))
     self.assertEqual(model.rowCount(), 3)
     self.assertEqual(model.index(0, 0).data(), "a")
     self.assertEqual(model.index(0, 1).data(), 1.1)
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 0).data(), "a")
     self.assertEqual(model.index(1, 1).data(), 1.1)
     self.assertEqual(model.index(1, 2).data(), "")
Esempio n. 6
0
 def test_removeRows_last_row(self):
     map_value = Map(["a", "b"], [1.1, 2.2])
     model = MapModel(map_value)
     self.assertTrue(model.removeRows(0, 1))
     self.assertEqual(model.rowCount(), 2)
     self.assertEqual(model.index(0, 0).data(), "b")
     self.assertEqual(model.index(0, 1).data(), 2.2)
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 0).data(), "")
     self.assertEqual(model.index(1, 1).data(), "")
     self.assertEqual(model.index(1, 2).data(), "")
Esempio n. 7
0
 def test_insertRows_to_empty_model(self):
     map_value = Map([], [], str)
     model = MapModel(map_value)
     self.assertEqual(model.rowCount(), 1)
     self.assertTrue(model.insertRows(0, 1))
     self.assertEqual(model.rowCount(), 2)
     self.assertEqual(model.index(0, 0).data(), None)
     self.assertEqual(model.index(0, 1).data(), None)
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 0).data(), "")
     self.assertEqual(model.index(1, 1).data(), "")
     self.assertEqual(model.index(1, 2).data(), "")
Esempio n. 8
0
 def test_data_DisplayRole(self):
     map_value = Map(["a", "b"], [1.1, 2.2])
     model = MapModel(map_value)
     self.assertEqual(model.index(0, 0).data(), "a")
     self.assertEqual(model.index(1, 0).data(), "b")
     self.assertEqual(model.index(2, 0).data(), "")
     self.assertEqual(model.index(0, 1).data(), 1.1)
     self.assertEqual(model.index(1, 1).data(), 2.2)
     self.assertEqual(model.index(2, 1).data(), "")
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 2).data(), "")
     self.assertEqual(model.index(2, 2).data(), "")
Esempio n. 9
0
 def test_data_nested_maps_EditRole(self):
     nested_map = Map(["a", "b"], [1.1, 2.2])
     map_value = Map(["A", "B"], [-1.1, nested_map])
     model = MapModel(map_value)
     self.assertEqual(model.index(0, 0).data(Qt.EditRole), "A")
     self.assertEqual(model.index(1, 0).data(Qt.EditRole), "B")
     self.assertEqual(model.index(2, 0).data(Qt.EditRole), "B")
     self.assertEqual(model.index(0, 1).data(Qt.EditRole), -1.1)
     self.assertEqual(model.index(1, 1).data(Qt.EditRole), "a")
     self.assertEqual(model.index(2, 1).data(Qt.EditRole), "b")
     self.assertEqual(model.index(0, 2).data(Qt.EditRole), None)
     self.assertEqual(model.index(1, 2).data(Qt.EditRole), 1.1)
     self.assertEqual(model.index(2, 2).data(Qt.EditRole), 2.2)
Esempio n. 10
0
 def test_setData_expands_empty_table(self):
     model = MapModel(Map([], [], Duration))
     self.assertEqual(model.rowCount(), 1)
     self.assertEqual(model.columnCount(), 1)
     self.assertEqual(model.index(0, 0).data(), "")
     self.assertTrue(model.setData(model.index(0, 0), Duration("1 month")))
     self.assertEqual(model.rowCount(), 2)
     self.assertEqual(model.columnCount(), 3)
     self.assertEqual(model.index(0, 0).data(), "1M")
     self.assertEqual(model.index(0, 1).data(), None)
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 0).data(), "")
     self.assertEqual(model.index(1, 1).data(), "")
     self.assertEqual(model.index(1, 2).data(), "")
Esempio n. 11
0
 def test_convert_leaf_maps(self):
     nested_map = Map(
         [DateTime("2020-07-03 12:00:00"),
          DateTime("2020-07-03 12:00:00")], [22.2, 23.3])
     map_ = Map([1.0], [nested_map])
     model = MapModel(map_)
     model.convert_leaf_maps()
     self.assertEqual(model.columnCount(), 3)
     self.assertEqual(model.rowCount(), 2)
     self.assertEqual(model.index(0, 0).data(), 1.0)
     self.assertEqual(model.index(0, 1).data(), "Time series")
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 0).data(), "")
     self.assertEqual(model.index(1, 1).data(), "")
     self.assertEqual(model.index(1, 2).data(), "")
Esempio n. 12
0
 def test_flags(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     index = model.index(0, 0)
     self.assertEqual(
         model.flags(index),
         Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)
Esempio n. 13
0
 def test_removeRows_single_row(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     self.assertTrue(model.removeRows(0, 1))
     self.assertEqual(model.rowCount(), 1)
     self.assertEqual(model.columnCount(), 1)
     self.assertEqual(model.index(0, 0).data(), "")
Esempio n. 14
0
 def test_data_DisplayRole_repeated_indexes_do_not_show(self):
     leaf_map = Map(["a", "b"], [1.1, 2.2])
     nested_map = Map(["A"], [leaf_map])
     root_map = Map(["root"], [nested_map])
     model = MapModel(root_map)
     expected_data = [["root", "A", "a", 1.1], ["root", "A", "b", 2.2]]
     for row in range(2):
         for column in range(4):
             index = model.index(row, column)
             self.assertEqual(index.data(), expected_data[row][column])
 def test_copy_selection(self):
     model = MapModel(Map(["A"], [2.3]))
     table_view = MapTableView()
     table_view.setModel(model)
     for column in (0, 1):
         table_view.selectionModel().select(model.index(0, column),
                                            QItemSelectionModel.Select)
     self.assertTrue(table_view.copy())
     clip = StringIO(QApplication.clipboard().text())
     table = [row for row in csv.reader(clip, delimiter="\t")]
     self.assertEqual(table, [["A", "2.3"]])
 def test_paste_to_single_cell_pastes_everything(self):
     model = MapModel(Map(["A"], [2.3]))
     table_view = MapTableView()
     table_view.setModel(model)
     table_view.selectionModel().select(model.index(0, 0),
                                        QItemSelectionModel.Select)
     self._write_to_clipboard([["V", -5.5], ["W", -6.6]])
     self.assertTrue(table_view.paste())
     self.assertEqual(model.rowCount(), 3)
     self.assertEqual(model.columnCount(), 3)
     self.assertEqual(model.value(), Map(["V", "W"], [-5.5, -6.6]))
Esempio n. 17
0
 def test_value_interleaved_rows(self):
     model = MapModel(Map(["a"], [0.0]))
     model.insertRows(1, 2)
     self.assertEqual(model.rowCount(), 4)
     model.append_column()
     self.assertEqual(model.columnCount(), 4)
     model.setData(model.index(0, 0), "key1")
     model.setData(model.index(0, 1), "a")
     model.setData(model.index(0, 2), -2.0)
     model.setData(model.index(1, 0), "key2")
     model.setData(model.index(1, 1), 23.0)
     model.setData(model.index(2, 0), "key1")
     model.setData(model.index(2, 1), "b")
     model.setData(model.index(2, 2), -3.0)
     map_ = model.value()
     self.assertEqual(map_.indexes, ["key1", "key2"])
     self.assertIsInstance(map_.values[0], Map)
     self.assertEqual(map_.values[0].indexes, ["a", "b"])
     self.assertEqual(map_.values[0].values, [-2.0, -3.0])
     self.assertEqual(map_.values[1], 23.0)
Esempio n. 18
0
 def test_removeRows_middle_row_in_nested_map(self):
     nested_map = Map(["a", "b", "c"], [1.1, 2.2, 3.3])
     map_value = Map(["A"], [nested_map])
     model = MapModel(map_value)
     self.assertTrue(model.removeRows(1, 1))
     self.assertEqual(model.rowCount(), 3)
     expected_table = [["A", "a", 1.1, ""], ["A", "c", 3.3, ""],
                       ["", "", "", ""]]
     for y, row in enumerate(expected_table):
         for x, expected in enumerate(row):
             self.assertEqual(model.index(y, x).data(), expected)
 def test_paste_to_empty_table(self):
     model = MapModel(Map([], [], str))
     table_view = MapTableView()
     table_view.setModel(model)
     table_view.selectionModel().select(model.index(0, 0),
                                        QItemSelectionModel.Select)
     self._write_to_clipboard([["A", 2.3]])
     self.assertTrue(table_view.paste())
     self.assertEqual(model.rowCount(), 2)
     self.assertEqual(model.columnCount(), 3)
     self.assertEqual(model.value(), Map(["A"], [2.3]))
Esempio n. 20
0
 def test_value_interleaved_rows_nested_maps_with_same_indexes(self):
     model = MapModel(Map(["a"], [0.0]))
     model.insertRows(1, 3)
     self.assertEqual(model.rowCount(), 5)
     model.append_column()
     self.assertEqual(model.columnCount(), 4)
     model.setData(model.index(0, 0), "key1")
     model.setData(model.index(0, 1), "kkey1")
     model.setData(model.index(0, 2), "value11")
     model.setData(model.index(1, 0), "key2")
     model.setData(model.index(1, 1), "kkey1")
     model.setData(model.index(1, 2), "value21")
     model.setData(model.index(2, 0), "key1")
     model.setData(model.index(2, 1), "kkey2")
     model.setData(model.index(2, 2), "value12")
     model.setData(model.index(3, 0), "key2")
     model.setData(model.index(3, 1), "kkey2")
     model.setData(model.index(3, 2), "value22")
     map_ = model.value()
     self.assertEqual(map_.indexes, ["key1", "key2"])
     self.assertIsInstance(map_.values[0], Map)
     self.assertEqual(map_.values[0].indexes, ["kkey1", "kkey2"])
     self.assertEqual(map_.values[0].values, ["value11", "value12"])
     self.assertIsInstance(map_.values[1], Map)
     self.assertEqual(map_.values[1].indexes, ["kkey1", "kkey2"])
     self.assertEqual(map_.values[1].values, ["value21", "value22"])
 def test_paste_large_data_to_small_selection_cuts_data(self):
     model = MapModel(Map(["A", "B", "C"], [2.3, 3.2, 4.3]))
     table_view = MapTableView()
     table_view.setModel(model)
     for row in (0, 1):
         table_view.selectionModel().select(model.index(row, 0),
                                            QItemSelectionModel.Select)
     self._write_to_clipboard([["Q", -4.4], ["V", -5.5], ["W", -6.6]])
     self.assertTrue(table_view.paste())
     self.assertEqual(model.rowCount(), 4)
     self.assertEqual(model.columnCount(), 3)
     m = model.value()
     self.assertEqual(model.value(), Map(["Q", "V", "C"], [2.3, 3.2, 4.3]))
Esempio n. 22
0
 def test_append_column(self):
     nested_map = Map(["a", "b"], [1.1, 2.2])
     map_value = Map(["A", "B"], [-1.1, nested_map])
     model = MapModel(map_value)
     model.append_column()
     self.assertEqual(model.columnCount(), 5)
     expected_table = [
         ["A", -1.1, None, None, ""],
         ["B", "a", 1.1, None, ""],
         ["B", "b", 2.2, None, ""],
         ["", "", "", "", ""],
     ]
     for y, row in enumerate(expected_table):
         for x, expected in enumerate(row):
             index = model.index(y, x)
             self.assertEqual(index.data(), expected)
Esempio n. 23
0
 def test_data_nested_maps_FontRole(self):
     nested_map = Map(["a", "b"], [1.1, 2.2])
     map_value = Map(["A", "B"], [-1.1, nested_map])
     model = MapModel(map_value)
     self.assertEqual(model.index(0, 0).data(Qt.FontRole), None)
     self.assertEqual(model.index(1, 0).data(Qt.FontRole), None)
     self.assertEqual(model.index(2, 0).data(Qt.FontRole), None)
     self.assertTrue(model.index(0, 1).data(Qt.FontRole).bold())
     self.assertEqual(model.index(1, 1).data(Qt.FontRole), None)
     self.assertEqual(model.index(2, 1).data(Qt.FontRole), None)
     self.assertEqual(model.index(0, 2).data(Qt.FontRole), None)
     self.assertTrue(model.index(1, 2).data(Qt.FontRole).bold())
     self.assertTrue(model.index(2, 2).data(Qt.FontRole).bold())
Esempio n. 24
0
 def test_setData_expands_rows(self):
     model = MapModel(Map([Duration("1 month")], [1.1]))
     self.assertEqual(model.rowCount(), 2)
     self.assertEqual(model.columnCount(), 3)
     self.assertTrue(model.setData(model.index(1, 1), 2.2))
     self.assertEqual(model.rowCount(), 3)
     self.assertEqual(model.columnCount(), 3)
     self.assertEqual(model.index(0, 0).data(), "1M")
     self.assertEqual(model.index(0, 1).data(), 1.1)
     self.assertEqual(model.index(0, 2).data(), "")
     self.assertEqual(model.index(1, 0).data(), "1M")
     self.assertEqual(model.index(1, 1).data(), 2.2)
     self.assertEqual(model.index(1, 2).data(), "")
     self.assertEqual(model.index(2, 0).data(), "")
     self.assertEqual(model.index(2, 1).data(), "")
     self.assertEqual(model.index(2, 2).data(), "")
Esempio n. 25
0
 def test_data_nested_maps_BackgroundRole(self):
     nested_map = Map(["a", "b"], [1.1, 2.2])
     map_value = Map(["A", "B"], [-1.1, nested_map])
     model = MapModel(map_value)
     self.assertEqual(model.index(0, 0).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(1, 0).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(2, 0).data(Qt.BackgroundRole), None)
     self.assertEqual(
         model.index(3, 0).data(Qt.BackgroundRole), QColor(245, 245, 245))
     self.assertEqual(model.index(0, 1).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(1, 1).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(2, 1).data(Qt.BackgroundRole), None)
     self.assertEqual(
         model.index(3, 1).data(Qt.BackgroundRole), QColor(245, 245, 245))
     self.assertEqual(
         model.index(0, 2).data(Qt.BackgroundRole), QColor(255, 240, 240))
     self.assertEqual(model.index(1, 2).data(Qt.BackgroundRole), None)
     self.assertEqual(model.index(2, 2).data(Qt.BackgroundRole), None)
     self.assertEqual(
         model.index(3, 2).data(Qt.BackgroundRole), QColor(245, 245, 245))
     self.assertEqual(
         model.index(0, 3).data(Qt.BackgroundRole), QColor(245, 245, 245))
     self.assertEqual(
         model.index(1, 3).data(Qt.BackgroundRole), QColor(245, 245, 245))
     self.assertEqual(
         model.index(2, 3).data(Qt.BackgroundRole), QColor(245, 245, 245))
     self.assertEqual(
         model.index(3, 3).data(Qt.BackgroundRole), QColor(245, 245, 245))
Esempio n. 26
0
 def test_setData(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     self.assertTrue(model.setData(model.index(0, 0), Duration("1 month")))
     self.assertEqual(model.index(0, 0).data(), "1M")