Skip to content

load username, email, and orcid number into config files #62

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 1 commit 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
45 changes: 45 additions & 0 deletions src/diffpy/labpdfproc/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from diffpy.labpdfproc.tools import (
known_sources,
load_user_metadata,
load_username_email,
set_input_lists,
set_output_directory,
set_wavelength,
Expand Down Expand Up @@ -241,3 +242,47 @@ def test_load_user_metadata_bad(inputs, msg):
actual_args = get_args(cli_inputs)
with pytest.raises(ValueError, match=msg[0]):
actual_args = load_user_metadata(actual_args)


# Since in both extracting git config or ask users, we take username and email as args.
# Probably define --username and
# --email from get_args()
params7 = [
(
["--username", "stevenhua0320", "--email", "[email protected]", "--orcid", "0009-0003-1947-1857"],
[["username", "stevenhua0320"], ["email", "[email protected]"], ["orcid", "0009-0003-1947-1857"]],
),
(
["--username", "yucongalicechen", "--email", "[email protected]"],
[["username", "yucongalicechen"], ["email", "[email protected]"]],
),
(
["--username", "sbillinge", "--email", "[email protected]"],
[["username", "sbillinge"], ["email", "[email protected]"]],
),
]


@pytest.mark.parametrize("inputs, expected", params7)
def test_load_username_email(inputs, expected):
actual_args = get_args(inputs)
# load username, email, orcid(optional)into config in key-value pairs
actual_args = load_username_email(actual_args)
assert actual_args == expected
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not quite correct. your expected is a list of lists, but it should be args attributes.



params8 = [
(
["--username", "stevenhua0320", "--email", "[email protected]", "--orcid", "ngss-0003-1947-1857"],
["Please provide valid orcid number."],
),
(["--username", "yucongalicechen%$#", "--email", "[email protected]"], ["Please provide valid username."]),
(["--username", "sbllinge", "--email", "sb2896"], ["Please provide valid email."]),
Copy link
Contributor

Choose a reason for hiding this comment

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

typo? Also, I don't think we need this check. The user can put pretty much anything they want for username.

We may want to check if an email is valid

it is better to use non-identifying information for the tests, no actual emails and names. We often use names in the tests that convey meaning about the test, for example, "bad_email" (no @) "[email protected]" for example.

]


@pytest.mark.parametrize("inputs, msg", params8)
def test_load_username_email_bad(inputs, msg):
with pytest.raises(ValueError, match=msg[0]):
actual_args = get_args(inputs)
actual_args = load_username_email(actual_args)
4 changes: 4 additions & 0 deletions src/diffpy/labpdfproc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,7 @@ def load_user_metadata(args):
setattr(args, key, value)
delattr(args, "user_metadata")
return args


def load_username_email(args):
pass
Loading