Example #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)
Example #2
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)
Example #3
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)