|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Licensed under the terms of the BSD 3-Clause |
| 4 | +# (see cdl/LICENSE for details) |
| 5 | + |
| 6 | +""" |
| 7 | +Miscellaneous application test |
| 8 | +------------------------------ |
| 9 | +
|
| 10 | +Whenever we have a test that does not fit in any of the other test files, |
| 11 | +we put it here... |
| 12 | +""" |
| 13 | + |
| 14 | +# pylint: disable=invalid-name # Allows short reference names like x, y, ... |
| 15 | +# guitest: show |
| 16 | + |
| 17 | +from typing import Any |
| 18 | + |
| 19 | +import cdl.obj |
| 20 | +import cdl.param |
| 21 | +from cdl.env import execenv |
| 22 | +from cdl.tests import cdltest_app_context |
| 23 | +from cdl.tests.data import create_paracetamol_signal |
| 24 | + |
| 25 | + |
| 26 | +def __print_test_result(title: str, result: Any = None) -> None: |
| 27 | + """Print a test result""" |
| 28 | + execenv.print(f"Testing {title}{'' if result is None else ':'}") |
| 29 | + if result is not None: |
| 30 | + execenv.print(str(result)) |
| 31 | + execenv.print("") |
| 32 | + |
| 33 | + |
| 34 | +def test_misc_app() -> None: |
| 35 | + """Run misc. application test scenario""" |
| 36 | + with cdltest_app_context(console=False) as win: |
| 37 | + execenv.print("Miscellaneous application test") |
| 38 | + execenv.print("==============================") |
| 39 | + execenv.print("") |
| 40 | + |
| 41 | + # We don't need to refresh the GUI during those tests (that's faster!) |
| 42 | + win.toggle_auto_refresh(False) |
| 43 | + |
| 44 | + panel = win.signalpanel |
| 45 | + objview = panel.objview |
| 46 | + |
| 47 | + sig = create_paracetamol_signal() |
| 48 | + panel.add_object(sig) |
| 49 | + panel.processor.compute_derivative() |
| 50 | + panel.processor.compute_moving_average(cdl.param.MovingAverageParam.create(n=5)) |
| 51 | + |
| 52 | + __print_test_result("`SimpleObjectTree.__str__` method", objview) |
| 53 | + |
| 54 | + # Updated metadata view settings: |
| 55 | + __print_test_result("Updated metadata view settings") |
| 56 | + panel.update_metadata_view_settings() |
| 57 | + |
| 58 | + # Double click on the first signal item in object view: |
| 59 | + __print_test_result("Double click on the first signal item in object view") |
| 60 | + tree_item = objview.currentItem() |
| 61 | + objview.itemDoubleClicked.emit(tree_item, 0) |
| 62 | + |
| 63 | + # Open context menu on current item: |
| 64 | + __print_test_result("Open context menu on current item") |
| 65 | + tree_item_pos = objview.mapToGlobal(objview.visualItemRect(tree_item).center()) |
| 66 | + objview.SIG_CONTEXT_MENU.emit(tree_item_pos) |
| 67 | + |
| 68 | + # Plot item parameters changed: |
| 69 | + __print_test_result("Plot item parameters changed") |
| 70 | + objview.select_objects([sig.uuid]) |
| 71 | + item = panel.plothandler[sig.uuid] |
| 72 | + panel.plot_item_parameters_changed(item) |
| 73 | + |
| 74 | + # Duplicate group: |
| 75 | + __print_test_result("Duplicate group") |
| 76 | + objview.select_groups([1]) |
| 77 | + panel.duplicate_object() |
| 78 | + |
| 79 | + # Delete group: |
| 80 | + __print_test_result("Delete group") |
| 81 | + objview.select_groups([2]) |
| 82 | + panel.remove_object() |
| 83 | + |
| 84 | + # Exec import wizard: |
| 85 | + __print_test_result("Exec signal import wizard") |
| 86 | + win.signalpanel.exec_import_wizard() |
| 87 | + __print_test_result("Exec image import wizard") |
| 88 | + win.imagepanel.exec_import_wizard() |
| 89 | + |
| 90 | + # Properties changed: |
| 91 | + __print_test_result("Properties changed") |
| 92 | + objview.select_objects([sig.uuid]) |
| 93 | + panel.properties_changed() |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + test_misc_app() |
0 commit comments