Skip to content

Commit c910c98

Browse files
committed
Refactor pulse features application test to improve table validation and structure
1 parent f4938f9 commit c910c98

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

datalab/tests/features/signal/pulse_features_app_test.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,60 @@
77
# pylint: disable=invalid-name # Allows short reference names like x, y, ...
88
# guitest: show
99

10-
from sigima.objects import create_signal_from_param
10+
from sigima.objects import SignalObj, TableKind, TableResult, create_signal_from_param
11+
from sigima.tests.helpers import check_scalar_result
1112
from sigima.tests.signal.pulse_unit_test import (
1213
create_test_square_params,
1314
create_test_step_params,
1415
)
1516

17+
from datalab.adapters_metadata import TableAdapter
1618
from datalab.tests import datalab_test_app_context
1719

1820

21+
def __check_table(obj: SignalObj) -> TableResult:
22+
"""Check that the object has a pulse features table."""
23+
tables = list(TableAdapter.iterate_from_obj(obj))
24+
assert len(tables) == 1
25+
table = tables[0].result
26+
assert table.kind == TableKind.PULSE_FEATURES
27+
return table
28+
29+
1930
def test_pulse_features_app():
2031
"""Pulse features application test."""
2132
with datalab_test_app_context(console=False) as win:
2233
panel = win.signalpanel
34+
35+
# Add first signal and extract features
2336
s1 = create_signal_from_param(create_test_step_params())
2437
panel.add_object(s1)
2538
panel.processor.run_feature("extract_pulse_features")
39+
40+
# Check that features are extracted
41+
table1 = __check_table(s1)
42+
assert table1["signal_shape"][0] == "step"
43+
assert table1["polarity"][0] == 1.0
44+
for name, expected_value in (("amplitude", 4.9), ("rise_time", 1.5)):
45+
check_scalar_result(name, table1[name][0], expected_value, rtol=1e-2)
46+
47+
# Add second signal and extract features
2648
s2 = create_signal_from_param(create_test_square_params())
2749
panel.add_object(s2)
2850
panel.processor.run_feature("extract_pulse_features")
2951

52+
# Check that features are extracted
53+
table2 = __check_table(s2)
54+
assert table2["signal_shape"][0] == "square"
55+
assert table2["polarity"][0] == 1.0
56+
for name, expected_value in (
57+
("amplitude", 4.94),
58+
("rise_time", 1.60),
59+
("fall_time", 3.95),
60+
("fwhm", 5.49),
61+
):
62+
check_scalar_result(name, table2[name][0], expected_value, rtol=1e-2)
63+
3064

3165
if __name__ == "__main__":
3266
test_pulse_features_app()

0 commit comments

Comments
 (0)