mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-102130: Support tab completion in cmd for Libedit. (GH-107748)
--- Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
dc824c5dc1
commit
aa5bee30ab
5 changed files with 51 additions and 1 deletions
|
@ -9,7 +9,10 @@ import sys
|
|||
import doctest
|
||||
import unittest
|
||||
import io
|
||||
import textwrap
|
||||
from test import support
|
||||
from test.support.import_helper import import_module
|
||||
from test.support.pty_helper import run_pty
|
||||
|
||||
class samplecmdclass(cmd.Cmd):
|
||||
"""
|
||||
|
@ -259,6 +262,33 @@ class CmdPrintExceptionClass(cmd.Cmd):
|
|||
def default(self, line):
|
||||
print(sys.exc_info()[:2])
|
||||
|
||||
|
||||
@support.requires_subprocess()
|
||||
class CmdTestReadline(unittest.TestCase):
|
||||
def setUpClass():
|
||||
# Ensure that the readline module is loaded
|
||||
# If this fails, the test is skipped because SkipTest will be raised
|
||||
readline = import_module('readline')
|
||||
|
||||
def test_basic_completion(self):
|
||||
script = textwrap.dedent("""
|
||||
import cmd
|
||||
class simplecmd(cmd.Cmd):
|
||||
def do_tab_completion_test(self, args):
|
||||
print('tab completion success')
|
||||
return True
|
||||
|
||||
simplecmd().cmdloop()
|
||||
""")
|
||||
|
||||
# 't' and complete 'ab_completion_test' to 'tab_completion_test'
|
||||
input = b"t\t\n"
|
||||
|
||||
output = run_pty(script, input)
|
||||
|
||||
self.assertIn(b'ab_completion_test', output)
|
||||
self.assertIn(b'tab completion success', output)
|
||||
|
||||
def load_tests(loader, tests, pattern):
|
||||
tests.addTest(doctest.DocTestSuite())
|
||||
return tests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue