diff --git a/src/nsidc/metgen/cli.py b/src/nsidc/metgen/cli.py index 2805ab8..c99a1ff 100644 --- a/src/nsidc/metgen/cli.py +++ b/src/nsidc/metgen/cli.py @@ -6,6 +6,7 @@ LOGGER = logging.getLogger(constants.ROOT_LOGGER) + @click.group(epilog="For detailed help on each command, run: metgenc COMMAND --help") def cli(): """The metgenc utility allows users to create granule-level @@ -31,7 +32,6 @@ def init(config): help="Path to configuration file to display", required=True, ) - def info(config_filename): """Summarizes the contents of a configuration file.""" click.echo(metgen.banner()) @@ -58,7 +58,6 @@ def info(config_filename): default="cnm", show_default=True, ) - def validate(config_filename, content_type): """Validates the contents of local JSON files.""" click.echo(metgen.banner()) diff --git a/src/nsidc/metgen/constants.py b/src/nsidc/metgen/constants.py index 0339184..36cde2f 100644 --- a/src/nsidc/metgen/constants.py +++ b/src/nsidc/metgen/constants.py @@ -9,13 +9,13 @@ DEFAULT_DRY_RUN = False # Logging -ROOT_LOGGER = 'metgenc' +ROOT_LOGGER = "metgenc" # JSON schema locations and versions CNM_JSON_SCHEMA = ("nsidc.metgen.json-schema", "cumulus_sns_schema.json") CNM_JSON_SCHEMA_VERSION = "1.6.1" UMMG_JSON_SCHEMA = ("nsidc.metgen.json-schema", "umm-g-json-schema.json") -UMMG_JSON_SCHEMA_VERSION = '1.6.6' +UMMG_JSON_SCHEMA_VERSION = "1.6.6" # Configuration sections SOURCE_SECTION_NAME = "Source" diff --git a/src/nsidc/metgen/metgen.py b/src/nsidc/metgen/metgen.py index 1e35884..954e909 100644 --- a/src/nsidc/metgen/metgen.py +++ b/src/nsidc/metgen/metgen.py @@ -704,7 +704,7 @@ def file_type_path(configuration, content_type): match content_type: case "cnm": return configuration.cnm_path() - case 'ummg': + case "ummg": return configuration.ummg_path() case _: return "" @@ -716,33 +716,23 @@ def schema_file_path(content_type): """ dummy_json = dict() match content_type: -<<<<<<< HEAD - case 'cnm': + case "cnm": return constants.CNM_JSON_SCHEMA, dummy_json - case 'ummg': + case "ummg": # We intentionally create UMM-G output with a couple of parts missing, # so we need to fill in the gaps with dummy values during validation. dummy_json["ProviderDates"] = [{"Date": "2000", "Type": "Create"}] dummy_json["GranuleUR"] = "FakeUR" return constants.UMMG_JSON_SCHEMA, dummy_json case _: - return '', {} + return "", {} + def apply_schema(schema, json_file, dummy_json): """ Apply JSON schema to generated JSON content. """ logger = logging.getLogger(constants.ROOT_LOGGER) -======= - case "cnm": - return constants.CNM_JSON_SCHEMA - case _: - return "" - - -def apply_schema(schema, json_file): - logger = logging.getLogger("metgenc") ->>>>>>> main with open(json_file) as jf: json_content = json.load(jf) try: diff --git a/tests/test_metgen.py b/tests/test_metgen.py index 143e85f..01e9af5 100644 --- a/tests/test_metgen.py +++ b/tests/test_metgen.py @@ -181,30 +181,33 @@ def failing_op(): assert new_ledger.granule == ledger.granule assert len(new_ledger.actions) == 1 - assert new_ledger.actions[0].successful == False assert not new_ledger.actions[0].successful + def test_no_dummy_json_for_cnm(): - schema_path, dummy_json = metgen.schema_file_path('cnm') + schema_path, dummy_json = metgen.schema_file_path("cnm") assert schema_path assert not dummy_json - schema_path, dummy_json = metgen.schema_file_path('foobar') + schema_path, dummy_json = metgen.schema_file_path("foobar") assert not schema_path assert not dummy_json + def test_dummy_json_for_ummg(): - schema_path, dummy_json = metgen.schema_file_path('ummg') + schema_path, dummy_json = metgen.schema_file_path("ummg") assert schema_path assert dummy_json -@patch('nsidc.metgen.metgen.open') -@patch('nsidc.metgen.metgen.jsonschema.validate') + +@patch("nsidc.metgen.metgen.open") +@patch("nsidc.metgen.metgen.jsonschema.validate") def test_dummy_json_used(mock_validate, mock_open): fake_json = {"key": [{"foo": "bar"}]} fake_dummy_json = {"missing_key": "missing_foo"} - with patch("nsidc.metgen.metgen.json.load", return_value = fake_json): + with patch("nsidc.metgen.metgen.json.load", return_value=fake_json): metgen.apply_schema("schema file", "json_file", fake_dummy_json) - mock_validate.assert_called_once_with(instance = fake_json | fake_dummy_json, schema="schema file") - + mock_validate.assert_called_once_with( + instance=fake_json | fake_dummy_json, schema="schema file" + )