Skip to content

Commit 65e6c24

Browse files
initial commit
1 parent 2ccd7d6 commit 65e6c24

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/diffpy/utils/tools.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _create_global_config(args):
9191
return return_bool
9292

9393

94-
def get_user_info(args=None):
94+
def get_user_info(args=None, skip_config_creation=False):
9595
"""
9696
Get username and email configuration.
9797
@@ -114,6 +114,9 @@ def get_user_info(args=None):
114114
config_bool = True
115115
global_config = load_config(Path().home() / "diffpyconfig.json")
116116
local_config = load_config(Path().cwd() / "diffpyconfig.json")
117+
if skip_config_creation:
118+
config = _sorted_merge(clean_dict(global_config), clean_dict(local_config), clean_dict(args))
119+
return config
117120
if global_config is None and local_config is None:
118121
print(
119122
"No global configuration file was found containing "

tests/test_tools.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def _run_tests(inputs, expected):
2222
config = get_user_info(args)
2323
assert config.get("username") == expected_username
2424
assert config.get("email") == expected_email
25+
config = get_user_info(args, skip_config_creation=True)
26+
assert config.get("username") == expected_username
27+
assert config.get("email") == expected_email
2528

2629

2730
params_user_info_with_home_conf_file = [
@@ -118,7 +121,20 @@ def test_get_user_info_no_conf_file_no_inputs(monkeypatch, inputsa, inputsb, exp
118121
os.remove(Path().home() / "diffpyconfig.json")
119122
inp_iter = iter(inputsb)
120123
monkeypatch.setattr("builtins.input", lambda _: next(inp_iter))
121-
_run_tests(inputsa, expected)
124+
125+
args = {"username": inputsa[0], "email": inputsa[1]}
126+
expected_username, expected_email = expected
127+
128+
# Test with user inputs
129+
config = get_user_info(args)
130+
assert config.get("username") == expected_username
131+
assert config.get("email") == expected_email
132+
133+
# Test skipping config creation, expecting None values
134+
config = get_user_info(args, skip_config_creation=True)
135+
assert config.get("username") is None
136+
assert config.get("email") is None
137+
122138
confile = Path().home() / "diffpyconfig.json"
123139
assert confile.exists() is False
124140

0 commit comments

Comments
 (0)