Skip to content

Commit

Permalink
fix double yielding of results
Browse files Browse the repository at this point in the history
  • Loading branch information
jsheunis committed Sep 1, 2023
1 parent ae17248 commit 4c173ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
25 changes: 13 additions & 12 deletions datalad_catalog/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,19 @@ def __call__(
message=success_msg,
home=success_home_spec,
)
# if home already set and no reckless mode, yield impossible
msg = (
f"Home page already set: dataset_id={home_spec[cnst.DATASET_ID]}, "
f"dataset_version={home_spec[cnst.DATASET_VERSION]}."
"To overwrite this property, use '--reckless overwrite'"
)
yield get_status_dict(
**res_kwargs,
status="impossible",
message=msg,
home=home_spec,
)
else:
# if home already set and no reckless mode, yield impossible
msg = (
f"Home page already set: dataset_id={home_spec[cnst.DATASET_ID]}, "
f"dataset_version={home_spec[cnst.DATASET_VERSION]}."
"To overwrite this property, use '--reckless overwrite'"
)
yield get_status_dict(
**res_kwargs,
status="impossible",
message=msg,
home=home_spec,
)
except FileNotFoundError:
# if home not set, set it
catalog.set_main_dataset(dataset_id, dataset_version)
Expand Down
19 changes: 19 additions & 0 deletions datalad_catalog/tests/test_set.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datalad.tests.utils_pytest import (
assert_in_results,
assert_result_count,
)
import datalad_catalog.constants as cnst
from datalad_catalog.add import Add
Expand Down Expand Up @@ -128,6 +129,12 @@ def test_set_home(demo_catalog, test_data):
cnst.DATASET_VERSION: ds_meta2[cnst.DATASET_VERSION],
},
)
assert_result_count(
res,
1,
action="catalog_set",
action_property="home",
)


def test_set_home_outofcatalog(demo_catalog, test_data):
Expand Down Expand Up @@ -170,6 +177,12 @@ def test_set_home_outofcatalog(demo_catalog, test_data):
cnst.DATASET_VERSION: "version_not_in_ctalog",
},
)
assert_result_count(
res,
1,
action="catalog_set",
action_property="home",
)
# 2. Test when home page already set, dataset NOT in catalog
# test WITH reckless=overwrite
res = catalog_set(
Expand All @@ -189,3 +202,9 @@ def test_set_home_outofcatalog(demo_catalog, test_data):
path=demo_catalog.location,
home={cnst.DATASET_ID: "bla", cnst.DATASET_VERSION: "bla"},
)
assert_result_count(
res,
1,
action="catalog_set",
action_property="home",
)

0 comments on commit 4c173ec

Please sign in to comment.