Skip to content

Commit

Permalink
DAS-1177 - Added missing tests and updated comment for index range in…
Browse files Browse the repository at this point in the history
… the end-to-end test
  • Loading branch information
lyonthefrog committed Mar 14, 2024
1 parent b906d2a commit e5f64d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
14 changes: 8 additions & 6 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2094,12 +2094,14 @@ def test_edge_aligned_no_bounds_end_to_end(self, mock_stage,
# Ensure the constraint expression contains all the required variables.
# The latitude and longitude index ranges here depend on whether
# the cells have centre-alignment or edge-alignment.
# - Expected index range for latitude: [53:54] for values (69,72).
# - Expected index range for longitude: [85:89] for values (75,78,81,81,87)
# - Expected index range for science variable: [53:54][85:89]
# If centre-alignment was incorrectly assumed:
# - Incorrect ranges off by one: [54:55]
# - Incorrect ranges off by one: [86:89]
# Previously, the incorrect index ranges assuming centre-alignment:
# latitude [54:55] with values (72,75)
# longitude [86:89] with values (78,81,84,87)
#
# Now, the correct index ranges with edge-alignment:
# latitude: [53:54] for values (69,72).
# longitude:[85:89] for values (75,78,81,84,87)
#
index_range_data = mock_util_download.call_args_list[2][1].get('data', {})
self.assert_valid_request_data(
index_range_data,
Expand Down
28 changes: 20 additions & 8 deletions tests/unit/test_dimension_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,28 @@ def test_write_bounds(self):

write_bounds(prefetch_dataset, root_varinfo_variable)

# Check that bounds variable was written to the root group.
self.assertTrue(prefetch_dataset.variables[root_bounds_name])

resulting_bounds_root_data = prefetch_dataset.variables[
root_bounds_name][:]

assert_array_equal(resulting_bounds_root_data,
expected_bounds_data)
# Check that bounds variable exists in the root group.
self.assertTrue(prefetch_dataset.variables[root_variable_name])
# Check that bounds variable has expected attributes.
# (This is only the 'bounds' attribute, since other attributes
# are not required.)
root_bounds_varinfo_variable = varinfo_prefetch.get_variable(
root_variable_full_path)
self.assertEqual(root_bounds_varinfo_variable.attributes['bounds'],
root_bounds_name)
# Check that dimension variable has 'bounds' attribute.
# Check that varinfo variable has 'bounds' attribute.
self.assertEqual(root_varinfo_variable.attributes['bounds'],
root_bounds_name)
# Check that NetCDF4 dimension variable has 'bounds' attribute.
self.assertEqual(prefetch_dataset.variables[
root_variable_name].__dict__.get('bounds'),
root_bounds_name)
# Check that VariableFromDmr has 'bounds' reference in
# the references dictionary.
self.assertEqual(root_varinfo_variable.references['bounds'],
Expand All @@ -453,27 +459,33 @@ def test_write_bounds(self):
nested_varinfo_variable = varinfo_prefetch.get_variable(
nested_variable_full_path)
nested_variable_name = 'zelda'
nested_variable_path = '/group1/group2'
nested_group = prefetch_dataset[nested_variable_path]
nested_group_path = '/group1/group2'
nested_group = prefetch_dataset[nested_group_path]
nested_bounds_name = nested_variable_name + '_bnds'

write_bounds(prefetch_dataset, nested_varinfo_variable)

# Check that bounds variable exists in the nested group.
self.assertTrue(nested_group.variables[nested_bounds_name])

resulting_bounds_nested_data = nested_group.variables[
nested_bounds_name][:]
assert_array_equal(resulting_bounds_nested_data,
expected_bounds_data)
# Check that bounds variable exists in the nested group.
self.assertTrue(nested_group.variables[nested_bounds_name])
# Check that bounds variable has expected attributes.
# (This is only the 'bounds' attribute, since other attributes
# are not required.)
nested_bounds_varinfo_variable = varinfo_prefetch.get_variable(
nested_variable_full_path)
self.assertEqual(nested_bounds_varinfo_variable.attributes['bounds'],
nested_bounds_name)
# Check that dimension variable has 'bounds' attribute.
# Check that varinfo variable has 'bounds' attribute.
self.assertEqual(nested_varinfo_variable.attributes['bounds'],
nested_bounds_name)
# Check that NetCDF4 dimension variable has 'bounds' attribute.
self.assertEqual(nested_group.variables[
nested_variable_name].__dict__.get('bounds'),
nested_bounds_name)
# Check that VariableFromDmr 'has bounds' reference in
# the references dictionary.
self.assertEqual(nested_varinfo_variable.references['bounds'],
Expand Down

0 comments on commit e5f64d3

Please sign in to comment.