-
Notifications
You must be signed in to change notification settings - Fork 11
load username and email #63
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this @yucongalicechen .
When you write hte tests I will review those and then I will look at the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see inline
@@ -44,4 +47,10 @@ def user_filesystem(tmp_path): | |||
f.write("good_data.xy \n") | |||
f.write(f"{str(input_dir.resolve() / 'good_data.txt')}\n") | |||
|
|||
user_config_data = {"username": "good_username", "email": "[email protected]"} | |||
with open(conf_dir / "test.json", "w") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to have the correct name here and below... diffpyconf.json
user_config_data = {"username": "good_username", "email": "[email protected]"} | ||
with open(conf_dir / "test.json", "w") as f: | ||
json.dump(user_config_data, f) | ||
with open(conf_dir / "test2.json", "w") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not allowed. We will only check for diffpyconf.json
.
However, we will check for it here, but also in cwd where the programming is running. We would like to test both situations so we can't write that second file in conftest.py but will have to write it in a bespoke test.
def test_load_user_info(monkeypatch, inputs, expected, user_filesystem): | ||
os.chdir(user_filesystem / "conf_dir") | ||
expected_username, expected_email = expected | ||
input_username, input_email, input_config_file = inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not inputting a config file. options are:
- find
diffpyconfig.json
incwd
- failing that, find
diffpyconfig.json
in~
- failing that, check if username and email are provided in the input line
- failing that, trigger the workflow to create
diffpyconfig.json
in~
Then the workflow is:
- If 1 or 3, check that those files contain username/email. If they do continue, if they don't trigger workflow to update
diffpyconfig.json
- If continue above, then check if username/email are provided at the command line. If yes, use them (but don't update config). If not, use the values in config.
- if (4.) above, then use these values to create the
diffpyconfig.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I edited the tests. I included "paths" in @pytest.mark.parametrize because it helps manage different cwd and home directories, not sure if this is the best approach though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This testing structure is hard for me to understand so I am not sure if it is capturing the right information. It may be ok, but not easy to follow.
I was thinking something more like
def test_load_user_info_configfile(monkeypatch, inputs, expected, user_filesystem):
os.chdir(user_filesystem)
# test it works when config file is in home directory
cli_inputs = ["2.5", "data.xy"]
actual_args = get_args(cli_inputs)
actual_args = load_user_info(actual_args)
assert actual_args.username == expected_args_username
assert actual_args.email == expected_args_email
# test it works when config file is in current directory
with open(user_filesystem / 'diffpyconfig.json', "w") as f:
config_data = json.dump(user_data f)
cli_inputs = ["2.5", "data.xy"]
actual_args = get_args(cli_inputs)
actual_args = load_user_info(actual_args)
assert actual_args.username == expected_args_username
assert actual_args.email == expected_args_email
then other tests for other cases
this seems more understandable to me, though your tests may also be working, I just can't follow them too easily.
Okay, yes I also think this is more readable. But this is not testing the config file? I was using different paths because I wanted to test if the config file was modified or not by the inputs. |
I see. I would put the different behaviors in different tests. We usually
use one test to test one behavior.
…On Tue, May 21, 2024 at 6:33 PM Yucong (Alice) Chen < ***@***.***> wrote:
Okay, yes I also think this is more readable. But this is not testing the
config file? I was using different paths because I wanted to test if the
config file was modified or not by the inputs.
—
Reply to this email directly, view it on GitHub
<#63 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAOWUI2XD6VFIEOTYGMNOLZDPDR3AVCNFSM6AAAAABH72HJPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRTGU2DEMJUHA>
.
You are receiving this because you commented.Message ID: <diffpy/diffpy.
***@***.***>
--
Simon Billinge
Professor,
Department of Applied Physics and Applied Mathematics
Columbia University
|
what I mean by that is in this test there is a valid config file that
doesn't need to be updated.....but it can still be overloaded by a command
line input
…On Tue, May 21, 2024 at 6:52 PM Simon Billinge ***@***.***> wrote:
I see. I would put the different behaviors in different tests. We
usually use one test to test one behavior.
On Tue, May 21, 2024 at 6:33 PM Yucong (Alice) Chen <
***@***.***> wrote:
> Okay, yes I also think this is more readable. But this is not testing the
> config file? I was using different paths because I wanted to test if the
> config file was modified or not by the inputs.
>
> —
> Reply to this email directly, view it on GitHub
> <#63 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABAOWUI2XD6VFIEOTYGMNOLZDPDR3AVCNFSM6AAAAABH72HJPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRTGU2DEMJUHA>
> .
> You are receiving this because you commented.Message ID: <diffpy/diffpy.
> ***@***.***>
>
--
Simon Billinge
Professor,
Department of Applied Physics and Applied Mathematics
Columbia University
--
Simon Billinge
Professor,
Department of Applied Physics and Applied Mathematics
Columbia University
|
Yes I get it. It's just my previous codes updated the config files, so I wanted to correct that. The tests are a bit similar so I was thinking of ways to put them together. I now separate the tests into no config files, config file in home directory, and config file in cwd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can test everything (except the missing config file) in one test thinking about it. We just have to test the username and email come out right when the right flow is followed, then we read the config file in conf_dir
and make sure it has the right thing in it.
For the missing config file we will have to delete the config file in home before running the same test. We can call the user home_dir_user
, cwd_user
, cli_user
, input_user
and same for the emails and make sure the right user shows up in args and in the home_dir/diffpyconf.json
These can be handed in in params
What do you think?
|
Yes I think we can combine these. Since this PR is closed, shall I make another PR for the updates? |
No you can use this PR, I didn't know it was closed
…On Tue, May 21, 2024, 8:26 PM Yucong (Alice) Chen ***@***.***> wrote:
Yes I think we can combine these. Since this PR is closed, shall I make
another PR for the updates?
—
Reply to this email directly, view it on GitHub
<#63 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAOWUON6ZRWUG4MAM6E7C3ZDPQ4ZAVCNFSM6AAAAABH72HJPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRTGYZTKNZXGY>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
I see I closed it, but that was in error, I thought it was a stale PR from earlier. My apologies. I think writing a little test private function that asserts that the name and email are correct in args and also that they are correct in the Actually, I thought more about this and I think that this is a capability that we may want to have working across many our diffpy programs (which is why I chose the name of the config file with diffpy not labpdfproc), but from this point of view, having this capability in I think this is also true for the time-stamp and package name-version capabilities. Everywhere we write |
Ah, okay, got it. I'll push my latest changes here and copy over the codes to diffpy.utils. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of quick comments. But are you then going to combine tests into one or two test functions as we discussed? Please reach out if you have questions.
@@ -8,6 +9,8 @@ def user_filesystem(tmp_path): | |||
base_dir = Path(tmp_path) | |||
input_dir = base_dir / "input_dir" | |||
input_dir.mkdir(parents=True, exist_ok=True) | |||
conf_dir = base_dir / "conf_dir" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call it home_dir
instead of conf_dir
to make the intent clearer.
@@ -44,4 +47,8 @@ def user_filesystem(tmp_path): | |||
f.write("good_data.xy \n") | |||
f.write(f"{str(input_dir.resolve() / 'good_data.txt')}\n") | |||
|
|||
user_config_data = {"username": "good_username", "email": "[email protected]"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be home_user
and [email protected]
replaced by #77 |
Uh oh!
There was an error while loading. Please reload this page.