|
| 1 | +# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file. |
| 2 | + |
| 3 | +""" |
| 4 | +Operation modes test |
| 5 | +-------------------- |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +# guitest: show |
| 10 | + |
| 11 | +from __future__ import annotations |
| 12 | + |
| 13 | +from cdl import app |
| 14 | +from cdl.utils.qthelpers import cdl_app_context |
| 15 | +from cdl.utils.tests import get_test_fnames |
| 16 | + |
| 17 | + |
| 18 | +def test_single_operand_mode(): |
| 19 | + """Run single operand mode test scenario""" |
| 20 | + with cdl_app_context(exec_loop=True): |
| 21 | + win = app.create(h5files=[get_test_fnames("reorder*")[0]], console=False) |
| 22 | + panel = win.signalpanel |
| 23 | + view, model = panel.objview, panel.objmodel |
| 24 | + |
| 25 | + # Store the number of groups before the operations |
| 26 | + n_groups = len(model.get_groups()) |
| 27 | + |
| 28 | + # Select the two first groups |
| 29 | + groups = [model.get_group_from_number(idx) for idx in (1, 2)] |
| 30 | + view.select_groups(groups) |
| 31 | + |
| 32 | + # Perform a sum operation |
| 33 | + panel.processor.compute_sum() |
| 34 | + |
| 35 | + # Default operation mode is single operand mode, so the sum operation |
| 36 | + # is applied to the selected groups, and we should have a new group |
| 37 | + # with two signals being the sum of signals from each group: |
| 38 | + # - signal 1: group 1 signal 1 + group 1 signal 2 |
| 39 | + # - signal 2: group 2 signal 1 + group 2 signal 2 |
| 40 | + assert len(model.get_groups()) == n_groups + 1 |
| 41 | + new_group = model.get_group_from_number(n_groups + 1) |
| 42 | + assert len(new_group.get_objects()) == 2 |
| 43 | + for idx, obj in enumerate(new_group.get_objects()): |
| 44 | + pfx_orig = ", ".join(obj.short_id for obj in groups[idx].get_objects()) |
| 45 | + assert obj.title == f"Σ({pfx_orig})" |
| 46 | + |
| 47 | + # Remove new group |
| 48 | + view.select_groups([new_group]) |
| 49 | + panel.remove_object(force=True) |
| 50 | + |
| 51 | + # Store the number of groups before the operations |
| 52 | + n_groups = len(model.get_groups()) |
| 53 | + |
| 54 | + # Select the two first signals of the first two groups |
| 55 | + groups = [model.get_group_from_number(idx) for idx in (1, 2)] |
| 56 | + objs = groups[0][:2] + groups[1][:2] |
| 57 | + view.select_objects(objs) |
| 58 | + |
| 59 | + # Perform a sum operation |
| 60 | + panel.processor.compute_sum() |
| 61 | + |
| 62 | + # Default operation mode is single operand mode, so the sum operation |
| 63 | + # is applied to the selected signals, and we should have a new resulting |
| 64 | + # signal being the sum of the selected signals added in each group: |
| 65 | + # - signal added to group 1: group 1 signal 1 + group 2 signal 1 |
| 66 | + # - signal added to group 2: group 1 signal 2 + group 2 signal 2 |
| 67 | + assert len(model.get_groups()) == n_groups # no new group |
| 68 | + for idx in range(1): |
| 69 | + pfx_orig = ", ".join(obj.short_id for obj in groups[idx][:2]) |
| 70 | + assert groups[idx][-1].title == f"Σ({pfx_orig})" |
| 71 | + |
| 72 | + # Removing resulting signals |
| 73 | + view.select_objects([groups[0][-1], groups[1][-1]]) |
| 74 | + panel.remove_object() |
| 75 | + |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + test_single_operand_mode() |
0 commit comments