Skip to content

Commit

Permalink
test callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 committed Oct 26, 2023
1 parent b8459c3 commit ea137cb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_canape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
import unittest.mock
from pathlib import Path
from typing import Callable, Iterator, List

Expand Down Expand Up @@ -146,6 +147,22 @@ def test_canape(canape_fixture: Callable[[bool], pycanape.CANape], set_channels)
assert Path(canape.get_cna_filename()) == CANAPE_PROJECT / "XCPsimDemo.cna"
canape.load_cna_file(CANAPE_PROJECT / "XCPsimDemo.cna")

data_acq_before_start_callback = unittest.mock.Mock()
canape.register_callback(
event_code=pycanape.EventCode.et_ON_BEFORE_DATA_ACQ_START,
callback_func=data_acq_before_start_callback,
)
data_acq_start_callback = unittest.mock.Mock()
canape.register_callback(
event_code=pycanape.EventCode.et_ON_DATA_ACQ_START,
callback_func=data_acq_start_callback,
)
data_acq_stop_callback = unittest.mock.Mock()
canape.register_callback(
event_code=pycanape.EventCode.et_ON_DATA_ACQ_STOP,
callback_func=data_acq_stop_callback,
)

assert (
canape.get_measurement_state()
is pycanape.MeasurementState.eT_MEASUREMENT_STOPPED
Expand All @@ -160,6 +177,9 @@ def test_canape(canape_fixture: Callable[[bool], pycanape.CANape], set_channels)
canape.get_measurement_state()
is pycanape.MeasurementState.eT_MEASUREMENT_STOPPED
)
assert data_acq_before_start_callback.call_count == 1
assert data_acq_start_callback.call_count == 1
assert data_acq_stop_callback.call_count == 1


@pytest.mark.skipif(not XCPSIM_FOUND, reason="CANape example project not found")
Expand Down

0 comments on commit ea137cb

Please sign in to comment.