Skip to content

Commit 55414a9

Browse files
committed
Changed cell_methods regex slightly to fix failures in unit tests.
Also added new unit test to check cell_methods with: 1. Name only (no colon and method) 2. Not space between colon separator and method.
1 parent 5325653 commit 55414a9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/iris/fileformats/_nc_load_rules/helpers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@
202202
_CM_INTERVAL = "interval"
203203
_CM_METHOD = "method"
204204
_CM_NAME = "name"
205-
_CM_PARSE_NAME = re.compile(r"([\w_]+\s*?:\s?)+")
205+
_CM_PARSE_NAME = re.compile(r"([\w_]+\s*?:\s*)+")
206206
_CM_PARSE = re.compile(
207207
r"""
208-
(?P<name>([\w_]+\s*?:\s?)+)
209-
(?P<method>[\w_\s]+(?![\w_]*\s*?:))\s*
208+
(?P<name>([\w_]+\s*?:\s*)+)
209+
(?P<method>[^\s][\w_\s]+(?![\w_]*\s*?:))\s*
210210
(?:
211211
\(\s*
212212
(?P<extra>.+)

lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_parse_cell_methods.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Test(tests.IrisTest):
1919
def test_simple(self):
2020
cell_method_strings = [
2121
"time: mean",
22+
"time:mean",
2223
"time : mean",
2324
]
2425
expected = (CellMethod(method="mean", coords="time"),)
@@ -125,6 +126,7 @@ def test_badly_formatted_warning(self):
125126
cell_method_strings = [
126127
# "time: maximum (interval: 1 hr comment: first bit "
127128
# "time: mean (interval: 1 day comment: second bit)",
129+
'time',
128130
"time: (interval: 1 hr comment: first bit) "
129131
"time: mean (interval: 1 day comment: second bit)",
130132
"time: maximum (interval: 1 hr comment: first bit) "

0 commit comments

Comments
 (0)