Skip to content

Commit

Permalink
Merge pull request #91 from ecmwf-projects/cim_layout_bugfix
Browse files Browse the repository at this point in the history
in case of no cim layout file, no processing
  • Loading branch information
alex75 authored Aug 22, 2023
2 parents 7f207db + 4976dec commit 6ec1583
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
25 changes: 12 additions & 13 deletions cads_catalogue/layout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,20 @@ def transform_cim_blocks(layout_data: dict[str, Any], cim_layout_path: str):
-------
dict: dictionary of layout_data modified
"""
if not os.path.exists(cim_layout_path):
return layout_data
remove_tab = True
remove_aside = True
qa_tab_blocks = None
qa_aside_blocks = None
if os.path.exists(cim_layout_path):
with open(cim_layout_path) as fp:
cim_layout_data = json.load(fp)
qa_tab = cim_layout_data.get("quality_assurance_tab", {})
qa_tab_blocks = qa_tab.get("blocks")
if qa_tab_blocks is not None:
remove_tab = False
qa_aside = cim_layout_data.get("quality_assurance_aside", {})
qa_aside_blocks = qa_aside.get("blocks")
if qa_aside_blocks is not None:
remove_aside = False
with open(cim_layout_path) as fp:
cim_layout_data = json.load(fp)
qa_tab = cim_layout_data.get("quality_assurance_tab", {})
qa_tab_blocks = qa_tab.get("blocks")
if qa_tab_blocks is not None:
remove_tab = False
qa_aside = cim_layout_data.get("quality_assurance_aside", {})
qa_aside_blocks = qa_aside.get("blocks")
if qa_aside_blocks is not None:
remove_aside = False
new_data = copy.deepcopy(layout_data)
body = new_data.get("body", {})
body_main = body.get("main", {})
Expand Down
20 changes: 2 additions & 18 deletions tests/test_30_layout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,7 @@ def test_transform_cim_blocks(tmpdir):
new_layout_data = layout_manager.transform_cim_blocks(
layout_data, cim_layout_path=cim_layout_path
)
assert new_layout_data == {
"uid": "cams-global-reanalysis-eac4",
"body": {
"main": {
"sections": test_sections_1,
},
"aside": test_aside_1,
},
}
assert new_layout_data == layout_data

# test case 3: not existing cim layout, existing only aside block
new_aside_block = {
Expand All @@ -698,15 +690,7 @@ def test_transform_cim_blocks(tmpdir):
new_layout_data = layout_manager.transform_cim_blocks(
layout_data, cim_layout_path=cim_layout_path
)
assert new_layout_data == {
"uid": "cams-global-reanalysis-eac4",
"body": {
"main": {
"sections": test_sections_1,
},
"aside": test_aside_1,
},
}
assert new_layout_data == layout_data

# test case 4: existing cim layout, not existing section/aside on layout
layout_data = create_layout_for_test(
Expand Down

0 comments on commit 6ec1583

Please sign in to comment.