Skip to content

Commit

Permalink
tests: Add tests for normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
pmav99 committed Feb 3, 2024
1 parent 7c141e5 commit 6df5f28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions tests/normalization_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import pytest
import xarray as xr

from . import DATA_DIR
from thalassa import api
from thalassa import normalization
from thalassa.normalization import THALASSA_FORMATS

@pytest.mark.parametrize(
"ds,expected_fmt",
[
pytest.param(api.open_dataset(DATA_DIR / "fort.63.nc", normalize=False), THALASSA_FORMATS.ADCIRC, id="ADCIRC"),
pytest.param(xr.Dataset(), THALASSA_FORMATS.UNKNOWN, id="Unknown"),
],
)
def test_infer_format(ds, expected_fmt):
fmt = normalization.infer_format(ds)
assert fmt == expected_fmt


@pytest.mark.parametrize(
"path,expected",
[
pytest.param(DATA_DIR / "fort.63.nc", True, id="ADCIRC"),
pytest.param(__file__, False, id="Unknown"),
],
)
def test_can_be_inferred(path, expected):
result = normalization.can_be_inferred(path)
assert result == expected
4 changes: 2 additions & 2 deletions thalassa/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def is_adcirc(ds: xarray.Dataset) -> bool:
def infer_format(ds: xarray.Dataset) -> THALASSA_FORMATS:
if is_schism(ds):
fmt = THALASSA_FORMATS.SCHISM
elif is_adcirc(ds):
fmt = THALASSA_FORMATS.ADCIRC
elif is_pyposeidon(ds):
fmt = THALASSA_FORMATS.PYPOSEIDON
elif is_generic(ds):
fmt = THALASSA_FORMATS.GENERIC
elif is_adcirc(ds):
fmt = THALASSA_FORMATS.ADCIRC
else:
fmt = THALASSA_FORMATS.UNKNOWN
logger.debug("Inferred format: %s", fmt)
Expand Down

0 comments on commit 6df5f28

Please sign in to comment.