Skip to content

Commit

Permalink
Check type of argument passed to `esmvalcore.cmor.table.read_cmor_tab…
Browse files Browse the repository at this point in the history
…les` (#2217)
  • Loading branch information
valeriupredoi authored Oct 9, 2023
1 parent adeb1e2 commit 0b07b05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions esmvalcore/cmor/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/cmor/test_read_cmor_tables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path

import pytest
import yaml

from esmvalcore.cmor.table import CMOR_TABLES
Expand All @@ -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'
Expand Down

0 comments on commit 0b07b05

Please sign in to comment.