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

Cellmethod tolerance #5126

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Various 'empty' cell-method testcases: failing.
  • Loading branch information
pp-mo committed Jan 4, 2023
commit 63387d964e1e40ed0b3c98abb58ef1fdf9c932c9
48 changes: 43 additions & 5 deletions lib/iris/tests/unit/fileformats/netcdf/test_parse_cell_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@


class TestParseCellMethods:
def _check_answers(self, test_strings, result):
def _check_answers(self, test_string_or_strings, result):
"""
Compare a list of test strings against a single expected result.

Done this way so that any failures produce intelligible Pytest messages.
"""
if isinstance(test_string_or_strings, str):
test_string_or_strings = [test_string_or_strings]
expected_tests_and_results = [
(cell_method_str, result) for cell_method_str in test_strings
(cell_method_str, result)
for cell_method_str in test_string_or_strings
]
actual_tests_and_results = [
(cell_method_str, parse_cell_methods(cell_method_str))
for cell_method_str in test_strings
for cell_method_str in test_string_or_strings
]
assert actual_tests_and_results == expected_tests_and_results

Expand Down Expand Up @@ -146,7 +149,7 @@ def test_comment_bracket_mismatch_warning(self):
with pytest.warns(UserWarning, match=msg):
self._check_answers(cell_method_strings, expected)

def test_badly_formatted_warning(self):
def test_badly_formatted__warns(self):
cell_method_strings = [
(
"time: (interval: 1 hr comment: first bit) "
Expand Down Expand Up @@ -187,7 +190,7 @@ def test_climatology(self):
)
self._check_answers(cell_method_strings, expected)

def test_climatology_with_unknown_method(self):
def test_climatology_with_unknown_method__warns(self):
cell_method_strings = [
"time: min within days time: mean over days",
"time : min within days time: mean over days",
Expand All @@ -203,3 +206,38 @@ def test_climatology_with_unknown_method(self):
with pytest.warns(UnknownCellMethodWarning, match=msg):
res = parse_cell_methods(cell_method_str)
assert res == expected

def test_empty__warns(self):
cm_str = ""
msg = "contains no valid cell methods"
with pytest.warns(UserWarning, match=msg):
result = parse_cell_methods(cm_str)
assert result == ()

def test_whitespace__warns(self):
cm_str = " \t "
msg = "contains no valid cell methods"
with pytest.warns(UserWarning, match=msg):
result = parse_cell_methods(cm_str)
assert result == ()

def test_barename__warns(self):
cm_str = "time"
msg = "contains no valid cell methods"
with pytest.warns(UserWarning, match=msg):
result = parse_cell_methods(cm_str)
assert result == ()

def test_missedspace__warns(self):
cm_str = "time:mean"
msg = "contains no valid cell methods"
with pytest.warns(UserWarning, match=msg):
result = parse_cell_methods(cm_str)
assert result == ()

def test_random_junk__warns(self):
cm_str = "y:12+4#?x:this"
msg = "contains no valid cell methods"
with pytest.warns(UserWarning, match=msg):
result = parse_cell_methods(cm_str)
assert result == ()