Display help when ran without any arguments#1
Display help when ran without any arguments#1millefalcon wants to merge 8 commits intocdunklau:masterfrom
Conversation
|
Thanks! Can you see if you can write a test for this? |
|
Sure :) |
|
As discussed on IRC, please just make the tests pass on py2, more work is apparently necessary to get them passing on py3, will handle this separately (in #4 ). Also make a CONTRIBUTORS file with yourself in it, formatted like |
|
This seems a bit weird, since it doesn't need any change on
✘ gistenv ~/.../cdunklu/gistit master ../gistenv/bin/python2 gistit.py
usage: gistit.py [-h] [--token TOKEN] {create,token} ...
gistit.py: error: too few arguments
gistenv ~/.../cdunklu/gistit master ● ../gistenv/bin/python3 gistit.py
Traceback (most recent call last):
File "gistit.py", line 245, in <module>
main()
File "gistit.py", line 104, in main
command = args.func
AttributeError: 'Namespace' object has no attribute 'func' |
|
Sure. Will do
…On Tue, Dec 31, 2019, 18:41 Colin Dunklau ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In gistit.py
<#1 (comment)>:
> @@ -98,6 +98,9 @@ def make_parser():
def main():
parser = make_parser()
args = parser.parse_args()
+ if args.command is None:
+ parser.print_help()
+ sys.exit(1)
Prefer parser.exit(1)
------------------------------
In gistit.py
<#1 (comment)>:
> @@ -335,3 +338,18 @@ def test_token(self):
def test_create(self):
self.assertReadmeContainsOutput(['create', '-h'])
+
+class SimpleRun(unittest.TestCase):
+ def setUp(self):
+ cmd_args = [sys.executable, 'gistit.py', '--help']
+ self.help_output_lines = subprocess.Popen(
+ cmd_args,
+ stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
+
+ def test_no_args(self):
+ cmd_args = [sys.executable, 'gistit.py']
+ self.test_output_lines = subprocess.Popen(
+ cmd_args,
+ stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
+ self.assertTrue(self.help_output_lines == self.test_output_lines)
Use assertEqual instead, for a better error message.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1?email_source=notifications&email_token=AEBSPHH6U3OE2PKJK24GJ6TQ3NAHPA5CNFSM4KBTF3NKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCQN6J4Q#pullrequestreview-337372402>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEBSPHFKOM3TTEHNSIASUSTQ3NAHPANCNFSM4KBTF3NA>
.
|
|
I merged PR #5 and fixed the existing tests so they work on py3 as well, so feel free to update your branch with master and adjust as necessary. |
|
So i am wondering, how to overcome the different behavior between One thing i saw is we could set the ...
parser.add_argument(
'--token', '-t', default=default_token_file,
help='Path to token file')
subparsers = parser.add_subparsers(
dest='command', help='Available commands')
subparsers.required = True # <--- here
create_parser = subparsers.add_parser('create', help='Create new gist')
...Then, we don't need to have the fix that i raised the PR for :) |
Looks like that was added in 3.7, but I'd like to keep 3.6 support (and 2.7, at least for now). |
|
Okay. Then this new fix will fail for the test in 2.7 :| |
|
I think comparing the outputs is unnecessary. Instead, just check that |
|
Okay. I will update with that |
If ran without any arguments, it will raise the error: