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
Proposed approach for testing CLI arg parsing #1566
Conversation
Combination of HFArgumentParser from transformers with args setup through dataclass like https://github.com/huggingface/transformers/blob/main/examples/research_projects/wav2vec2/run_asr.py#L343 and the As for the current code, testing the parser the way presented seems like testing the argument parser, not the code of this repo module. We put 5 to something that should be a number and it works. In this case it might be useful to check that it always fails if the input is like The `try... except' example here seems to be overreacting to an already solved case — no prevention of new failures. Some future failures may be prevented (though this hypothesis should be tested by turning on failed code and rechecking) after mypy checks are turned back on (even for tests). |
Thanks for the feedback @LSinev ! You're right that these cases don't necessarily cover what we'd like. After thinking about this and checking the videos and the links, I decided to take a different approach and unit test whether each CLI argument, with the exception of booleans, has a type. That way, if you input one without a type unit tests won't pass and if it's a boolean you'll have to delcare a default anyway. Let me know what you think about this approach. |
This seems to be a much better approach.
which also adds |
Thanks!
I checked these and decided not to add a test for them since we use the |
Standardization is good for future improvements and development. Even more, after reading the documentation I see that
with or without this argument, the code is trusted by default. I don't know if this pattern adds an option of |
The behavior of Ironically this is the default behavior of the module 😅 . I figured from that perspective, it was better to explicitly set it (explicit is better than implicit, etc, zen of python) even though we handle it later downstream. I can also check |
I think, your gist example/test may be more insightful with parsing of same set of args (and also setup when no args is provided) by all three defined parsers. I am a bit confused here. As far as I understand now, after this PR (with
Also I suppose (in this case) user or any system calling from commandline consider equivalent all typical ways of setting I checked one with ipython 3.8
and then
Seems, there is no way to turn off trust in remote code. I tried some ways to set false and didn't find any. Without
No confusion for user, just having key/argument set — turns something on, and no trust to remote code if not specified. Found big discussion with many ways to implement (still no pre-commit check which I was actually looking for): https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse |
It seems like you mention, we might want to test this flag specifically - I'll see what I can add from a testing perspective to cover Based on the thread you posted, this looks like the easiest and most accepted answer https://stackoverflow.com/a/59579733. In looking at how HF implements this, they take a similar approach:https://github.com/huggingface/transformers/blob/11bbb505c77a1d29370cf16a964cfe73b7a76340/src/transformers/hf_argparser.py#L34C5-L34C19 so we could go this way too if we wanted. |
If sorted by highest score, there are more interesting answers. Leaving argument like it was before, for me seems the best for now
no argument — no trust, and that's all. |
👍 Works for me, I just changed the two args that take it, but am keeping the ones added for args in cases where action is not |
Hi @veekaybee ! This approach looks good to me. And agree we should leave the |
Thanks so much both for your discussion and comments! This PR is now ready for review. |
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.
Everything LGTM!
* New tests for CLI args * fix spacing * change tests for parsing * add tests, fix parser * remove defaults for store_true
* New tests for CLI args * fix spacing * change tests for parsing * add tests, fix parser * remove defaults for store_true
See discussion here: #1518
Here's an approach to start testing CLI argument parsing:
parse_eval_args
into a separate method,setup_parser
that gets called inparse_eval_args
cli_evaluate
methodLet me know what you think about this approach. If it seems reasonable, I'll add the tests for the rest of the methods and exceptions where it's reasonable.
@LSinev @haileyschoelkopf