@@ -151,26 +151,46 @@ def test_Update(self) -> None:
151
151
assert env ['ANSWER' ] == 54
152
152
153
153
# Test that the value is not substituted if 'subst' is False
154
- def check_subst (key , value , env ) -> None :
154
+ # and that it is if 'subst' is True.
155
+ def check_no_subst (key , value , env ) -> None :
155
156
"""Check that variable was not substituted before we get called."""
156
157
assert value == "$ORIGIN" , \
157
158
f"Validator: '$ORIGIN' was substituted to { value !r} "
158
159
159
- def conv_subst (value ) -> None :
160
+ def conv_no_subst (value ) -> None :
160
161
"""Check that variable was not substituted before we get called."""
161
162
assert value == "$ORIGIN" , \
162
163
f"Converter: '$ORIGIN' was substituted to { value !r} "
163
164
return value
164
165
166
+ def check_subst (key , value , env ) -> None :
167
+ """Check that variable was substituted before we get called."""
168
+ assert value == "Value" , \
169
+ f"Validator: '$SUB' was not substituted { value !r} instead of 'Value'"
170
+
171
+ def conv_subst (value ) -> None :
172
+ """Check that variable was not substituted before we get called."""
173
+ assert value == "Value" , \
174
+ f"Converter: '$SUB' was substituted to { value !r} instead of 'Value'"
175
+ return value
176
+
165
177
opts .Add ('NOSUB' ,
166
178
help = 'Variable whose value will not be substituted' ,
167
179
default = '$ORIGIN' ,
180
+ validator = check_no_subst ,
181
+ converter = conv_no_subst ,
182
+ subst = False )
183
+ opts .Add ('SUB' ,
184
+ help = 'Variable whose value will be substituted' ,
185
+ default = '$VAR' ,
168
186
validator = check_subst ,
169
187
converter = conv_subst ,
170
- subst = False )
188
+ subst = True )
171
189
env = Environment ()
190
+ env ['VAR' ] = "Value"
172
191
opts .Update (env )
173
- assert env ['NOSUB' ] == "$ORIGIN"
192
+ assert env ['NOSUB' ] == "$ORIGIN" , env ['NOSUB' ]
193
+ assert env ['SUB' ] == env ['VAR' ], env ['SUB' ]
174
194
175
195
# Test that a bad value from the file is used and
176
196
# validation fails correctly.
0 commit comments