-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from sbillinge/configupdate
Config updater workflow
- Loading branch information
Showing
4 changed files
with
157 additions
and
98 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,23 @@ | ||
**Added:** | ||
|
||
* no news added: covered in the news from the get_user_info work | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
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 |
---|---|---|
|
@@ -5,72 +5,7 @@ | |
|
||
import pytest | ||
|
||
from diffpy.utils.tools import get_package_info, get_user_info | ||
|
||
# def _setup_dirs(monkeypatch, user_filesystem): | ||
# home_dir, cwd_dir = user_filesystem.home_dir, user_filesystem.cwd_dir | ||
# os.chdir(cwd_dir) | ||
# return home_dir | ||
# | ||
|
||
|
||
def _run_tests(inputs, expected): | ||
args = {"username": inputs[0], "email": inputs[1]} | ||
expected_username, expected_email = expected | ||
config = get_user_info(args) | ||
assert config.get("username") == expected_username | ||
assert config.get("email") == expected_email | ||
|
||
|
||
params_user_info_with_local_conf_file = [ | ||
(["", ""], ["cwd_username", "[email protected]"]), | ||
(["cli_username", ""], ["cli_username", "[email protected]"]), | ||
(["", "[email protected]"], ["cwd_username", "[email protected]"]), | ||
([None, None], ["cwd_username", "[email protected]"]), | ||
(["cli_username", None], ["cli_username", "[email protected]"]), | ||
([None, "[email protected]"], ["cwd_username", "[email protected]"]), | ||
(["cli_username", "[email protected]"], ["cli_username", "[email protected]"]), | ||
] | ||
params_user_info_with_no_home_conf_file = [ | ||
( | ||
[None, None], | ||
["input_username", "[email protected]"], | ||
["input_username", "[email protected]"], | ||
), | ||
( | ||
["cli_username", None], | ||
["", "[email protected]"], | ||
["cli_username", "[email protected]"], | ||
), | ||
( | ||
[None, "[email protected]"], | ||
["input_username", ""], | ||
["input_username", "[email protected]"], | ||
), | ||
( | ||
["", ""], | ||
["input_username", "[email protected]"], | ||
["input_username", "[email protected]"], | ||
), | ||
( | ||
["cli_username", ""], | ||
["", "[email protected]"], | ||
["cli_username", "[email protected]"], | ||
), | ||
( | ||
["", "[email protected]"], | ||
["input_username", ""], | ||
["input_username", "[email protected]"], | ||
), | ||
( | ||
["cli_username", "[email protected]"], | ||
["input_username", "[email protected]"], | ||
["cli_username", "[email protected]"], | ||
), | ||
] | ||
params_user_info_no_conf_file_no_inputs = [ | ||
([None, None], ["", ""], ["", ""]), | ||
] | ||
from diffpy.utils.tools import check_and_build_global_config, get_package_info, get_user_info | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -149,27 +84,63 @@ def test_get_user_info_with_local_conf_file(runtime_inputs, expected, user_files | |
assert actual == expected | ||
|
||
|
||
# @pytest.mark.parametrize("inputsa, inputsb, expected", params_user_info_with_no_home_conf_file) | ||
# def test_get_user_info_with_no_home_conf_file(monkeypatch, inputsa, inputsb, expected, user_filesystem): | ||
# _setup_dirs(monkeypatch, user_filesystem) | ||
# os.remove(Path().home() / "diffpyconfig.json") | ||
# inp_iter = iter(inputsb) | ||
# monkeypatch.setattr("builtins.input", lambda _: next(inp_iter)) | ||
# _run_tests(inputsa, expected) | ||
# confile = Path().home() / "diffpyconfig.json" | ||
# assert confile.is_file() | ||
# | ||
# | ||
# @pytest.mark.parametrize("inputsa, inputsb, expected", params_user_info_no_conf_file_no_inputs) | ||
# def test_get_user_info_no_conf_file_no_inputs(monkeypatch, inputsa, inputsb, expected, user_filesystem): | ||
# _setup_dirs(monkeypatch, user_filesystem) | ||
# os.remove(Path().home() / "diffpyconfig.json") | ||
# inp_iter = iter(inputsb) | ||
# monkeypatch.setattr("builtins.input", lambda _: next(inp_iter)) | ||
# _run_tests(inputsa, expected) | ||
# confile = Path().home() / "diffpyconfig.json" | ||
# assert confile.exists() is False | ||
# | ||
@pytest.mark.parametrize( | ||
"test_inputs,expected", | ||
[ # Check check_and_build_global_config() builds correct config when config is found missing | ||
( # C1: user inputs valid name, email and orcid | ||
{"user_inputs": ["input_name", "[email protected]", "input_orcid"]}, | ||
{"owner_email": "[email protected]", "owner_orcid": "input_orcid", "owner_name": "input_name"}, | ||
), | ||
({"user_inputs": ["", "", ""]}, None), # C2: empty strings passed in, expect no config file created | ||
( # C3: just username input, expect config file but with some empty values | ||
{"user_inputs": ["input_name", "", ""]}, | ||
{"owner_email": "", "owner_orcid": "", "owner_name": "input_name"}, | ||
), | ||
], | ||
) | ||
def test_check_and_build_global_config(test_inputs, expected, user_filesystem, mocker): | ||
# user_filesystem[0] is tmp_dir/home_dir with the global config file in it, user_filesystem[1] | ||
# is tmp_dir/cwd_dir | ||
mocker.patch.object(Path, "home", return_value=user_filesystem[0]) | ||
os.chdir(user_filesystem[1]) | ||
confile = user_filesystem[0] / "diffpyconfig.json" | ||
# remove the config file from home that came with user_filesystem | ||
os.remove(confile) | ||
mocker.patch("builtins.input", side_effect=test_inputs["user_inputs"]) | ||
actual_bool = check_and_build_global_config() | ||
try: | ||
with open(confile, "r") as f: | ||
actual = json.load(f) | ||
expected_bool = True | ||
except FileNotFoundError: | ||
expected_bool = False | ||
actual = None | ||
assert actual == expected | ||
assert actual_bool == expected_bool | ||
|
||
|
||
def test_check_and_build_global_config_file_exists(user_filesystem, mocker): | ||
mocker.patch.object(Path, "home", return_value=user_filesystem[0]) | ||
os.chdir(user_filesystem[1]) | ||
confile = user_filesystem[0] / "diffpyconfig.json" | ||
expected = {"owner_name": "home_ownername", "owner_email": "[email protected]", "owner_orcid": "home_orcid"} | ||
actual_bool = check_and_build_global_config() | ||
assert actual_bool is True | ||
with open(confile, "r") as f: | ||
actual = json.load(f) | ||
assert actual == expected | ||
|
||
|
||
def test_check_and_build_global_config_skipped(user_filesystem, mocker): | ||
mocker.patch.object(Path, "home", return_value=user_filesystem[0]) | ||
os.chdir(user_filesystem[1]) | ||
confile = user_filesystem[0] / "diffpyconfig.json" | ||
# remove the config file from home that came with user_filesystem | ||
os.remove(confile) | ||
actual_bool = check_and_build_global_config(skip_config_creation=True) | ||
assert actual_bool is False | ||
assert not confile.exists() | ||
|
||
|
||
params_package_info = [ | ||
(["diffpy.utils", None], {"package_info": {"diffpy.utils": "3.3.0"}}), | ||
|