Exemple #1
0
def test_dataArray(good_data_arrays):
    table_model = CalibrationTableModel()

    for good_data in good_data_arrays:
        table_model.setDataArray(good_data)

        returned_array = table_model.dataArray()
        returned_array_copy = copy.deepcopy(returned_array)

        for i, row in enumerate(returned_array):
            for j, val in enumerate(row):
                returned_array[i][j] = None

        assert returned_array_copy == table_model.dataArray()
Exemple #2
0
def test_removeRows():
    table_model = CalibrationTableModel()

    tbl_1 = [['hal_value', 'gui_value'],
             [          0,        0.00],
             [         10,        0.63],
             [         50,        3.10],
             [        100,        9.66],
             [        255,       24.00]]


    #Try removing 2 rows
    number_to_remove = 2
    row_index = 1
    table_model.setDataArray(tbl_1)
    table_model.removeRows(row_index,number_to_remove)

    tbl_2 = [['hal_value', 'gui_value'],
             [          0,        0.00],
             [        100,        9.66],
             [        255,       24.00]]

    assert tbl_2 == table_model.dataArray()


    #Try removing 1 row
    number_to_remove = 1
    row_index = 0
    table_model.removeRows(row_index,number_to_remove)

    tbl_3 = [['hal_value', 'gui_value'],
             [        100,        9.66],
             [        255,       24.00]]

    assert tbl_3 == table_model.dataArray()

    #Try removing 1 row too many!
    number_to_remove = 1
    row_index = 0
    table_model.removeRows(row_index,number_to_remove)

    assert tbl_3 == table_model.dataArray()
Exemple #3
0
def test_setDataArray(good_data_arrays, bad_data_arrays):
    table_model = CalibrationTableModel()

    for good_data in good_data_arrays:
        table_model.setDataArray(good_data)
        assert good_data == table_model.dataArray()


    for bad_data in bad_data_arrays:
        with pytest.raises(Exception) as e_info:
            table_model.setDataArray(bad_data)
Exemple #4
0
def test_insertRows():
    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)


   #First try adding 1 row
    number_to_add = 1
    row_index = 1 #it's inserted above this index

    tbl_2 = [['hal_value', 'gui_value'],
             [          0,         0.00],
             [          5,         0.30],
             [         10,         0.60],
             [         50,         3.10],
             [        100,         9.00],
             [        160,        24.00]]

    table_model.insertRows(row_index,number_to_add)
    assert tbl_2 == table_model.dataArray()


    #Try adding 2 rows
    number_to_add = 2
    row_index = 5 #it's inserted above this index
    tbl_3 = [['hal_value', 'gui_value'],
             [          0,         0.00],
             [          5,         0.30],
             [         10,         0.60],
             [         50,         3.10],
             [        100,         9.00],
             [        120,         14.0],
             [        140,         19.0],
             [        160,        24.00]]

    table_model.insertRows(row_index,number_to_add)
    assert tbl_3 == table_model.dataArray()


    #Try adding 2 rows at beginning
    number_to_add = 2
    row_index = 0 #it's inserted above this index
    tbl_4 = [['hal_value', 'gui_value'],
             [        -10,        -0.60],  #row 0
             [         -5,        -0.30],
             [          0,         0.00],
             [          5,         0.30],
             [         10,         0.60],
             [         50,         3.10],
             [        100,         9.00],
             [        120,         14.0],
             [        140,         19.0],
             [        160,        24.00]] #row 9


    table_model.insertRows(row_index,number_to_add)
    assert tbl_4 == table_model.dataArray()


    #Try adding 2 rows at the end
    number_to_add = 2
    row_index = 10 #it's inserted above this index

    tbl_5 = [['hal_value', 'gui_value'],
             [        -10,        -0.60],  #row 0
             [         -5,        -0.30],
             [          0,         0.00],
             [          5,         0.30],
             [         10,         0.60],
             [         50,         3.10],
             [        100,         9.00],
             [        120,         14.0],
             [        140,         19.0],
             [        160,        24.00],
             [        180,        29.00],
             [        200,        34.00]] #row 11

    table_model.insertRows(row_index,number_to_add)
    assert tbl_5 == table_model.dataArray()