ya2 · news · projects · code · about

more asserts
authorFlavio Calva <f.calva@gmail.com>
Mon, 18 Jul 2022 18:41:04 +0000 (19:41 +0100)
committerFlavio Calva <f.calva@gmail.com>
Mon, 18 Jul 2022 18:41:04 +0000 (19:41 +0100)
pmachines/app.py
prj.org
ya2/p3d/asserts.py [new file with mode: 0644]

index a5f964dd9df54d338aacbe4475fc474eab0e8809..8adb7659f98aa48eaf81f3bcfaebe58a2332fa3b 100755 (executable)
@@ -31,6 +31,8 @@ from ya2.p3d.p3d import LibP3d
 from ya2.utils.lang import LangMgr
 from ya2.utils.log import LogMgr
 from ya2.utils.functional import FunctionalTest
+from ya2.p3d.asserts import assert_threads, assert_tasks, assert_render3d, \
+    assert_render2d, assert_aspect2d, assert_events, assert_buffers
 
 
 class MainFsm(FSM):
@@ -44,12 +46,25 @@ class MainFsm(FSM):
 
     def exitMenu(self):
         self._pmachines.on_menu_exit()
+        self.__do_asserts()
 
     def enterScene(self, cls):
         self._pmachines.on_scene_enter(cls)
 
     def exitScene(self):
         self._pmachines.on_scene_exit()
+        self.__do_asserts()
+
+    def __do_asserts(self):
+        args = self._pmachines._args
+        if args.functional_test or args.functional_ref:
+            assert_threads()
+            assert_tasks()
+            assert_render3d()
+            assert_render2d()
+            assert_aspect2d()
+            assert_events()
+            assert_buffers()
 
 
 class PmachinesApp:
diff --git a/prj.org b/prj.org
index 85082cd7358019a2cf58af2dcdb6ba2e8ba15b2f..9c1366c5c33bc2f0d8d9fbf8f554c743290cf82e 100644 (file)
--- a/prj.org
+++ b/prj.org
@@ -3,15 +3,7 @@
 #+CATEGORY: pmachines
 #+TAGS: bug(b) calendar(c) waiting(w)
 
-* CODE functional tests for "cleaning" i.e. at the end of the states verify:
-- [ ] active threads
-- [ ] active tasks
-- [ ] current nodepaths (render3d)
-- [ ] current nodepaths (render2d)
-- [ ] current nodepaths (render3d)
-- [ ] current accepting events
-- [ ] current buffers
-* READY drag and drop positions in the scene files as empty nodes
+* CODE drag and drop positions in the scene files as empty nodes
 * READY refactoring (recurring task)
 * BACKLOG intro animation (from target item to start position)
 * BACKLOG buttons of the scenes enabled sequentially
diff --git a/ya2/p3d/asserts.py b/ya2/p3d/asserts.py
new file mode 100644 (file)
index 0000000..b450f51
--- /dev/null
@@ -0,0 +1,58 @@
+from logging import info, debug
+import threading
+
+
+def assert_render3d():
+    for child in render.children:
+        if child.name != 'camera':
+            raise Exception()
+
+def assert_aspect2d():
+    for child in aspect2d.children:
+        preserve = [
+            'a2dBackground', 'a2dTopCenter', 'a2dTopCenterNS',
+            'a2dBottomCenter', 'a2dBottomCenterNS', 'a2dLeftCenter',
+            'a2dLeftCenterNS', 'a2dRightCenter', 'a2dRightCenterNS',
+            'a2dTopLeft', 'a2dTopLeftNS', 'a2dTopRight',
+            'a2dTopRightNS', 'a2dBottomLeft', 'a2dBottomLeftNS',
+            'a2dBottomRight', 'a2dBottomRightNS']
+        if child.name not in preserve and not child.has_python_tag('preserve'):
+            raise Exception()
+
+def assert_render2d():
+    for child in render2d.children:
+        preserve = ['aspect2d', 'pixel2d', 'camera2d']
+        if child.name not in preserve and not child.has_python_tag('preserve'):
+            raise Exception()
+
+def assert_events():
+    preserve = ['window-event', 'window-closed', 'async_loader_0',
+                'render-texture-targets-changed', 'aspectRatioChanged']
+    for evt in messenger.getEvents():
+        if evt not in preserve:
+            msg = 'unexpected event: %s' % evt
+            raise Exception(msg)
+
+def assert_tasks():
+    preserve = [
+        'ivalLoop', 'garbageCollectStates', 'collisionLoop',
+        'igLoop', 'audioLoop', 'resetPrevTransform', 'dataLoop',
+        'eventManager', 'simplepbr update', 'on frame music']
+    for task in taskMgr.getTasks() + taskMgr.getDoLaters():
+        if task.name not in preserve and not hasattr(task, 'preserve'):
+            msg = 'unexpected task: %s' % task.name
+            raise Exception(msg)
+
+def assert_buffers():
+    pass
+    #for buffer in RenderToTexture.buffers:
+    #    raise Error()
+
+
+def assert_threads():
+    thr_names = [thread.name for thread in threading.enumerate()]
+    preserve = ['MainThread']
+    for thr_name in thr_names:
+        if thr_name not in preserve:
+            msg = 'unexpected thread: %s' % thr_name
+            raise Exception(msg)