Skip to content

Commit 0b07b05

Browse files
Check type of argument passed to esmvalcore.cmor.table.read_cmor_tables (#2217)
1 parent adeb1e2 commit 0b07b05

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

esmvalcore/cmor/table.py

+8
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,17 @@ def read_cmor_tables(cfg_developer: Optional[Path] = None) -> None:
124124
----------
125125
cfg_developer:
126126
Path to config-developer.yml file.
127+
128+
Raises
129+
------
130+
TypeError
131+
If `cfg_developer` is not a Path-like object
127132
"""
128133
if cfg_developer is None:
129134
cfg_developer = Path(__file__).parents[1] / 'config-developer.yml'
135+
elif not isinstance(cfg_developer, Path):
136+
raise TypeError("cfg_developer is not a Path-like object, got ",
137+
cfg_developer)
130138
mtime = cfg_developer.stat().st_mtime
131139
cmor_tables = _read_cmor_tables(cfg_developer, mtime)
132140
CMOR_TABLES.clear()

tests/integration/cmor/test_read_cmor_tables.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22

3+
import pytest
34
import yaml
45

56
from esmvalcore.cmor.table import CMOR_TABLES
@@ -18,6 +19,14 @@
1819
}
1920

2021

22+
def test_read_cmor_tables_raiser():
23+
"""Test func raiser."""
24+
cfg_file = {"cow": "moo"}
25+
with pytest.raises(TypeError) as exc:
26+
read_cmor_tables(cfg_file)
27+
assert "cow" in str(exc)
28+
29+
2130
def test_read_cmor_tables():
2231
"""Test that the function `read_cmor_tables` loads the tables correctly."""
2332
table_path = Path(root).parent / 'tables'

0 commit comments

Comments
 (0)