Beispiel #1
0
def test_setData_decreasing():
    tbl_1 = [['hal_value', 'gui_value'],
             [        0.0,        1000],
             [        2.5,         900],
             [        5.0,         300],
             [        7.5,           0],
             [       10.0,        -100]]

    table_model = CalibrationTableModel()
    table_model.setDataArray(tbl_1)

    gui_col = 1
    #These should succeed at changing the data
    index = table_model.index(0,gui_col, QtCore.QModelIndex())
    table_model.setData(index, 1200, QtCore.Qt.EditRole)
    assert 1200 == table_model.data(index,  QtCore.Qt.DisplayRole)

    index = table_model.index(4,gui_col, QtCore.QModelIndex())
    table_model.setData(index, -101, QtCore.Qt.EditRole)
    assert -101 == table_model.data(index,  QtCore.Qt.DisplayRole)


    #This should fail
    index = table_model.index(4,gui_col, QtCore.QModelIndex())
    with pytest.raises(Exception) as e_info:
        table_model.setData(index, 0, QtCore.Qt.EditRole)
Beispiel #2
0
def test_addRemoveRows(qtbot, open_window):
    table_model = CalibrationTableModel()
    table_view = open_window(CalibrationTableView)
    table_view.setModel(table_model)

    starting_count = table_model.rowCount()

    #Find a QRect of a row
    cell_rect = table_view.visualRect(table_model.index(1,1,QtCore.QModelIndex()))

    #Add One After
    table_view.setSelection(cell_rect, QtCore.QItemSelectionModel.Select)
    table_view.addRowAfterSelected()
    assert (starting_count+1) ==  table_model.rowCount()
    qtbot.wait(TestingFlags.TEST_WAIT_SHORT)

    #Remove One
    table_view.setSelection(cell_rect, QtCore.QItemSelectionModel.Select)
    table_view.removeSelectedRow()
    assert (starting_count) ==  table_model.rowCount()
    qtbot.wait(TestingFlags.TEST_WAIT_SHORT)

    #Add One Before
    table_view.setSelection(cell_rect, QtCore.QItemSelectionModel.Select)
    table_view.addRowBeforeSelected()
    assert (starting_count+1) ==  table_model.rowCount()
    qtbot.wait(TestingFlags.TEST_WAIT_SHORT)
Beispiel #3
0
def test_setData_increasing_to_decreasing():
    tbl_1 = [['hal_value', 'gui_value'],
             [        0.0,        10],
             [       10.0,       100]]

    table_model = CalibrationTableModel()
    table_model.setDataArray(tbl_1)

    gui_col = 1

    #If there's just two rows we can change if it's increasing or decreasing
    index = table_model.index(0,gui_col, QtCore.QModelIndex())
    table_model.setData(index, 1200, QtCore.Qt.EditRole)
    assert 1200 == table_model.data(index,  QtCore.Qt.DisplayRole)

    #If there's just two rows we can change if it's increasing or decreasing
    index = table_model.index(1,gui_col, QtCore.QModelIndex())
    table_model.setData(index, 12000, QtCore.Qt.EditRole)
    assert 12000 == table_model.data(index,  QtCore.Qt.DisplayRole)
Beispiel #4
0
def test_flags(good_data_arrays):

    table_model = CalibrationTableModel()
    hal_col = table_model.halValueColumn()
    gui_col = table_model.halValueColumn()

    for good_data in good_data_arrays:
        table_model.setDataArray(good_data)

        main_data = good_data[1:]


        for i, row in enumerate(main_data):
            hal_flags = table_model.flags(table_model.index(i, hal_col, QtCore.QModelIndex()))
            gui_flags = table_model.flags(table_model.index(i, gui_col, QtCore.QModelIndex()))

            assert hal_flags == QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
            assert gui_flags == QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
Beispiel #5
0
def test_setData_increasing():
    tbl_1 = [['hal_value', 'gui_value'],
             [          0,        0.00],
             [         10,        0.60],
             [         50,        3.10],
             [        100,        9.00],
             [        160,       24.00]]

    table_model = CalibrationTableModel()
    table_model.setDataArray(tbl_1)


    #These should succeed at changing the data
    index = table_model.index(0,0, QtCore.QModelIndex())
    table_model.setData(index, -12.3, QtCore.Qt.EditRole)
    assert -12.3 == table_model.data(index,  QtCore.Qt.DisplayRole)

    index = table_model.index(0,1, QtCore.QModelIndex())
    table_model.setData(index, -1., QtCore.Qt.EditRole)
    assert -1. == table_model.data(index,  QtCore.Qt.DisplayRole)


    #These should fail at changing the data
    index = table_model.index(0,0, QtCore.QModelIndex())
    with pytest.raises(Exception) as e_info:
        table_model.setData(index, 3999, QtCore.Qt.EditRole)

    index = table_model.index(0,1, QtCore.QModelIndex())
    with pytest.raises(Exception) as e_info:
        table_model.setData(index, 16000, QtCore.Qt.EditRole)

    index = table_model.index(2,0, QtCore.QModelIndex())
    with pytest.raises(Exception) as e_info:
        table_model.setData(index, 'cat', QtCore.Qt.EditRole)

    #These should work
    index = table_model.index(2,0, QtCore.QModelIndex())
    table_model.setData(index, 10.01, QtCore.Qt.EditRole)
    assert 10.01 == table_model.data(index,  QtCore.Qt.DisplayRole)

    index = table_model.index(2,1, QtCore.QModelIndex())
    table_model.setData(index, 8.999, QtCore.Qt.EditRole)
    assert 8.999 == table_model.data(index,  QtCore.Qt.DisplayRole)