Skip to content

Commit d70bdae

Browse files
author
Will Benfold
committed
Significantly simpler warning checks
1 parent 3877ed7 commit d70bdae

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/iris/tests/unit/fileformats/netcdf/test_parse_cell_methods.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ def test_comment_bracket_mismatch_warning(self):
122122
"time : minimum within days (comment: 18h day-1)-18h)",
123123
]
124124
for cell_method_str in cell_method_strings:
125-
with mock.patch("warnings.warn") as warn:
125+
with self.assertWarns(
126+
UserWarning,
127+
msg="Cell methods may be incorrectly parsed due to mismatched brackets",
128+
):
126129
_ = parse_cell_methods(cell_method_str)
127-
self.assertIn(
128-
"Cell methods may be incorrectly parsed due to mismatched brackets",
129-
warn.call_args[0][0],
130-
)
131130

132131
def test_badly_formatted_warning(self):
133132
cell_method_strings = [
@@ -139,12 +138,11 @@ def test_badly_formatted_warning(self):
139138
"time: (interval: 1 day comment: second bit)",
140139
]
141140
for cell_method_str in cell_method_strings:
142-
with mock.patch("warnings.warn") as warn:
141+
with self.assertWarns(
142+
UserWarning,
143+
msg=f"Failed to fully parse cell method string: {cell_method_str}",
144+
):
143145
_ = parse_cell_methods(cell_method_str)
144-
self.assertIn(
145-
f"Failed to fully parse cell method string: {cell_method_str}",
146-
warn.call_args[0][0],
147-
)
148146

149147
def test_portions_of_cells(self):
150148
cell_method_strings = [

0 commit comments

Comments
 (0)