NCAR / ccpp-framework

Common Community Physics Package (CCPP)
http://www.dtcenter.org/community-code/common-community-physics-package-ccpp/
Other
26 stars 63 forks source link

feature/capgen: var.get_prop_value is not returning the correct value for optional variable properties are not #509

Closed climbfuji closed 9 months ago

climbfuji commented 9 months ago

Description

When querying the value of an optional property from a variable that is set for the variable (therefore assuming the default function or value) and that has a default value (not a default function, these are mutually exclusive), the code returns None instead of the default value. An example is the active attribute, where the default value is .true..

Steps to Reproduce

I've added doctests for this to scripts/metavar.py in PR https://github.com/NCAR/ccpp-framework/pull/508. If you remove the bug fix in (old code) line 499 / (new code) line 505, the doctests fail (cd scripts && python3 -m doctest metavar.py).

Additional Context

n/a

Output

Without the bug fix in line 409 / 505:

$ python3 -m doctest  metavar.py
**********************************************************************
File "/Users/heinzell/work/ccpp-framework/ccpp-framework-feature-capgen-fix-optional-varprop-default-val/scripts/metavar.py", line 123, in metavar.Var
Failed example:
    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')
Expected:
    '.true.'
Got nothing
**********************************************************************
1 items had failures:
   1 of  25 in metavar.Var
***Test Failed*** 1 failures.
climbfuji commented 9 months ago

Close via https://github.com/NCAR/ccpp-framework/pull/508