示例#1
0
def testActions():

    t = buildTable()
    n = len(t)
    model = TableModel(t, None)
    t_orig = t.copy()

    action = DeleteRowsAction(model, [0], [0])
    action.do()
    assert len(model.table) == len(t_orig)-1
    assert model.table.rows[0] == t_orig.rows[1]
    action.undo()
    assert len(model.table) == len(t_orig)
    assert model.table.rows[0] == t_orig.rows[0]

    action = CloneRowAction(model, 0, 0)
    action.do()
    assert model.table.rows[0] == t_orig.rows[0]
    assert model.table.rows[1] == t_orig.rows[0]
    assert model.table.rows[2] == t_orig.rows[1]
    assert len(model.table) == n+1
    action.undo()
    assert len(model.table) == n
    assert model.table.rows[0] == t_orig.rows[0]
    assert model.table.rows[1] == t_orig.rows[1]

    orig_permutation = model.get_row_permutation()
    action = SortTableAction(model, [("mz", True)])
    action.do()
    permutation = model.get_row_permutation()
    assert tuple(model.table.mz.values[pi] for pi in permutation) == (None, 1.0, 2.0)
    action.undo()
    permutation = model.get_row_permutation()
    assert permutation == orig_permutation

    orig_permutation = model.get_row_permutation()
    action = SortTableAction(model, [("mz", False)])
    action.do()
    permutation = model.get_row_permutation()
    assert tuple(model.table.mz.values[pi] for pi in permutation) == (2.0, 1.0, None)
    action.undo()
    permutation = model.get_row_permutation()
    assert permutation == orig_permutation

    class Index(object):

        def row(self):
            return 0

        def column(self):
            return 0

    action = ChangeValueAction(model, Index(), 0, 0, 3.0)
    action.do()
    assert model.table.rows[0][0] == 3.0
    action.undo()
    assert model.table.rows[0][0] == 1.0

    t = buildTable()
    import numpy
    peak = numpy.array(((1.0, 100.0),))
    specs = [Spectrum(peak, rt, 1, "+") for rt in range(9, 15)]
    pm = PeakMap(specs)

    t.replaceColumn("peakmap", pm)

    model.table = emzed.utils.integrate(t, "no_integration")

    action = IntegrateAction(model, 0, "", "trapez", 0, 100, 0)
    action.do()
    assert model.table.area.values[0] == 500.0
    action.undo()

    assert model.table.area.values[0] == None