-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-133363: Fix Cmd completion for lines beginning with !
#133364
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,6 +289,31 @@ def do_tab_completion_test(self, args): | |
| self.assertIn(b'ab_completion_test', output) | ||
| self.assertIn(b'tab completion success', output) | ||
|
|
||
| def test_bang_completion_without_do_shell(self): | ||
| script = textwrap.dedent(""" | ||
| import cmd | ||
| class simplecmd(cmd.Cmd): | ||
| def completedefault(self, text, line, begidx, endidx): | ||
| return ["hello"] | ||
|
|
||
| def default(self, line): | ||
| if line == "! hello": | ||
| print('tab completion success') | ||
| else: | ||
| print('tab completion failure') | ||
| return True | ||
|
|
||
| simplecmd().cmdloop() | ||
| """) | ||
|
|
||
| # '! h' and complete 'ello' to '! hello' | ||
| input = b"! h\t\n" | ||
|
|
||
| output = run_pty(script, input) | ||
|
|
||
| self.assertIn(b'ello', output) | ||
|
||
| self.assertIn(b'tab completion success', output) | ||
|
|
||
| def load_tests(loader, tests, pattern): | ||
| tests.addTest(doctest.DocTestSuite()) | ||
| return tests | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The :class:`cmd.Cmd` class has been fixed to call the ``completedefault`` | ||
| method whenever the ``do_shell`` method is not defined and tab completion is | ||
| requested for a line beginning with ``!``. Previously ``completedefault`` | ||
| was called only if there were no spaces between the ``!`` and the cursor | ||
|
||
| position where tab completion was attempted. | ||
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 should do add check here for
!h\t\n(without space) as well. No need for another method, just another input.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.
That does need to be another method, because the assertions are:
and those would pass if either of the two inputs succeeded, not only if both of them did.
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.
Or maybe we could use a subtest for this? I know how to avoid duplication with pytest, but I'm not really familiar with unittest. Does this work?
Seems to...
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 mean just use the same script and do two
run_pty- I don't think you even need a subtest. It's a very small case.