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'])