Exemplo n.º 1
0
 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))
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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())
Exemplo n.º 5
0
 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")
Exemplo n.º 6
0
 def test_removeRows_when_empty_array(self):
     model = ArrayModel()
     self.assertFalse(model.removeRows(0, 1))
Exemplo n.º 7
0
 def test_row_count_with_empty_array_is_still_one(self):
     model = ArrayModel()
     self.assertEqual(model.rowCount(), 1)
Exemplo n.º 8
0
 def test_columnCount(self):
     model = ArrayModel()
     self.assertEqual(model.columnCount(), 1)
     model.reset(Array([3, 5, 1]))
     self.assertEqual(model.columnCount(), 1)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
 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")
Exemplo n.º 12
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)
Exemplo n.º 13
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)