Skip to content

Commit

Permalink
DAS-2232 - added unit test for get_valid_indices
Browse files Browse the repository at this point in the history
  • Loading branch information
sudha-murthy committed Oct 10, 2024
1 parent 7883465 commit dd98e81
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/unit/test_coordinate_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
is_lat_lon_ascending,
update_dimension_variables,
)
from hoss.exceptions import MissingCoordinateDataset
from hoss.exceptions import MissingCoordinateDataset, MissingValidCoordinateDataset


class TestCoordinateUtilities(TestCase):
Expand Down Expand Up @@ -77,6 +77,39 @@ def tearDown(self):
if exists(self.temp_dir):
rmtree(self.temp_dir)

def test_get_valid_indices(self):
"""Ensure that latitude and longitude values are correctly identified as
ascending or descending.
"""

expected_result1 = np.array([0, 1, 2, 3, 4])
expected_result2 = np.array([0, 1, 2, 6, 7, 8, 9])
expected_result3 = np.empty((0, 0))

fill_array = np.array([-9999.0, -9999.0, -9999.0, -9999.0])
with self.subTest('valid indices with no fill values configured'):
actual_result1 = get_valid_indices(self.lat_arr[:, -1], None, 'latitude')
print('actual_result1=' f'{actual_result1}')
print('expected_result1=' f'{expected_result1}')
self.assertTrue(np.array_equal(actual_result1, expected_result1))

with self.subTest('valid indices with fill values configured'):
actual_result2 = get_valid_indices(self.lon_arr[0, :], -9999.0, 'longitude')
print('actual_result2=' f'{actual_result2}')
print('expected_result2=' f'{expected_result2}')
self.assertTrue(np.array_equal(actual_result2, expected_result2))

with self.subTest('all fill values - no valid indices'):
with self.assertRaises(MissingValidCoordinateDataset) as context:
actual_result3 = get_valid_indices(fill_array, -9999.0, 'longitude')
print('actual_result3=' f'{actual_result3}')
print('expected_result3=' f'{expected_result3}')
self.assertEqual(
context.exception.message,
'Coordinate: "longitude" is not valid in source granule file.',
)

def test_is_lat_lon_ascending(self):
"""Ensure that latitude and longitude values are correctly identified as
ascending or descending.
Expand Down

0 comments on commit dd98e81

Please sign in to comment.