summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-12-26 18:07:45 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-12-26 18:07:45 (GMT)
commit2034340f3bc4fc97cb8d097d7e1a1d810028fb0f (patch)
tree21af07a7748af6d6fab6d4aea9363be5984eeaa3
parent421a32de58afb8932bdee5b3ad95ad2059bf5951 (diff)
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>
-rw-r--r--wasp/boards/simulator/conftest.py25
-rw-r--r--wasp/boards/simulator/test_smoke.py24
2 files changed, 49 insertions, 0 deletions
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'])