Esempio n. 1
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. 2
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"])
Esempio n. 3
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. 4
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. 5
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)
 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]))
 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]))
 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. 9
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. 10
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. 11
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. 12
0
 def test_columnCount_nested_maps(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.columnCount(), 4)
Esempio n. 13
0
 def test_columnCount(self):
     map_value = Map(["a", "b"], [1.1, 2.2])
     model = MapModel(map_value)
     self.assertEqual(model.columnCount(), 3)
Esempio n. 14
0
 def test_trim_columns(self):
     map_value = Map(["a"], [1.1])
     model = MapModel(map_value)
     model.append_column()
     model.trim_columns()
     self.assertEqual(model.columnCount(), 3)