-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
from .metoffice_global import CedaMetOfficeGlobalModelRepository | ||
from .ecmwf_realtime import ECMWFRealTimeS3ModelRepository | ||
|
||
__all__ = ["CedaMetOfficeGlobalModelRepository"] | ||
__all__ = [ | ||
"CedaMetOfficeGlobalModelRepository", | ||
"ECMWFRealTimeS3ModelRepository", | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import dataclasses | ||
import datetime as dt | ||
import os | ||
import unittest | ||
|
||
from returns.pipeline import flow, is_successful | ||
Check failure on line 6 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (F401)
|
||
from returns.pointfree import bind | ||
Check failure on line 7 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (F401)
|
||
import xarray as xr | ||
Check failure on line 8 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (TCH002)
|
||
|
||
from nwp_consumer.internal import entities | ||
Check failure on line 10 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (TCH001)
|
||
|
||
from .ecmwf_realtime import ECMWFRealTimeS3ModelRepository | ||
from ...entities import NWPDimensionCoordinateMap | ||
|
||
|
||
class TestECMWFRealTimeS3ModelRepository(unittest.TestCase): | ||
Check failure on line 16 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (I001)
|
||
"""Test the business methods of the ECMWFRealTimeS3ModelRepository class.""" | ||
|
||
@unittest.skipIf( | ||
condition="CI" in os.environ, | ||
reason="Skipping integration test that requires S3 access.", | ||
) | ||
def test__download_and_convert(self) -> None: | ||
"""Test the _download_and_convert method.""" | ||
|
||
auth_result = ECMWFRealTimeS3ModelRepository.authenticate() | ||
self.assertTrue(is_successful(auth_result), msg=f"Error: {auth_result.failure}") | ||
c: ECMWFRealTimeS3ModelRepository = auth_result.unwrap() | ||
|
||
test_it: dt.datetime = dt.datetime(2024, 10, 25, 0, tzinfo=dt.UTC) | ||
test_coordinates: entities.NWPDimensionCoordinateMap = dataclasses.replace( | ||
c.model().expected_coordinates, | ||
init_time=[test_it], | ||
) | ||
|
||
urls: list[str] = [ | ||
f"s3://{f}" | ||
for f in c._fs.ls(f"{c.bucket}/ecmwf") | ||
if test_it.strftime( | ||
os.getenv("ECMWF_DISSEMINATION_REALTIME_FILE_PREFIX", "A2") + "D%m%d%H%M", | ||
) in f | ||
] | ||
|
||
for url in urls: | ||
with (self.subTest(url=url)): | ||
result = c._download_and_convert(url) | ||
|
||
self.assertTrue(is_successful(result), msg=f"Error: {result}") | ||
|
||
da: xr.DataArray = result.unwrap()[0] | ||
determine_region_result = NWPDimensionCoordinateMap.from_xarray(da).bind( | ||
test_coordinates.determine_region, | ||
) | ||
self.assertTrue(is_successful(determine_region_result), msg=f"Error: {determine_region_result}") | ||
Check failure on line 54 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (E501)
Check failure on line 54 in src/nwp_consumer/internal/repositories/model_repositories/test_ecmwf_realtime.py GitHub Actions / lint-typecheckRuff (W292)
|