mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-28 09:47:20 +02:00
[tests] Rewrite test_nodeCommandLineFormatting
using test nodes
The tests in that file were using AliceVision nodes, which are now out of Meshroom's repository.
This commit is contained in:
parent
cfa33b6442
commit
ee5e9401ce
1 changed files with 158 additions and 60 deletions
|
@ -1,78 +1,176 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding:utf-8
|
# coding:utf-8
|
||||||
import meshroom.multiview
|
|
||||||
from meshroom.core.graph import Graph
|
from meshroom.core.graph import Graph, loadGraph, executeGraph
|
||||||
|
from meshroom.core import desc, registerNodeType, unregisterNodeType
|
||||||
|
from meshroom.core.node import Node
|
||||||
|
|
||||||
|
|
||||||
def test_formatting_listOfFiles():
|
class NodeWithAttributesNeedingFormatting(desc.Node):
|
||||||
meshroom.core.initNodes()
|
"""
|
||||||
|
A node containing list, file, choice and group attributes in order to test the formatting of the command line.
|
||||||
|
"""
|
||||||
|
inputs = [
|
||||||
|
desc.ListAttribute(
|
||||||
|
name="images",
|
||||||
|
label="Images",
|
||||||
|
description="List of images.",
|
||||||
|
elementDesc=desc.File(
|
||||||
|
name="image",
|
||||||
|
label="Image",
|
||||||
|
description="Path to an image.",
|
||||||
|
value="",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
desc.File(
|
||||||
|
name="input",
|
||||||
|
label="Input File",
|
||||||
|
description="An input file.",
|
||||||
|
value="",
|
||||||
|
),
|
||||||
|
desc.ChoiceParam(
|
||||||
|
name="method",
|
||||||
|
label="Method",
|
||||||
|
description="Method to choose from a list of available methods.",
|
||||||
|
value="MethodC",
|
||||||
|
values=["MethodA", "MethodB", "MethodC"],
|
||||||
|
),
|
||||||
|
desc.GroupAttribute(
|
||||||
|
name="firstGroup",
|
||||||
|
label="First Group",
|
||||||
|
description="Group with boolean and integer parameters.",
|
||||||
|
joinChar=":",
|
||||||
|
groupDesc=[
|
||||||
|
desc.BoolParam(
|
||||||
|
name="enableFirstGroup",
|
||||||
|
label="Enable",
|
||||||
|
description="Enable other parameter in the group.",
|
||||||
|
value=False,
|
||||||
|
),
|
||||||
|
desc.IntParam(
|
||||||
|
name="width",
|
||||||
|
label="Width",
|
||||||
|
description="Width setting.",
|
||||||
|
value=3,
|
||||||
|
range=(1, 10, 1),
|
||||||
|
enabled=lambda node: node.firstGroup.enableFirstGroup.value,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
desc.GroupAttribute(
|
||||||
|
name="secondGroup",
|
||||||
|
label="Second Group",
|
||||||
|
description="Group with boolean, choice and float parameters.",
|
||||||
|
joinChar=",",
|
||||||
|
groupDesc=[
|
||||||
|
desc.BoolParam(
|
||||||
|
name="enableSecondGroup",
|
||||||
|
label="Enable",
|
||||||
|
description="Enable other parameters in the group.",
|
||||||
|
value=False,
|
||||||
|
),
|
||||||
|
desc.ChoiceParam(
|
||||||
|
name="groupChoice",
|
||||||
|
label="Grouped Choice",
|
||||||
|
description="Value to choose from a group.",
|
||||||
|
value="second_value",
|
||||||
|
values=["first_value", "second_value", "third_value"],
|
||||||
|
enabled=lambda node: node.secondGroup.enableSecondGroup.value,
|
||||||
|
),
|
||||||
|
desc.FloatParam(
|
||||||
|
name="floatWidth",
|
||||||
|
label="Width",
|
||||||
|
description="Width setting (but with a float).",
|
||||||
|
value=3.0,
|
||||||
|
range=(1.0, 10.0, 0.5),
|
||||||
|
enabled=lambda node: node.secondGroup.enableSecondGroup.value,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
inputImages = ['/non/existing/fileA', '/non/existing/with space/fileB']
|
outputs = [
|
||||||
|
desc.File(
|
||||||
|
name="output",
|
||||||
|
label="Output",
|
||||||
|
description="Output file.",
|
||||||
|
value="{nodeCacheFolder}",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
graph = Graph('')
|
class TestCommandLineFormatting:
|
||||||
n1 = graph.addNewNode('CameraInit')
|
@classmethod
|
||||||
n1.viewpoints.extend([{'path': image} for image in inputImages])
|
def setup_class(cls):
|
||||||
# viewId, poseId, path, intrinsicId, rigId, subPoseId, metadata
|
registerNodeType(NodeWithAttributesNeedingFormatting)
|
||||||
assert n1.viewpoints.getValueStr() == \
|
|
||||||
'-1 -1 "/non/existing/fileA" -1 -1 -1 "" -1 -1 "/non/existing/with space/fileB" -1 -1 -1 ""'
|
|
||||||
|
|
||||||
graph = Graph('')
|
@classmethod
|
||||||
n1 = graph.addNewNode('ImageMatching')
|
def teardown_class(cls):
|
||||||
assert n1.featuresFolders.getValueStr() == ''
|
unregisterNodeType(NodeWithAttributesNeedingFormatting)
|
||||||
|
|
||||||
n1.featuresFolders.extend("single value with space")
|
def test_formatting_listOfFiles(self):
|
||||||
assert n1.featuresFolders.getValueStr() == '"single value with space"'
|
inputImages = ["/non/existing/fileA", "/non/existing/with space/fileB"]
|
||||||
|
|
||||||
n1.featuresFolders.resetToDefaultValue()
|
graph = Graph("")
|
||||||
assert n1.featuresFolders.getValueStr() == ''
|
node = graph.addNewNode("NodeWithAttributesNeedingFormatting")
|
||||||
|
|
||||||
n1.featuresFolders.extend(inputImages)
|
# Assert that an empty list gives an empty string
|
||||||
assert n1.featuresFolders.getValueStr() == '"/non/existing/fileA" "/non/existing/with space/fileB"'
|
assert node.images.getValueStr() == ""
|
||||||
|
|
||||||
n1._buildCmdVars() # prepare vars for command line creation
|
# Assert that values in a list a correctly concatenated
|
||||||
# and check some values
|
node.images.extend([i for i in inputImages])
|
||||||
name = 'featuresFolders'
|
assert node.images.getValueStr() == '"/non/existing/fileA" "/non/existing/with space/fileB"'
|
||||||
assert n1._cmdVars[name + 'Value'] == '/non/existing/fileA /non/existing/with space/fileB'
|
|
||||||
|
|
||||||
|
# Reset list content and add a single value that contains spaces
|
||||||
|
node.images.resetToDefaultValue()
|
||||||
|
assert node.images.getValueStr() == "" # The value has been correctly reset
|
||||||
|
node.images.extend("single value with space")
|
||||||
|
assert node.images.getValueStr() == '"single value with space"'
|
||||||
|
|
||||||
def test_formatting_strings():
|
# Assert that extending values when the list is not empty is working
|
||||||
meshroom.core.initNodes()
|
node.images.extend(inputImages)
|
||||||
|
assert node.images.getValueStr() == '"single value with space" "{}" "{}"'.format(inputImages[0],
|
||||||
|
inputImages[1])
|
||||||
|
|
||||||
graph = Graph('')
|
# Values are not retrieved as strings in the command line, so quotes around them are not expected
|
||||||
n1 = graph.addNewNode('ImageMatching')
|
assert node._cmdVars["imagesValue"] == 'single value with space {} {}'.format(inputImages[0],
|
||||||
name = 'weights'
|
inputImages[1])
|
||||||
assert n1.weights.getValueStr() == '""' # Empty string should generate empty quotes
|
|
||||||
assert n1._cmdVars[name + 'Value'] == ''
|
|
||||||
name = 'method'
|
|
||||||
assert n1.method.getValueStr() == '"SequentialAndVocabularyTree"'
|
|
||||||
assert n1._cmdVars[name + 'Value'] == 'SequentialAndVocabularyTree'
|
|
||||||
|
|
||||||
n2 = graph.addNewNode('ImageMatching')
|
def test_formatting_strings(self):
|
||||||
n2._buildCmdVars() # prepare vars for command line creation
|
graph = Graph("")
|
||||||
name = 'featuresFolders'
|
node = graph.addNewNode("NodeWithAttributesNeedingFormatting")
|
||||||
assert n2._cmdVars[name + 'Value'] == '', 'Empty list should become fully empty'
|
node._buildCmdVars()
|
||||||
n2.featuresFolders.extend('')
|
|
||||||
n2._buildCmdVars() # prepare vars for command line creation
|
|
||||||
assert n2.featuresFolders.getValueStr() == '""', 'A list with one empty string should generate empty quotes'
|
|
||||||
assert n2._cmdVars[name + 'Value'] == '', 'The Value is always only the value, so empty here'
|
|
||||||
n2.featuresFolders.extend('')
|
|
||||||
n2._buildCmdVars() # prepare vars for command line creation
|
|
||||||
assert n2.featuresFolders.getValueStr() == '"" ""', 'A list with 2 empty strings should generate quotes'
|
|
||||||
assert n2._cmdVars[name + 'Value'] == ' ', \
|
|
||||||
'The Value is always only the value, so 2 empty with the space separator in the middle'
|
|
||||||
|
|
||||||
|
# Assert an empty File attribute generates empty quotes when requesting its value as a string
|
||||||
|
assert node.input.getValueStr() == '""'
|
||||||
|
assert node._cmdVars["inputValue"] == ""
|
||||||
|
|
||||||
def test_formatting_groups():
|
# Assert a Choice attribute with a non-empty default value is surrounded with quotes when requested as a string
|
||||||
meshroom.core.initNodes()
|
assert node.method.getValueStr() == '"MethodC"'
|
||||||
|
assert node._cmdVars["methodValue"] == "MethodC"
|
||||||
|
|
||||||
graph = Graph('')
|
# Assert that the empty list is really empty (no quotes)
|
||||||
n3 = graph.addNewNode('ImageProcessing')
|
assert node.images.getValueStr() == ""
|
||||||
n3._buildCmdVars() # prepare vars for command line creation
|
assert node._cmdVars["imagesValue"] == "", "Empty list should become fully empty"
|
||||||
name = 'sharpenFilter'
|
|
||||||
assert n3.sharpenFilter.getValueStr() == '"False:3:1.0:0.0"'
|
# Assert that the list with one empty value generates empty quotes
|
||||||
assert n3._cmdVars[name + 'Value'] == 'False:3:1.0:0.0', 'The Value is always only the value, so no quotes'
|
node.images.extend("")
|
||||||
name = 'fillHoles'
|
assert node.images.getValueStr() == '""', "A list with one empty string should generate empty quotes"
|
||||||
assert n3._cmdVars[name + 'Value'] == 'False', 'Booleans'
|
assert node._cmdVars["imagesValue"] == "", "The value is always only the value, so empty here"
|
||||||
name = 'noiseFilter'
|
|
||||||
assert n3.noiseFilter.getValueStr() == '"False:uniform:0.0:1.0:True"'
|
# Assert that a list with 2 empty strings generates quotes
|
||||||
assert n3._cmdVars[name + 'Value'] == 'False:uniform:0.0:1.0:True'
|
node.images.extend("")
|
||||||
|
assert node.images.getValueStr() == '"" ""', "A list with 2 empty strings should generate quotes"
|
||||||
|
assert node._cmdVars["imagesValue"] == ' ', \
|
||||||
|
"The value is always only the value, so 2 empty strings with the space separator in the middle"
|
||||||
|
|
||||||
|
def test_formatting_groups(self):
|
||||||
|
graph = Graph("")
|
||||||
|
node = graph.addNewNode("NodeWithAttributesNeedingFormatting")
|
||||||
|
node._buildCmdVars()
|
||||||
|
|
||||||
|
assert node.firstGroup.getValueStr() == '"False:3"'
|
||||||
|
assert node._cmdVars["firstGroupValue"] == 'False:3', \
|
||||||
|
"There should be no quotes here as the value is not formatted as a string"
|
||||||
|
|
||||||
|
assert node.secondGroup.getValueStr() == '"False,second_value,3.0"'
|
||||||
|
assert node._cmdVars["secondGroupValue"] == 'False,second_value,3.0'
|
||||||
|
|
Loading…
Add table
Reference in a new issue