Skip to content

Commit

Permalink
fix merge errors, format updates
Browse files Browse the repository at this point in the history
  • Loading branch information
juliacollins committed Dec 4, 2024
1 parent f537cfd commit 3adac71
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
3 changes: 1 addition & 2 deletions src/nsidc/metgen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/nsidc/metgen/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 5 additions & 15 deletions src/nsidc/metgen/metgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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:
Expand Down
21 changes: 12 additions & 9 deletions tests/test_metgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 3adac71

Please sign in to comment.