-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the exception message when an option within the rootpath sec…
…tion is missing from the user configuration file (#2236)
- Loading branch information
Showing
2 changed files
with
53 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Tests for ``_get_rootpath`` in ``esmvalcore.local``.""" | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from esmvalcore import local | ||
|
||
|
||
@mock.patch("os.path.exists") | ||
def test_get_rootpath_exists(mexists): | ||
mexists.return_value = True | ||
cfg = {"rootpath": {"CMIP5": ["/path1"], "CMIP6": ["/path2"]}} | ||
project = "CMIP5" | ||
with mock.patch.dict(local.CFG, cfg): | ||
output = local._get_rootpath(project) | ||
# 'output' is a list containing a PosixPath: | ||
assert str(output[0]) == cfg["rootpath"][project][0] | ||
|
||
|
||
@mock.patch("os.path.exists") | ||
def test_get_rootpath_does_not_exist(mexists): | ||
mexists.return_value = False | ||
cfg = {"rootpath": {"CMIP5": ["path1"], "CMIP6": ["path2"]}} | ||
project = "OBS" | ||
with mock.patch.dict(local.CFG, cfg): | ||
msg = rf"The \"{project}\" option is missing.*" | ||
with pytest.raises(KeyError, match=msg): | ||
local._get_rootpath(project) |