Skip to content

Commit

Permalink
g Added tests (covered missing lines introduced by refactor found by
Browse files Browse the repository at this point in the history
  sentry)
- Updated cmip6.yaml as a different translator is required for Cordex
  experiments as main CMIP6 experiments.
  • Loading branch information
charles-turner-1 committed Oct 14, 2024
1 parent 51be2ea commit f9dbb95
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
6 changes: 1 addition & 5 deletions config/cmip6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ sources:

- metadata_yaml: /g/data/xp65/admin/access-nri-intake-catalog/config/metadata_sources/cmip6-oi10/metadata.yaml
path:
- /g/data/oi10/catalog/v2/esm/catalog.json

- metadata_yaml: /g/data/xp65/admin/intake/metadata/cmip6_ig45/metadata.yaml
path:
- /g/data/ig45/catalog/v2/esm/catalog.json
- /g/data/oi10/catalog/v2/esm/catalog.json
26 changes: 0 additions & 26 deletions config/experiments/cmip6_ig45/metadata.yaml

This file was deleted.

1 change: 0 additions & 1 deletion config/metadata_sources/cordex-ig45/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ license:
url: https://geonetwork.nci.org.au/geonetwork/srv/eng/catalog.search#/metadata/f7465_8388_5100_7022
parent_experiment:
related_experiments:
-
notes:
keywords:
- cmip
4 changes: 2 additions & 2 deletions src/access_nri_intake/catalog/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def set_dispatch(
The function to translate the column
"""
if core_colname not in ["model", "realm", "frequency", "variable"]:
raise ValueError(
"'flag' must be one of 'model', 'realm', 'frequency', 'variable'"
raise TranslatorError(
f"'core_colname' must be one of 'model', 'realm', 'frequency', 'variable', not {core_colname}"
)
self._dispatch[core_colname] = func
setattr(self._dispatch_keys, core_colname, input_name)
Expand Down
47 changes: 47 additions & 0 deletions tests/test_translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
TranslatorError,
_cmip_realm_translator,
_to_tuple,
tuplify_series,
)


Expand Down Expand Up @@ -189,6 +190,29 @@ def test_DefaultTranslator_error(test_data):
assert "Could not translate" in str(excinfo.value)


@pytest.mark.parametrize(
"colname, should_raise",
[
("model", False),
("realm", False),
("frequency", False),
("variable", False),
("random_string", True),
],
)
def test_DefaultTranslator_set_dispatch(test_data, colname, should_raise):
"""Test that only valid translation setups are allowed"""
esmds = intake.open_esm_datastore(test_data / "esm_datastore/cmip5-al33.json")
dtrans = DefaultTranslator(esmds, CORE_COLUMNS)
if should_raise:
with pytest.raises(TranslatorError) as excinfo:
dtrans.set_dispatch(colname, dtrans._model_translator, "model")
assert "'core_colname' must be one of" in str(excinfo.value)
else:
dtrans.set_dispatch(colname, dtrans._model_translator, colname)
assert dtrans._dispatch[colname] == dtrans._model_translator


@pytest.mark.parametrize(
"groupby, n_entries",
[
Expand Down Expand Up @@ -280,3 +304,26 @@ def test_CordexTranslator(test_data, groupby, n_entries):
esmds.description = "description"
df = CordexTranslator(esmds, CORE_COLUMNS).translate(groupby)
assert len(df) == n_entries


@pytest.mark.parametrize(
"input_series, expected_output",
[
(pd.Series([1, 2, 3]), pd.Series([(1,), (2,), (3,)])),
(pd.Series([(1,), 2, 3]), pd.Series([(1,), (2,), (3,)])),
],
)
def test_tuplify_series(input_series, expected_output):
"""Test the _tuplify_series function"""

@tuplify_series
def tuplify_func(series):
return series

class TestSeries:
@tuplify_series
def method(self, series):
return series

assert all(tuplify_func(input_series) == expected_output)
assert all(TestSeries().method(input_series) == expected_output)

0 comments on commit f9dbb95

Please sign in to comment.