Skip to content

Commit ebff98e

Browse files
committed
Test coverage: add various unit tests
1 parent 1a011e4 commit ebff98e

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

cdl/core/gui/panel/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def paste_metadata(self) -> None:
500500
def remove_object(self) -> None:
501501
"""Remove signal/image object"""
502502
sel_groups = self.objview.get_sel_groups()
503-
if sel_groups:
503+
if sel_groups and not execenv.unattended:
504504
answer = QW.QMessageBox.warning(
505505
self,
506506
_("Delete group(s)"),

cdl/tests/features/common/metadata_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def __test_metadata_features(panel: BaseDataPanel):
4747
# Duplicate the first object
4848
panel.duplicate_object()
4949
# Delete metadata of the first object
50-
panel.delete_metadata()
50+
for keep_roi in (True, False): # Test both cases (coverage test)
51+
panel.delete_metadata(keep_roi=keep_roi)
5152
# Select and copy metadata of the second object
5253
panel.objview.select_objects([2])
5354
panel.copy_metadata()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

Comments
 (0)