diff --git a/esmvalcore/cmor/table.py b/esmvalcore/cmor/table.py index aea873a9de..ebce5431ae 100644 --- a/esmvalcore/cmor/table.py +++ b/esmvalcore/cmor/table.py @@ -124,9 +124,17 @@ def read_cmor_tables(cfg_developer: Optional[Path] = None) -> None: ---------- cfg_developer: Path to config-developer.yml file. + + Raises + ------ + TypeError + If `cfg_developer` is not a Path-like object """ if cfg_developer is None: cfg_developer = Path(__file__).parents[1] / 'config-developer.yml' + elif not isinstance(cfg_developer, Path): + raise TypeError("cfg_developer is not a Path-like object, got ", + cfg_developer) mtime = cfg_developer.stat().st_mtime cmor_tables = _read_cmor_tables(cfg_developer, mtime) CMOR_TABLES.clear() diff --git a/tests/integration/cmor/test_read_cmor_tables.py b/tests/integration/cmor/test_read_cmor_tables.py index 4a50e2c76f..32a472b316 100644 --- a/tests/integration/cmor/test_read_cmor_tables.py +++ b/tests/integration/cmor/test_read_cmor_tables.py @@ -1,5 +1,6 @@ from pathlib import Path +import pytest import yaml from esmvalcore.cmor.table import CMOR_TABLES @@ -18,6 +19,14 @@ } +def test_read_cmor_tables_raiser(): + """Test func raiser.""" + cfg_file = {"cow": "moo"} + with pytest.raises(TypeError) as exc: + read_cmor_tables(cfg_file) + assert "cow" in str(exc) + + def test_read_cmor_tables(): """Test that the function `read_cmor_tables` loads the tables correctly.""" table_path = Path(root).parent / 'tables'