Skip to content

implement a skip_config_creation option in get_user_info #250

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 23 additions & 0 deletions news/config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* allow `get_user_info` to override user input interruption, even if there are no configuration files.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
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