diff --git a/datalad_catalog/add.py b/datalad_catalog/add.py index 975a521..da8af62 100644 --- a/datalad_catalog/add.py +++ b/datalad_catalog/add.py @@ -23,9 +23,6 @@ eval_results, get_status_dict, ) -from datalad_next.constraints import ( - EnsurePath, -) from datalad_next.exceptions import CapturedException import json @@ -44,6 +41,8 @@ class AddParameterValidator(EnsureCommandParameterization): """""" def __init__(self): + from datalad_next.constraints import EnsurePath + super().__init__( param_constraints=dict( catalog=CatalogRequired() & EnsureWebCatalog(), diff --git a/datalad_catalog/tests/test_add.py b/datalad_catalog/tests/test_add.py index ae90d89..e09f951 100644 --- a/datalad_catalog/tests/test_add.py +++ b/datalad_catalog/tests/test_add.py @@ -2,7 +2,6 @@ assert_in_results, assert_result_count, ) -from datalad_catalog.add import Add import io import json @@ -11,11 +10,12 @@ from datalad_next.constraints.exceptions import CommandParametrizationError -catalog_add = Add() - def test_no_args(demo_catalog, test_data): + from datalad_catalog.add import Add + """Both the catalog and metadata arguments are required""" + catalog_add = Add() with pytest.raises(CommandParametrizationError): catalog_add() @@ -28,6 +28,9 @@ def test_no_args(demo_catalog, test_data): def test_add_from_file(demo_catalog, test_data): """Add catalog metadata from a file with json line(s)""" + from datalad_catalog.add import Add + + catalog_add = Add() res = catalog_add( catalog=demo_catalog, metadata=test_data.catalog_metadata_dataset1, @@ -57,6 +60,9 @@ def test_add_from_file(demo_catalog, test_data): def test_add_from_file_faulty(demo_catalog, test_data): """Add catalog metadata from a file with json lines where at least one line is not valid json""" + from datalad_catalog.add import Add + + catalog_add = Add() res = catalog_add( catalog=demo_catalog, metadata=test_data.catalog_metadata_valid_invalid, @@ -80,10 +86,13 @@ def test_add_from_file_faulty(demo_catalog, test_data): def test_add_from_stdin(monkeypatch, demo_catalog): """Add catalog metadata from stdin""" + from datalad_catalog.add import Add + mdata1 = '{"dataset_id": "deabeb9b-7a37-4062-a1e0-8fcef7909609", "dataset_version": "0321dbde969d2f5d6b533e35b5c5c51ac0b15758", "type": "dataset", "metadata_sources": {"key_source_map": {}, "sources": [{"source_name": "", "source_version": ""}]}}' mdata2 = '{"dataset_id": "3344ffv5-7a37-4062-a1e0-8fcef7909609", "dataset_version": "8888dbde969d2f5d6b533e35b5c5c51ac0b15758", "type": "dataset", "metadata_sources": {"key_source_map": {}, "sources": [{"source_name": "", "source_version": ""}]}}' content = io.StringIO(json.dumps(mdata1) + "\n" + json.dumps(mdata2)) monkeypatch.setattr("sys.stdin", content) + catalog_add = Add() res = catalog_add( catalog=demo_catalog, metadata="-", @@ -101,7 +110,10 @@ def test_add_from_stdin(monkeypatch, demo_catalog): def test_add_from_json_str(demo_catalog, test_data): """Add catalog metadata from a json serialized string""" + from datalad_catalog.add import Add + mdata = '{"dataset_id": "deabeb9b-7a37-4062-a1e0-8fcef7909609", "dataset_version": "0321dbde969d2f5d6b533e35b5c5c51ac0b15758", "type": "dataset", "metadata_sources": {"key_source_map": {}, "sources": [{"source_name": "", "source_version": ""}]}}' + catalog_add = Add() res = catalog_add( catalog=demo_catalog, metadata=mdata, @@ -118,6 +130,8 @@ def test_add_from_json_str(demo_catalog, test_data): def test_add_from_dict(demo_catalog): """Add catalog metadata from a json serialized string""" + from datalad_catalog.add import Add + mdata = { "dataset_id": "deabeb9b-7a37-4062-a1e0-8fcef7909609", "dataset_version": "0321dbde969d2f5d6b533e35b5c5c51ac0b15758", @@ -127,6 +141,7 @@ def test_add_from_dict(demo_catalog): "sources": [{"source_name": "", "source_version": ""}], }, } + catalog_add = Add() res = catalog_add( catalog=demo_catalog, metadata=mdata,