[tests] Simplify registration/unregistration of nodes in tests

Add two methods that are local to tests, `registerNodeDesc` and
`unregisterNodeDesc`, which handle the registration and unregistration
of `NodePlugins` from a node description. This reduces the amount of
code in tests whenever `NodePlugin` need to be instantiated prior
to their registration and so on.
This commit is contained in:
Candice Bentéjac 2025-06-04 21:18:16 +02:00
parent 424abbff82
commit 3c57afb4d0
8 changed files with 76 additions and 77 deletions

View file

@ -3,7 +3,7 @@ from unittest.mock import patch
import meshroom
from meshroom.core import desc, pluginManager
from meshroom.core.plugins import NodePlugin
from meshroom.core.plugins import NodePlugin, NodePluginStatus
@contextmanager
def registeredNodeTypes(nodeTypes: list[desc.Node]):
@ -28,3 +28,16 @@ def overrideNodeTypeVersion(nodeType: desc.Node, version: str):
side_effect=lambda type: version if type is nodeType else unpatchedFunc(type),
):
yield
def registerNodeDesc(nodeDesc: desc.Node):
name = nodeDesc.__name__
if not pluginManager.isRegistered(name):
pluginManager._nodePlugins[name] = NodePlugin(nodeDesc)
pluginManager._nodePlugins[name].status = NodePluginStatus.LOADED
def unregisterNodeDesc(nodeDesc: desc.Node):
name = nodeDesc.__name__
if pluginManager.isRegistered(name):
plugin = pluginManager.getRegisteredNodePlugin(name)
plugin.status = NodePluginStatus.NOT_LOADED
del pluginManager._nodePlugins[name]