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 <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
421a32de58
commit
2034340f3b
2 changed files with 49 additions and 0 deletions
25
wasp/boards/simulator/conftest.py
Normal file
25
wasp/boards/simulator/conftest.py
Normal file
|
@ -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())
|
|
@ -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'])
|
||||
|
||||
|
|
Loading…
Reference in a new issue