Skip to content

Commit

Permalink
Merge pull request #333 from datalad/smallfixes
Browse files Browse the repository at this point in the history
[BF] Small fixes to latest cli commands
  • Loading branch information
jsheunis authored Sep 1, 2023
2 parents ae17248 + e0d7c28 commit d6efc34
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 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",
)
24 changes: 24 additions & 0 deletions datalad_catalog/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datalad_catalog.validate import Validate
from datalad_next.constraints.exceptions import CommandParametrizationError

from pathlib import Path
import pytest

catalog_validate = Validate()
Expand Down Expand Up @@ -65,3 +66,26 @@ def test_validate_from_file_faulty(demo_catalog, test_data):
status="error",
path=demo_catalog.location,
)


def test_validate_without_catalog(demo_catalog, test_data):
"""Validate metadata from a file with json lines,
and no catalog argument"""
res = catalog_validate(
metadata=test_data.catalog_metadata_valid_invalid,
on_failure="ignore",
return_type="list",
)
assert_result_count(
res,
2,
action="catalog_validate",
status="ok",
path=Path.cwd(),
)
assert_in_results(
res,
action="catalog_validate",
status="error",
path=Path.cwd(),
)
3 changes: 2 additions & 1 deletion datalad_catalog/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from datalad_next.exceptions import CapturedException
import json
import logging
from pathlib import Path


__docformat__ = "restructuredtext"
Expand Down Expand Up @@ -109,7 +110,7 @@ def __call__(
):
res_kwargs = dict(
action="catalog_validate",
path=catalog.location,
path=catalog.location if bool(catalog) else Path.cwd(),
)
# turn non-iterable into a list for uniform processing below
if isinstance(metadata, (str, dict)):
Expand Down

0 comments on commit d6efc34

Please sign in to comment.