Skip to content

Commit

Permalink
Fix bug in using eval with templates not at top level
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Apr 5, 2024
1 parent faa88a2 commit a6699fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion galsim/config/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def ProcessAllTemplates(config, logger=None, base=None):
"""
if base is None: base = config
ProcessTemplate(config, base, logger)
for (key, field) in config.items():
for (key, field) in list(config.items()):
if isinstance(field, dict):
ProcessAllTemplates(field, logger, base)
elif isinstance(field, list):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_config_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,21 @@ def test_template():
config8['psf']['items'][2] = config4['image']['noise']
assert config9 == config8

# Make sure evals work correltly for template string when not at top level.
# (This used to give an error about the config dict changing size during iteration.)
config10 = {
"eval_variables" : {
"iabc": 123,
"ddict": {
"template": "$os.path.join('config_input','dict.yaml')"
}
}
}
galsim.config.ProcessAllTemplates(config10)
assert config10['eval_variables']['ddict']['b'] == False
assert config10['eval_variables']['ddict']['s'] == "Brian"
assert config10['eval_variables']['ddict']['noise']['models'][0]['variance'] == 0.12


@timer
def test_variable_cat_size():
Expand Down

0 comments on commit a6699fc

Please sign in to comment.