Skip to content

Commit

Permalink
Test for an unexpected result from a wrapped metadata operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Nov 15, 2023
1 parent dca5dce commit dae3a28
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/iris/common/_split_attribute_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def _inner_function(*args, **kwargs):
_convert_pairedkeys_dict_to_splitattrs(right),
)
result = result.__class__([left, right])
else:
message = (
f"Common-metadata operation {operation!r} returned a result which is "
f"neither a Mapping nor a pair of Mappings : {result!r}."
)
raise ValueError(message)

return result

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright Iris contributors
#
# This file is part of Iris and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
"""Unit tests for the :mod:`iris.common.metadata._split_attribute_dicts` package."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright Iris contributors
#
# This file is part of Iris and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
"""
Unit tests for the :class:`iris.common._split_attribute_dicts.adjust_for_split_attribute_dictionaries`.
"""
import pytest

from iris.common._split_attribute_dicts import (
adjust_for_split_attribute_dictionaries,
)


class Test:
"""
Test the decorator function + behaviour of decorated functions.
In this module, only exercise the return-value error check,
since **all other behaviour is tested by integration**.
See : :mod:`iris.tests.unit.common.metadata.test_CubeMetadata`.
"""

def test_bad_return_value__fails(self):
@adjust_for_split_attribute_dictionaries
def sample_metadata_operation(*dictionary_args):
return [1, 2, 3]

message = (
"Common-metadata operation .*sample_metadata_operation .* "
"returned a result which is neither a Mapping nor a pair of Mappings "
r": \[1, 2, 3\]."
)
with pytest.raises(ValueError, match=message):
sample_metadata_operation({})

0 comments on commit dae3a28

Please sign in to comment.