Fix default variable values having substitutions from the calculus
This commit is contained in:
parent
5716bbefa9
commit
6d3f3e207b
2 changed files with 7 additions and 3 deletions
|
|
@ -494,7 +494,6 @@ def _Substitute( template, mapping ):
|
||||||
if mo.group( 'braceddefault' ) is not None:
|
if mo.group( 'braceddefault' ) is not None:
|
||||||
named = mo.group( 'defname' )
|
named = mo.group( 'defname' )
|
||||||
if named not in mapping:
|
if named not in mapping:
|
||||||
''
|
|
||||||
raise MissingSubstitution(
|
raise MissingSubstitution(
|
||||||
named,
|
named,
|
||||||
mo.group( 'default' ).replace( '\\}', '}' ) )
|
mo.group( 'default' ).replace( '\\}', '}' ) )
|
||||||
|
|
@ -536,8 +535,11 @@ def ExpandReferencesInString( orig_s,
|
||||||
if default_value is None and e.default_value is not None:
|
if default_value is None and e.default_value is not None:
|
||||||
try:
|
try:
|
||||||
default_value = _Substitute( e.default_value, mapping )
|
default_value = _Substitute( e.default_value, mapping )
|
||||||
except MissingSubstitution:
|
except MissingSubstitution as e2:
|
||||||
default_value = e.default_value
|
if e2.name in calculus:
|
||||||
|
default_value = calculus[ e2.name ]()
|
||||||
|
else:
|
||||||
|
default_value = e.default_value
|
||||||
|
|
||||||
mapping[ key ] = AskForInput( 'Enter value for {}: '.format( key ),
|
mapping[ key ] = AskForInput( 'Enter value for {}: '.format( key ),
|
||||||
default_value )
|
default_value )
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class TestExpandReferencesInDict( unittest.TestCase ):
|
||||||
'one': '${one}',
|
'one': '${one}',
|
||||||
'two': '${one} and ${two}',
|
'two': '${one} and ${two}',
|
||||||
'three': '${three}',
|
'three': '${three}',
|
||||||
|
'three_with_default': '${three_with_default:${three\\}}', # uses calculus
|
||||||
'four': '${four}',
|
'four': '${four}',
|
||||||
'five': '${five}',
|
'five': '${five}',
|
||||||
'list': [ '*${words}' ],
|
'list': [ '*${words}' ],
|
||||||
|
|
@ -58,6 +59,7 @@ class TestExpandReferencesInDict( unittest.TestCase ):
|
||||||
'one': 'one',
|
'one': 'one',
|
||||||
'two': 'one and TWO',
|
'two': 'one and TWO',
|
||||||
'three': '3',
|
'three': '3',
|
||||||
|
'three_with_default': '3',
|
||||||
'four': 'typed text',
|
'four': 'typed text',
|
||||||
'five': '5ive!',
|
'five': '5ive!',
|
||||||
'list': [ 'these', 'are', 'some', 'words' ],
|
'list': [ 'these', 'are', 'some', 'words' ],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue