Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

55/refactor fix_latlon_coord #63

Merged
merged 30 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f3951ff
Add grid checking functions
blimlim Jul 29, 2024
9189a6a
Add changes from develop
blimlim Jul 29, 2024
088378c
continue refactor and add tests
blimlim Jul 31, 2024
4545c5b
split fix_latlon_names to separate functions and add tests
blimlim Jul 31, 2024
45dfa8e
Add fixtures for lon/lat array examples and refactor tests
blimlim Aug 1, 2024
468e434
Clean up fix_latlon exception handling and add tests
blimlim Aug 1, 2024
cbc143b
Fix broken tests
blimlim Aug 2, 2024
b2fb618
Update coordinate array fixtures to match real coordinated from ESM1.…
blimlim Aug 2, 2024
995345c
Try undo accidental autoformat...
blimlim Aug 2, 2024
cf70d71
Continue attempting to undo accidental auto format
blimlim Aug 2, 2024
2e77e15
Review fixes inc magic numbers, readability, styling
blimlim Aug 12, 2024
a43b15f
merge in THE process refactor
blimlim Aug 14, 2024
193d7f1
Review style changes, fix tests
blimlim Aug 14, 2024
8e458dc
Finally installed a linter...
blimlim Aug 14, 2024
00f503c
Add end to end test of fix_latlon_coords and required dummy coordinat…
blimlim Aug 15, 2024
62a1bec
Simplify DummyCoordinate, add tests for specific grid types
blimlim Aug 17, 2024
317beae
Simplify DummyCubeWithCoords, ensure that coordinate names match betw…
blimlim Aug 17, 2024
159e430
Add missing coordinate test
blimlim Aug 19, 2024
ab3d6f7
Tidy up tests of fix_latlon_coords
blimlim Aug 19, 2024
c1ecfdc
Replace dummycoords with iris DimCoords
blimlim Aug 28, 2024
21dc1a4
Merge changes from develop
blimlim Aug 28, 2024
c6f6753
Replace repeated asserts with helper functions
blimlim Aug 28, 2024
171b7ff
Simplify coordinate fixtures using decorators
blimlim Aug 30, 2024
05f35f2
Cleanup and simplification from review
blimlim Aug 30, 2024
d2b4ce9
Remove resolved TODO message
blimlim Sep 6, 2024
4e0d637
Swap error type to new UnsupportedTimeSeries error
blimlim Sep 6, 2024
7fb48cd
Clean up based on review
blimlim Sep 6, 2024
6a4c876
Test style simplifications
blimlim Sep 10, 2024
21dc396
Clarity suggestions from review
blimlim Sep 17, 2024
37049c7
Fix indentation
blimlim Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions test/test_conversion_driver_esm1p5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from pathlib import Path
import unittest.mock as mock
import umpost.um2netcdf as um2nc


def test_get_esm1p5_fields_file_pattern():
Expand Down Expand Up @@ -98,11 +99,11 @@ def mock_process(base_mock_process):

@pytest.fixture
def mock_process_with_exception(mock_process):
# Add a generic exception with chosen message to mock_process.
# Yield function so that tests of different exception messages
# Add a specified exception with chosen message to mock_process.
# Yield function so that tests of different exceptions and messages
# can make use of the same fixture.
def _mock_process_with_exception(error_message):
mock_process.side_effect = Exception(error_message)
def _mock_process_with_exception(error_type, error_message):
mock_process.side_effect = error_type(error_message)

yield _mock_process_with_exception

Expand Down Expand Up @@ -130,29 +131,28 @@ def test_convert_fields_file_list_success(mock_process,


def test_convert_fields_file_list_fail_excepted(mock_process_with_exception):
# Hopefully this test will be unnecessary with um2nc standalone.
# Test that the "Variable can not be processed" error arising from time
# series inputs is excepted.
allowed_error_message = esm1p5_convert.ALLOWED_UM2NC_EXCEPTION_MESSAGES[
"TIMESERIES_ERROR"
]
mock_process_with_exception(allowed_error_message)
# Test that UnsupportedTimeSeriesErrors are excepted.

# TODO: This test will not catch changes to the exceptions in um2nc. E.g.
# if decided to instead raise a RuntimeError in um2nc when timeseries
# are encountered, the conversion of ESM1.5 outputs would undesirably
# crash, but this test would say everything is fine, since we're
# prescribing the error that is raised.
Comment on lines +136 to +140

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could define the error type raised in this instance as a global variable in conversion_driver_esm1p5.py, and then import it for use in the test as the expected error type?

mock_process_with_exception(um2nc.UnsupportedTimeSeriesError,
"timeseries error")
fake_file_path = Path("fake_file")

_, failed = esm1p5_convert.convert_fields_file_list(
[fake_file_path], "fake_nc_write_dir")

assert failed[0][0] == fake_file_path

# TODO: Testing the exception part of the reported failures will be easier
# once um2nc specific exceptions are added.


def test_convert_fields_file_list_fail_critical(mock_process_with_exception):
# Test that critical exceptions which are not allowed by ALLOWED_UM2NC_EXCEPTION_MESSAGES
# are raised, and hence lead to the conversion crashing.
generic_error_message = "Test error"
mock_process_with_exception(generic_error_message)
mock_process_with_exception(Exception, generic_error_message)
with pytest.raises(Exception) as exc_info:
esm1p5_convert.convert_fields_file_list(
["fake_file"], "fake_nc_write_dir")
Expand Down
Loading
Loading