Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/diffpy/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _create_global_config(args):
return return_bool


def get_user_info(args=None):
def get_user_info(args=None, skip_config_creation=False):
"""
Get username and email configuration.

Expand All @@ -114,6 +114,9 @@ def get_user_info(args=None):
config_bool = True
global_config = load_config(Path().home() / "diffpyconfig.json")
local_config = load_config(Path().cwd() / "diffpyconfig.json")
if skip_config_creation:
config = _sorted_merge(clean_dict(global_config), clean_dict(local_config), clean_dict(args))
return config
if global_config is None and local_config is None:
print(
"No global configuration file was found containing "
Expand Down
18 changes: 17 additions & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def _run_tests(inputs, expected):
config = get_user_info(args)
assert config.get("username") == expected_username
assert config.get("email") == expected_email
config = get_user_info(args, skip_config_creation=True)
assert config.get("username") == expected_username
assert config.get("email") == expected_email
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we can reuse this run_test function for most test cases for different skip_config_creation except when there're no inputs or files, so I added this here



params_user_info_with_home_conf_file = [
Expand Down Expand Up @@ -118,7 +121,20 @@ def test_get_user_info_no_conf_file_no_inputs(monkeypatch, inputsa, inputsb, exp
os.remove(Path().home() / "diffpyconfig.json")
inp_iter = iter(inputsb)
monkeypatch.setattr("builtins.input", lambda _: next(inp_iter))
_run_tests(inputsa, expected)

args = {"username": inputsa[0], "email": inputsa[1]}
expected_username, expected_email = expected

# Test with user inputs
config = get_user_info(args)
assert config.get("username") == expected_username
assert config.get("email") == expected_email

# Test skipping config creation, expecting None values
config = get_user_info(args, skip_config_creation=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little confused here....isn't this getting args as written?

assert config.get("username") is None
assert config.get("email") is None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to rewrite this from run_test for no args/inputs/config files


confile = Path().home() / "diffpyconfig.json"
assert confile.exists() is False

Expand Down
Loading