diff --git a/old_nodes/__init__.py b/old_nodes/__init__.py index aeb0ce3eb3..cfb985a510 100644 --- a/old_nodes/__init__.py +++ b/old_nodes/__init__.py @@ -106,17 +106,22 @@ def has_old_nodes(tree) -> bool: def register_old(bl_id): """Register old node class""" - if bl_id in old_bl_idnames: - mod = importlib.import_module(".{}".format(old_bl_idnames[bl_id]), __name__) - res = inspect.getmembers(mod) - for name, cls in res: - if inspect.isclass(cls): - if issubclass(cls, bpy.types.Node) and cls.bl_idname == bl_id: - if bl_id not in imported_mods: - mod.register() - imported_mods[bl_id] = mod - else: + if bl_id in imported_mods: + return + if bl_id not in old_bl_idnames: raise LookupError(f"Cannot find {bl_id} among old nodes") + mod = importlib.import_module(".{}".format(old_bl_idnames[bl_id]), __name__) + res = inspect.getmembers(mod) + module_node_bl_idnames = set() # there can be multiple of them + for name, cls in res: + if inspect.isclass(cls): + if issubclass(cls, bpy.types.Node): + module_node_bl_idnames.add(cls.bl_idname) + if bl_id not in module_node_bl_idnames: + raise LookupError(f"Old_bl_idnames returns something wrong for {bl_id=}") + mod.register() + for bl_idname in module_node_bl_idnames: + imported_mods[bl_idname] = mod def register_all(): diff --git a/tests/group_tests.py b/tests/group_tests.py index 1d37078704..9d9a97c533 100644 --- a/tests/group_tests.py +++ b/tests/group_tests.py @@ -24,7 +24,7 @@ def test_grouping_nodes(self): importer.import_into_tree(new_tree, print_log=False) [setattr(n, 'select', False) for n in new_tree.nodes] [setattr(new_tree.nodes[n], 'select', True) for n in ['A Number', 'Formula', - 'Vector polar input', 'Vector polar output']] + 'Vector Polar Input', 'Vector Polar Output']] with self.subTest(msg="Grouping nodes"): bpy.ops.node.add_group_tree_from_selected() with self.subTest(msg="Ungrouping nodes"): diff --git a/ui/testing_panel.py b/ui/testing_panel.py index 084109c255..f9c6ea1357 100644 --- a/ui/testing_panel.py +++ b/ui/testing_panel.py @@ -37,7 +37,7 @@ def execute(self, context): # making self.report after all tests lead to strange error, so no report for testing all test.run_all_tests() else: - test_result = test.run_test_from_file(self.test_module + '.py') + test_result = test.run_all_tests(self.test_module + '.py') self.report(type={'ERROR'} if test_result != 'OK' else {'INFO'}, message=test_result) return {'FINISHED'} diff --git a/utils/sv_json_struct.py b/utils/sv_json_struct.py index 3df84baae3..8deab77645 100644 --- a/utils/sv_json_struct.py +++ b/utils/sv_json_struct.py @@ -648,19 +648,21 @@ def build(self, node, factories: StructFactory, imported_data: OldNewNames): # it will cause replacing of all sockets with wrong identifiers in the group node. # clearing and adding sockets of Group input and Group output nodes # immediately cause their rebuilding by Blender, so JSON file does not save information about their sockets. - if node.bl_idname not in {'NodeGroupInput', 'NodeGroupOutput'}: + build_in_id_names = { + 'NodeGroupInput', 'NodeGroupOutput', 'NodeFrame', 'NodeReroute'} + if node.bl_idname not in build_in_id_names: node.inputs.clear() - for sock_identifier, raw_struct in self._struct.get("inputs", dict()).items(): - with self.logger.add_fail("Add in socket", - f"Tree: {node.id_data.name}, Node {node.name}, Sock: {sock_identifier}"): - factories.sock(sock_identifier, self.logger, raw_struct).build(node.inputs, factories, imported_data) + for sock_identifier, raw_struct in self._struct.get("inputs", dict()).items(): + with self.logger.add_fail("Add in socket", + f"Tree: {node.id_data.name}, Node {node.name}, Sock: {sock_identifier}"): + factories.sock(sock_identifier, self.logger, raw_struct).build(node.inputs, factories, imported_data) - if node.bl_idname not in {'NodeGroupInput', 'NodeGroupOutput'}: + if node.bl_idname not in build_in_id_names: node.outputs.clear() - for sock_identifier, raw_struct in self._struct.get("outputs", dict()).items(): - with self.logger.add_fail("Add out socket", - f"Tree: {node.id_data.name}, Node {node.name}, Sock: {sock_identifier}"): - factories.sock(sock_identifier, self.logger, raw_struct).build(node.outputs, factories, imported_data) + for sock_identifier, raw_struct in self._struct.get("outputs", dict()).items(): + with self.logger.add_fail("Add out socket", + f"Tree: {node.id_data.name}, Node {node.name}, Sock: {sock_identifier}"): + factories.sock(sock_identifier, self.logger, raw_struct).build(node.outputs, factories, imported_data) if hasattr(node, 'load_from_json'): with self.logger.add_fail("Setting advance node properties",