-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the exception message when an option within the rootpath section is missing from the user configuration file #2236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, you made these changes too, unless precommit hooks now write unit tests too (which would be fab) π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π€£ π€£ π€£ I added these after I made that comment! π |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pre-commit hooks made all the changes in this PR, except for this one, which is the one I made :)