-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add type
validation.
#2097
Add type
validation.
#2097
Conversation
Looks good so far!
How about making Something like: def filename(optname, path):
"""Argparse type validator for filename arguments"""
if os.path.isdir(path):
raise UsageError("Must be a filename, given: {0}".format(path))
return path And when registering the option, instead of: type=filename, We use: type=functools.partial(optname='--junitxml'), |
@@ -70,6 +70,18 @@ class UsageError(Exception): | |||
""" error in pytest usage or invocation""" | |||
|
|||
|
|||
def filename(path): |
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.
How about naming this something which makes it more explicit that it is a argparse type validator? How about filename_arg
or something like this?
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.
👍
Oh, |
@@ -1,6 +1,9 @@ | |||
3.0.5.dev0 | |||
========== | |||
|
|||
* Add Argparse style type validation for ``--confcutdir`` and ``--junit-xml`` (`#2089`_). |
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.
Perhaps something more user oriented, for example:
* Now ``--confcutdir`` and ``--junit-xml`` are properly validated if they are directories and filenames, respectively (`#2089`_ and `#2078`_). Thanks to `@lwm`_ for the PR.
With this, you can also remove the entry "An error message is now displayed if --confcutdir
is not a valid directory..." some items below this one, since it replaces it.
Thanks! |
🚀 |
Unless someone else wants more time to review this, I plan to merge this at the end of the day. 😁 |
@@ -70,6 +70,28 @@ class UsageError(Exception): | |||
""" error in pytest usage or invocation""" | |||
|
|||
|
|||
def filename_arg(path, optname): | |||
""" Argparse type validator for filename arguments. |
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.
Extra space here.. s/""" A/"""A/.
But also done like this elsewhere. So let's just keep it.
@lwm |
Ditto. 😁 👍 |
😄 🍷 |
Changes to add to the conversation in #2089.
Something which may not be acceptable is the reduced specificity of the error messages. For example, the validation function
filename
can't refer to--junit-xml
in the error message.Let me know what you think @nicoddemus.