Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Jan 21, 2025
1 parent 0d646eb commit fac7a79
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _convert(path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
errors="ignore",
)
.transpose(*MetOfficeDatahubRawRepository.model().expected_coordinates.dims))
print('ccc')

Check failure on line 307 in src/nwp_consumer/internal/repositories/raw_repositories/mo_datahub.py

View workflow job for this annotation

GitHub Actions / lint-typecheck

Ruff (W293)

src/nwp_consumer/internal/repositories/raw_repositories/mo_datahub.py:307:1: W293 Blank line contains whitespace
if "latitude" in MetOfficeDatahubRawRepository.model().expected_coordinates.dims:
da = da.sortby(variables=["step", "variable", "longitude"])
da = da.sortby(variables="latitude", ascending=False)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pathlib
import unittest
from unittest.mock import patch

from returns.result import Failure, ResultE, Success

Expand Down Expand Up @@ -89,3 +90,43 @@ class TestCase:
else:
self.assertIsInstance(region_result, Success, msg=f"{region_result}")

@patch.dict(os.environ, {"MODEL": "UKV"}, clear=True)
def test_convert_ukv(self) -> None:

@dataclasses.dataclass
class TestCase:
filename: str
expected_coords: NWPDimensionCoordinateMap
should_error: bool

tests: list[TestCase] = [
TestCase(
filename="test_MO_UKV_agl_relative-humidity_1.5_2025012112.grib",
expected_coords=dataclasses.replace(
MetOfficeDatahubRawRepository.model().expected_coordinates,
init_time=[dt.datetime(2025, 1, 21, 12, tzinfo=dt.UTC)],
variable=[Parameter.TEMPERATURE_SL],
step=[0],
),
should_error=False,
),
]

for t in tests:
with self.subTest(name=t.filename):
# Attempt to convert the file
result = MetOfficeDatahubRawRepository._convert(
path=pathlib.Path(__file__).parent.absolute() / "test_gribs" / t.filename,
)
region_result: ResultE[dict[str, slice]] = result.do(
region
for das in result
for da in das
for region in NWPDimensionCoordinateMap.from_xarray(da).bind(
t.expected_coords.determine_region,
)
)
if t.should_error:
self.assertIsInstance(region_result, Failure, msg=f"{region_result}")
else:
self.assertIsInstance(region_result, Success, msg=f"{region_result}")

Check failure on line 132 in src/nwp_consumer/internal/repositories/raw_repositories/test_mo_datahub.py

View workflow job for this annotation

GitHub Actions / lint-typecheck

Ruff (W292)

src/nwp_consumer/internal/repositories/raw_repositories/test_mo_datahub.py:132:94: W292 No newline at end of file

0 comments on commit fac7a79

Please sign in to comment.