Skip to content

Commit

Permalink
Merge pull request #508 from climbfuji/feature/capgen_bugfix_default_…
Browse files Browse the repository at this point in the history
…val_optional_varprop

Bug fix in metavar.py: optional var props with a default value need t…
  • Loading branch information
climbfuji authored Oct 27, 2023
2 parents eac8bb8 + 294eecf commit 0d9b33a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scripts/metavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ class Var:
['Bob', 'Ray']
>>> Var.get_prop('active') #doctest: +ELLIPSIS
<var_props.VariableProperty object at 0x...>
>>> Var.get_prop('active').get_default_val({})
'.true.'
>>> Var.get_prop('active').valid_value('flag_for_aerosol_physics')
'flag_for_aerosol_physics'
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in'}, ParseSource('vname', 'DDT', ParseContext()), _MVAR_DUMMY_RUN_ENV).get_prop_value('active')
'.true.'
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in', 'active' : 'child_is_home==.true.'}, ParseSource('vname', 'DDT', ParseContext()), _MVAR_DUMMY_RUN_ENV).get_prop_value('active')
'child_is_home==.true.'
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in'}, ParseSource('vname', 'SCHEME', ParseContext()), _MVAR_DUMMY_RUN_ENV).get_prop_value('long_name')
'Hi mom'
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in'}, ParseSource('vname', 'SCHEME', ParseContext()), _MVAR_DUMMY_RUN_ENV).get_prop_value('intent')
Expand Down Expand Up @@ -196,7 +202,7 @@ class Var:
VariableProperty('active', str, optional_in=True,
default_in='.true.'),
VariableProperty('polymorphic', bool, optional_in=True,
default_in='.false.')]
default_in=False)]

# XXgoldyXX: v debug only
__to_add = VariableProperty('valid_values', str,
Expand Down Expand Up @@ -496,7 +502,7 @@ def get_prop_value(self, name):
pvalue = self._prop_dict[name]
elif name in Var.__var_propdict:
vprop = Var.__var_propdict[name]
if vprop.has_default_func:
if vprop.optional:
pvalue = vprop.get_default_val(self._prop_dict,
context=self.context)
else:
Expand Down

0 comments on commit 0d9b33a

Please sign in to comment.