Skip to content

Commit b65f84b

Browse files
committed
Bring _utils.py up to 100% coverage
1 parent e9ef68d commit b65f84b

File tree

2 files changed

+29
-3
lines changed
  • packages/data

2 files changed

+29
-3
lines changed

packages/data/src/pyearthtools/data/transforms/normalisation/_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@
2121
def format_class_name(class_to_find: object) -> list[str]:
2222
"""
2323
Format class name for use in normalisation caching
24+
Strip out 'pyearthtools.data' from class names and use the rest
25+
as the identifiers
2426
2527
Args:
2628
class_to_find (str): Class to find name for
2729
2830
Returns:
2931
list[str]: Components of class name
3032
"""
33+
34+
# e.g. "<class 'pyearthtools.data.time.Petdt'>"
3135
class_str = str(class_to_find.__class__).split("'")[1]
3236
class_str = class_str.replace(CLASS_NAME_TO_TRIM, "")
3337
class_str_list = class_str.strip().split(".")
3438

35-
if "" in class_str_list:
36-
class_str_list.remove("")
37-
return []
39+
class_str_list = [e for e in class_str_list if e != ""]
40+
41+
return class_str_list
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright Commonwealth of Australia, Bureau of Meteorology 2025.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from pyearthtools.data.transforms.normalisation import _utils
16+
import pyearthtools.data.time
17+
18+
def test_format_class_name():
19+
20+
obj = pyearthtools.data.time.Petdt('2010-01-01')
21+
result = _utils.format_class_name(obj)
22+
assert result == ['time', 'Petdt']

0 commit comments

Comments
 (0)