forked from mdekauwe/CABLE_benchmarking
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move user membership in project tests to test_benchcab
- Loading branch information
1 parent
b78294b
commit e3f1f9e
Showing
6 changed files
with
97 additions
and
65 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
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
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,67 @@ | ||
"""`pytest` tests for `benchcab.py`.""" | ||
import re | ||
from contextlib import nullcontext as does_not_raise | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from benchcab.benchcab import Benchcab | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def _set_user_projects(): | ||
with mock.patch("grp.getgrgid") as mocked_getgrid, mock.patch( | ||
"os.getgroups" | ||
) as mocked_groups: | ||
type(mocked_getgrid.return_value).gr_name = mock.PropertyMock( | ||
return_value="hh5" | ||
) | ||
mocked_groups.return_value = [1] | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="module", params=["hh5", "invalid_project_name"]) | ||
def config_project(request): | ||
"""Get config project name.""" | ||
return request.param | ||
|
||
|
||
# Error message if config project name cannot be resolved. | ||
no_project_name_msg = re.escape( | ||
"""Couldn't resolve project: check 'project' in config.yaml | ||
and/or $PROJECT set in ~/.config/gadi-login.conf | ||
""" | ||
) | ||
|
||
# For testing whether user is member of necessary projects to run benchcab, we need to simulate the environment of Gadi | ||
# TODO: Simulate Gadi environment for running tests for validating environment | ||
|
||
|
||
@pytest.mark.skip() | ||
@pytest.mark.parametrize( | ||
("config_project", "pytest_error"), | ||
[ | ||
("hh5", does_not_raise()), | ||
(None, pytest.raises(AttributeError, match=no_project_name_msg)), | ||
], | ||
) | ||
def test_project_name(config_project, pytest_error): | ||
"""Tests whether config project name is suitable to run in Gadi environment.""" | ||
app = Benchcab(benchcab_exe_path=None) | ||
with pytest_error: | ||
app._validate_environment(project=config_project, modules=[]) | ||
|
||
|
||
@pytest.mark.skip() | ||
@pytest.mark.parametrize( | ||
("config_project", "pytest_error"), | ||
[ | ||
("hh5", does_not_raise()), | ||
("invalid_project_name", pytest.raises(PermissionError)), | ||
], | ||
) | ||
def test_user_project_group(config_project, pytest_error): | ||
"""Test _validate_environment for if current user's groups does not contain the project name.""" | ||
app = Benchcab(benchcab_exe_path=None) | ||
with pytest_error: | ||
app._validate_environment(project=config_project, modules=[]) | ||
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