From 752b63054d38cdb3803a9c9a12e3506d24a54c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Mon, 17 Mar 2025 16:49:42 +0100 Subject: [PATCH] [tests] Update `test_multiviewPipeline` with test nodes and template `test_multiviewPipeline` relied on the photogrammetry template and its nodes, which are not a part of Meshroom anymore. The test is rewritten to check the same items (serialization, graph equality, etc.) but using dedicated test nodes (which already existed) and template, which is added with this commit. The path of the template is added to `MESHROOM_PIPELINE_TEMPLATES_PATH` when loading the test module. --- tests/__init__.py | 6 +- tests/appendTextAndFiles.mg | 43 +++++++++++ tests/test_multiviewPipeline.py | 125 -------------------------------- tests/test_pipeline.py | 79 ++++++++++++++++++++ 4 files changed, 127 insertions(+), 126 deletions(-) create mode 100644 tests/appendTextAndFiles.mg delete mode 100644 tests/test_multiviewPipeline.py create mode 100644 tests/test_pipeline.py diff --git a/tests/__init__.py b/tests/__init__.py index 1760a896..8a6bd273 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,9 @@ import os -from meshroom.core import loadAllNodes +from meshroom.core import loadAllNodes, initPipelines loadAllNodes(os.path.join(os.path.dirname(__file__), "nodes")) +if os.getenv("MESHROOM_PIPELINE_TEMPLATES_PATH", False): + os.environ["MESHROOM_PIPELINE_TEMPLATES_PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__)) +else: + os.environ["MESHROOM_PIPELINE_TEMPLATES_PATH"] = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/appendTextAndFiles.mg b/tests/appendTextAndFiles.mg new file mode 100644 index 00000000..bbce48eb --- /dev/null +++ b/tests/appendTextAndFiles.mg @@ -0,0 +1,43 @@ +{ + "header": { + "releaseVersion": "2025.1.0-develop", + "fileVersion": "2.0", + "nodesVersions": {}, + "template": true + }, + "graph": { + "AppendFiles_1": { + "nodeType": "AppendFiles", + "position": [ + 189, + 8 + ], + "inputs": { + "input": "{AppendText_1.output}", + "input2": "{AppendText_2.output}", + "input3": "{AppendText_1.input}", + "input4": "{AppendText_2.input}" + } + }, + "AppendText_1": { + "nodeType": "AppendText", + "position": [ + 0, + 0 + ], + "inputs": { + "inputText": "Input text from AppendText_1" + } + }, + "AppendText_2": { + "nodeType": "AppendText", + "position": [ + 0, + 160 + ], + "inputs": { + "inputText": "Input text from AppendText_2" + } + } + } +} \ No newline at end of file diff --git a/tests/test_multiviewPipeline.py b/tests/test_multiviewPipeline.py deleted file mode 100644 index 0f10e578..00000000 --- a/tests/test_multiviewPipeline.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python -# coding:utf-8 -import os -import tempfile - -import meshroom.multiview -from meshroom.core.graph import loadGraph -from meshroom.core.node import Node - - -def test_multiviewPipeline(): - meshroom.core.initNodes() - meshroom.core.initPipelines() - - graph1InputImages = ['/non/existing/fileA'] - graph1 = loadGraph(meshroom.core.pipelineTemplates["photogrammetry"]) - graph1.name = "graph1" - graph1CameraInit = graph1.node("CameraInit_1") - graph1CameraInit.viewpoints.extend([{'path': image} for image in graph1InputImages]) - - graph2InputImages = [] # common to graph2 and graph2b - graph2 = loadGraph(meshroom.core.pipelineTemplates["photogrammetry"]) - graph2.name = "graph2" - graph2CameraInit = graph2.node("CameraInit_1") - graph2CameraInit.viewpoints.extend([{'path': image} for image in graph2InputImages]) - graph2b = loadGraph(meshroom.core.pipelineTemplates["photogrammetry"]) - graph2bCameraInit = graph2b.node("CameraInit_1") - graph2bCameraInit.viewpoints.extend([{'path': image} for image in graph2InputImages]) - - graph3InputImages = ['/non/existing/file1', '/non/existing/file2'] - graph3 = loadGraph(meshroom.core.pipelineTemplates["photogrammetry"]) - graph3.name = "graph3" - graph3CameraInit = graph3.node("CameraInit_1") - graph3CameraInit.viewpoints.extend([{'path': image} for image in graph3InputImages]) - - graph4InputViewpoints = [ - {'path': '/non/existing/file1', 'intrinsicId': 50}, - {'path': '/non/existing/file2', 'intrinsicId': 55} - ] # common to graph4 and graph4b - graph4 = loadGraph(meshroom.core.pipelineTemplates["photogrammetry"]) - graph4.name = "graph4" - graph4CameraInit = graph4.node("CameraInit_1") - graph4CameraInit.viewpoints.extend(graph4InputViewpoints) - graph4b = loadGraph(meshroom.core.pipelineTemplates["photogrammetry"]) - graph4b.name = "graph4b" - graph4bCameraInit = graph4b.node("CameraInit_1") - graph4bCameraInit.viewpoints.extend(graph4InputViewpoints) - - assert graph1.findNode('CameraInit').viewpoints.at(0).path.value == '/non/existing/fileA' - assert len(graph2.findNode('CameraInit').viewpoints) == 0 - assert graph3.findNode('CameraInit').viewpoints.at(0).path.value == '/non/existing/file1' - assert graph4.findNode('CameraInit').viewpoints.at(0).path.value == '/non/existing/file1' - - assert len(graph1.findNode('CameraInit').viewpoints) == 1 - assert len(graph2.findNode('CameraInit').viewpoints) == 0 - assert len(graph3.findNode('CameraInit').viewpoints) == 2 - assert len(graph4.findNode('CameraInit').viewpoints) == 2 - - viewpoints = graph3.findNode('CameraInit').viewpoints - assert viewpoints.at(0).path.value == '/non/existing/file1' - - assert viewpoints.at(0).path.value == '/non/existing/file1' - assert viewpoints.at(0).intrinsicId.value == -1 - assert viewpoints.at(1).path.value == '/non/existing/file2' - assert viewpoints.at(1).intrinsicId.value == -1 - - assert not viewpoints.at(0).path.isDefault - assert viewpoints.at(0).intrinsicId.isDefault - assert viewpoints.getPrimitiveValue(exportDefault=False) == [ - {"path": '/non/existing/file1'}, - {"path": '/non/existing/file2'}, - ] - - for graph in (graph4, graph4b): - viewpoints = graph.findNode('CameraInit').viewpoints - assert viewpoints.at(0).path.value == '/non/existing/file1' - assert viewpoints.at(0).intrinsicId.value == 50 - assert viewpoints.at(1).path.value == '/non/existing/file2' - assert viewpoints.at(1).intrinsicId.value == 55 - - # Ensure that all output UIDs are different as the input is different: - # graph1 != graph2 != graph3 != graph4 - for otherGraph in (graph2, graph3, graph4): - for node in graph1.nodes: - otherNode = otherGraph.node(node.name) - for key, attr in node.attributes.items(): - if attr.isOutput and attr.enabled: - otherAttr = otherNode.attribute(key) - assert attr.uid() != otherAttr.uid() - - # graph2 == graph2b - nodes, edges = graph2.dfsOnFinish() - for node in nodes: - otherNode = graph2b.node(node.name) - for key, attr in node.attributes.items(): - otherAttr = otherNode.attribute(key) - if attr.isOutput and attr.enabled: - assert attr.uid() == otherAttr.uid() - else: - assert attr.uid() == otherAttr.uid() - - # graph4 == graph4b - nodes, edges = graph4.dfsOnFinish() - for node in nodes: - otherNode = graph4b.node(node.name) - for key, attr in node.attributes.items(): - otherAttr = otherNode.attribute(key) - if attr.isOutput and attr.enabled: - assert attr.uid() == otherAttr.uid() - else: - assert attr.uid() == otherAttr.uid() - - # test serialization/deserialization - for graph in [graph1, graph2, graph3, graph4]: - filename = tempfile.mktemp() - graph.save(filename) - loadedGraph = loadGraph(filename) - os.remove(filename) - # check that all nodes have been properly de-serialized - # - same node set - assert sorted([n.name for n in loadedGraph.nodes]) == sorted([n.name for n in graph.nodes]) - # - no compatibility issues - assert all(isinstance(n, Node) for n in loadedGraph.nodes) - # - same UIDs for every node - assert sorted([n._uid for n in loadedGraph.nodes]) == sorted([n._uid for n in graph.nodes]) diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py new file mode 100644 index 00000000..a536a043 --- /dev/null +++ b/tests/test_pipeline.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# coding:utf-8 +import os +import tempfile + +import meshroom.multiview +from meshroom.core.graph import loadGraph +from meshroom.core.node import Node + + +def test_pipeline(): + meshroom.core.initNodes() + meshroom.core.initPipelines() + + graph1InputFiles = ["/non/existing/file1", "/non/existing/file2"] + graph1 = loadGraph(meshroom.core.pipelineTemplates["appendTextAndFiles"]) + graph1.name = "graph1" + graph1AppendText1 = graph1.node("AppendText_1") + graph1AppendText1.input.value = graph1InputFiles[0] + graph1AppendText2 = graph1.node("AppendText_2") + graph1AppendText2.input.value = graph1InputFiles[1] + + assert graph1.findNode("AppendFiles").input.value == graph1AppendText1.output.value + assert graph1.findNode("AppendFiles").input2.value == graph1AppendText2.output.value + assert graph1.findNode("AppendFiles").input3.value == graph1InputFiles[0] + assert graph1.findNode("AppendFiles").input4.value == graph1InputFiles[1] + + assert not graph1AppendText1.input.isDefault + assert graph1AppendText2.input.getPrimitiveValue() == graph1InputFiles[1] + + graph2InputFiles = ["/non/existing/file", ""] + graph2 = loadGraph(meshroom.core.pipelineTemplates["appendTextAndFiles"]) + graph2.name = "graph2" + graph2AppendText1 = graph2.node("AppendText_1") + graph2AppendText1.input.value = graph2InputFiles[0] + graph2AppendText2 = graph2.node("AppendText_2") + graph2AppendText2.input.value = graph2InputFiles[1] + + # Ensure that all output UIDs are different as the input is different: + # graph1 != graph2 + for node in graph1.nodes: + otherNode = graph2.node(node.name) + for key, attr in node.attributes.items(): + if attr.isOutput and attr.enabled: + otherAttr = otherNode.attribute(key) + assert attr.uid() != otherAttr.uid() + + # Test serialization/deserialization on both graphs + for graph in [graph1, graph2]: + filename = tempfile.mktemp() + graph.save(filename) + loadedGraph = loadGraph(filename) + os.remove(filename) + # Check that all nodes have been properly de-serialized + # - Same node set + assert sorted([n.name for n in loadedGraph.nodes]) == sorted([n.name for n in graph.nodes]) + # - No compatibility issues + assert all(isinstance(n, Node) for n in loadedGraph.nodes) + # - Same UIDs for every node + assert sorted([n._uid for n in loadedGraph.nodes]) == sorted([n._uid for n in graph.nodes]) + + # Graph 2b, set with identical parameters as graph 2 + graph2b = loadGraph(meshroom.core.pipelineTemplates["appendTextAndFiles"]) + graph2b.name = "graph2b" + graph2bAppendText1 = graph2b.node("AppendText_1") + graph2bAppendText1.input.value = graph2InputFiles[0] + graph2bAppendText2 = graph2b.node("AppendText_2") + graph2bAppendText2.input.value = graph2InputFiles[1] + + # Ensure that graph2 == graph2b + nodes, edges = graph2.dfsOnFinish() + for node in nodes: + otherNode = graph2b.node(node.name) + for key, attr in node.attributes.items(): + otherAttr = otherNode.attribute(key) + if attr.isOutput and attr.enabled: + assert attr.uid() == otherAttr.uid() + else: + assert attr.uid() == otherAttr.uid()