Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in case of no cim layout file, no processing #91

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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