Skip to content

bpo-35270: Cmd.complete: use completedefault also with cmd=None #10588

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge in the main branch
  • Loading branch information
encukou committed Jan 3, 2024
commit e3e256cc7af0506d954edaaeb84d334fa52f78ad
30 changes: 13 additions & 17 deletions Lib/test/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
import textwrap
from test import support
from unittest.mock import patch

try:
import readline
except ImportError:
readline = None

from test.support.import_helper import import_module
from test.support.pty_helper import run_pty

class samplecmdclass(cmd.Cmd):
"""
Expand Down Expand Up @@ -251,21 +247,21 @@ def test_input_reset_at_EOF(self):
"(Cmd) \n"
"(Cmd) *** Unknown syntax: EOF\n"))

@unittest.skipIf(readline is None, 'No readline module')
@patch('readline.get_line_buffer', return_value='foo')
@patch('readline.get_begidx', return_value=2)
@patch('readline.get_endidx', return_value=2)
def test_complete_with_None_from_parseline(self, *args):
readline = import_module('readline')

class CustomCmd(cmd.Cmd):
def parseline(self, line):
return None, None, line
with (patch('readline.get_line_buffer', return_value='foo'),
patch('readline.get_begidx', return_value=2),
patch('readline.get_endidx', return_value=2)):
class CustomCmd(cmd.Cmd):
def parseline(self, line):
return None, None, line

def completedefault(self, *args):
return ['via_completedefault']
def completedefault(self, *args):
return ['via_completedefault']

c = CustomCmd()
self.assertEqual(c.complete("", 0), "via_completedefault")
c = CustomCmd()
self.assertEqual(c.complete("", 0), "via_completedefault")


class CmdPrintExceptionClass(cmd.Cmd):
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.