From 2034340f3bc4fc97cb8d097d7e1a1d810028fb0f Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 26 Dec 2020 18:07:45 +0000 Subject: [PATCH] tests: Auto-discover applications and try to switch to them Currently `make check` doesn't test any not-default applications. Fix this by automatically discovering constructors and ensure that the application can be started and stopped without generating an exception. Signed-off-by: Daniel Thompson --- wasp/boards/simulator/conftest.py | 25 +++++++++++++++++++++++++ wasp/boards/simulator/test_smoke.py | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 wasp/boards/simulator/conftest.py diff --git a/wasp/boards/simulator/conftest.py b/wasp/boards/simulator/conftest.py new file mode 100644 index 0000000..ffd2344 --- /dev/null +++ b/wasp/boards/simulator/conftest.py @@ -0,0 +1,25 @@ +import glob +import importlib +import inspect +import pytest + +def discover_app_constructors(): + apps = [] + + globs = glob.glob('wasp/apps/*.py') + names = [ g[5:-3].replace('/', '.') for g in globs ] + modules = [ importlib.import_module(n) for n in names ] + + for m in modules: + for sym in m.__dict__.keys(): + if len(sym) > 3 and sym[-3:] == 'App': + constructor = m.__dict__[sym] + sig = inspect.signature(constructor) + if len(sig.parameters) == 0: + apps.append(constructor) + + return apps + +def pytest_generate_tests(metafunc): + if 'constructor' in metafunc.fixturenames: + metafunc.parametrize('constructor', discover_app_constructors()) diff --git a/wasp/boards/simulator/test_smoke.py b/wasp/boards/simulator/test_smoke.py index 4d8307b..26e4318 100644 --- a/wasp/boards/simulator/test_smoke.py +++ b/wasp/boards/simulator/test_smoke.py @@ -48,6 +48,30 @@ def test_app(system, name): system.step() system.switch(system.quick_ring[0]) +def test_constructor(system, constructor): + # Special case for the notification app + if 'NotificationApp' in str(constructor): + wasp.system.notify(wasp.watch.rtc.get_uptime_ms(), + { + "src":"testcase", + "title":"A test", + "body":"This is a long message containingaverylongwordthatdoesnotfit and lots of other contents as well." + }) + + try: + system.switch(constructor()) + system.step() + system.step() + wasp.watch.touch.press(120, 120) + system.step() + system.step() + system.switch(system.quick_ring[0]) + except FileNotFoundError: + # Some apps intend to generate exceptions during the constructor + # if they don't have required files available + if 'HaikuApp' not in str(constructor): + raise + def test_stopwatch(system): system.switch(system.apps['Timer'])