diff --git a/tests/pytest/README.md b/tests/pytest/README.md new file mode 100644 index 00000000..27ba1675 --- /dev/null +++ b/tests/pytest/README.md @@ -0,0 +1,8 @@ +# Run Tests + +`make check` on cmake builds will invoke pytest correctly. During development, +it might be useful to run an individual test (instead of everything). To do so, + +``` +PYTHONPATH=../../build/python/ python3 -m pytest -vv -s test_events.py::test_event_input +``` diff --git a/tests/pytest/test_status.py b/tests/pytest/test_status.py new file mode 100644 index 00000000..3a8178cb --- /dev/null +++ b/tests/pytest/test_status.py @@ -0,0 +1,68 @@ +# +# Copyright (c) 2023 Siddharth Chandrasekaran +# +# SPDX-License-Identifier: Apache-2.0 +# + +import time +import pytest + +from testlib import * + +pd_cap = PDCapabilities([ + (Capability.OutputControl, 1, 1), + (Capability.LEDControl, 1, 1), + (Capability.AudibleControl, 1, 1), + (Capability.TextOutput, 1, 1), +]) + +pd_info = [ + PDInfo(101, scbk=KeyStore.gen_key(), name='chn-0'), +] + +# TODO remove this. +pd_addr = pd_info[0].address +pd = PeripheralDevice(pd_info[0], pd_cap, log_level=LogLevel.Debug) +cp = ControlPanel(pd_info) + +@pytest.fixture(scope='module', autouse=True) +def setup_test(): + pd.start() + cp.start() + cp.sc_wait_all() + yield + teardown_test() + +def teardown_test(): + cp.teardown() + pd.teardown() + +def test_cp_status(): + assert cp.online_wait(pd.address) + pd.stop() + assert cp.online_wait(pd.address) == False + pd.start() + assert cp.online_wait(pd.address) + +def test_cp_sc_status(): + assert cp.sc_wait(pd.address) + pd.stop() + assert cp.sc_wait(pd.address) == False + pd.start() + assert cp.sc_wait(pd.address) + +def test_pd_status(): + cp.stop() + time.sleep(1) + assert pd.is_online() == False + cp.start() + assert cp.sc_wait(pd.address) + assert pd.is_online() + +def test_pd_sc_status(): + cp.stop() + time.sleep(1) + assert pd.is_sc_active() == False + cp.start() + assert cp.sc_wait(pd.address) + assert pd.is_sc_active()