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):
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:
#+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
--- /dev/null
+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)