TestCenter Reference
Fields.py
Go to the documentation of this file.
2# Copyright 2009, MeVis Medical Solutions AG
3#
4# The user may use this file in accordance with the license agreement provided with
5# the Software or, alternatively, in accordance with the terms contained in a
6# written agreement between the user and MeVis Medical Solutions AG.
7#
8# For further information use the contact form at https://www.mevislab.de/contact
9#
10
11
13
14# ----------------------------------------------------------------------------------------------}}}-
15
16from . import Base
17from . import Logging
18from TestSupport.TestHelper import TestHelper
19from TestSupport.ChangeSet import ChangeSet
20
21# ----------------------------------------------------------------------------------------------}}}-
22
23
24# -- def touch ---------------------------------------------------------------------------------{{{-
25
26def touch(fieldName, verbose=True):
27 TestHelper.getInstance().getChangeSet().setFieldValue(fieldName, None, verbose=verbose)
28
29
30# ----------------------------------------------------------------------------------------------}}}-
31
32
33# -- def setValues -----------------------------------------------------------------------------{{{-
34
39def setValues(fieldValueDict, verbose=True):
40 changeSet = TestHelper.getInstance().getChangeSet()
41 for key in fieldValueDict:
42 changeSet.setFieldValue(key, fieldValueDict[key], verbose=verbose)
43
44
45# --------------------------------------------------------------------------------------------}}}-
46
47
48# -- def varyValues --------------------------------------------------------------------------{{{-
49
57def varyValues(function, funcParams, fieldDict, parentChangeSet=None, verbose=True):
58 if not parentChangeSet:
59 parentChangeSet = TestHelper.getInstance().getChangeSet()
60
61 # No more fields to set, call given function.
62 if len(fieldDict) == 0:
63 function(*funcParams)
64 else:
65 # Create change set for local changes.
66 Base.pushChangeSet()
67
68 fieldName, fieldValues = fieldDict.popitem()
69 field = Base.getTestCaseContext().field(fieldName)
70 # If list of field values is empty use available.
71 if fieldValues == []:
72 # TODO This is only valid for enums. Should find good handling for other
73 # data types or exclude using [] for those.
74 fieldValues = list(field.items())
75
76 changeSet = TestHelper().getInstance().getChangeSet()
77
78 # For each value in the list call the sub dictionary.
79 for fieldValue in fieldValues:
80 changeSet.setFieldValue(fieldName, fieldValue, verbose=verbose)
81 varyValues(function, funcParams, fieldDict, changeSet, verbose)
82
83 Base.popChangeSet()
84
85 fieldDict[fieldName] = fieldValues
86
87
88# ----------------------------------------------------------------------------------------------}}}-
89
90
91# -- def getValue ------------------------------------------------------------------------------{{{-
92
95def getValue(fieldName):
96 field = Base.getTestCaseContext().field(fieldName)
97 if not field:
98 raise Exception("Field (%s) not found in current test's context!" % (fieldName))
99 if field.type in ("String", "Enum"):
100 return field.stringValue()
101 elif field.type == "Bool":
102 return field.boolValue()
103 elif field.type == "Integer":
104 return field.intValue()
105 elif field.type == "Float":
106 return field.floatValue()
107 elif field.type == "Double":
108 return field.doubleValue()
109 elif "Vector6" in field.type:
110 return field.stringValue()
111 elif field.type in ("Vector2", "Vector3", "Vector4", "Plane", "Rotation"):
112 return field.vectorValue()
113 elif field.type in ("Matrix"):
114 return field.matrixValue()
115 elif field.type in ("Color"):
116 return field.colorValue()
117 elif field.type == "Image":
118 return field.image()
119 elif "MLBase" in field.type:
120 return field.object()
121 else:
122 return field.value
123
124
125# ----------------------------------------------------------------------------------------------}}}-
126
127
128# -- def setValue ------------------------------------------------------------------------------{{{-
129
135def setValue(fieldName, fieldValue, verbose=True):
136 TestHelper.getInstance().getChangeSet().setFieldValue(fieldName, fieldValue, verbose=verbose)
137
138
139# ----------------------------------------------------------------------------------------------}}}-
140
141
142# -- def runFieldValueTestCase -----------------------------------------------------------------{{{-
143
150def runFieldValueTestCase(fieldValueTestCaseSet, testCaseName, verbose=True):
151 testCase = fieldValueTestCaseSet.get(testCaseName)
152 testCase.applyParameterization(TestHelper.getInstance().getChangeSet(), verbose=verbose)
153 if not testCase.verifyExpectedResults(verbose=verbose):
154 Logging.error("Failed to verify expected results.", depth=1)
155
156
157# ----------------------------------------------------------------------------------------------}}}-
Singleton for important helper facilities for the different tests.
getValue(fieldName)
Get value of the given field.
Definition Fields.py:95
varyValues(function, funcParams, fieldDict, parentChangeSet=None, verbose=True)
Set field values and for each combination call the given function with the given parameters.
Definition Fields.py:57
setValues(fieldValueDict, verbose=True)
Set field values to the given values.
Definition Fields.py:39
setValue(fieldName, fieldValue, verbose=True)
Set value of the given field.
Definition Fields.py:135
touch(fieldName, verbose=True)
Touch the given field.
Definition Fields.py:26
runFieldValueTestCase(fieldValueTestCaseSet, testCaseName, verbose=True)
Run a field-value test case.
Definition Fields.py:150