Skip to content

Commit 344c3e8

Browse files
committed
Add test
1 parent 8a75b41 commit 344c3e8

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Lib/test/test_sqlite3/test_cli.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
"""sqlite3 CLI tests."""
2+
import re
23
import sqlite3
34
import unittest
45

56
from sqlite3.__main__ import main as cli
7+
from test.support.import_helper import import_module
68
from test.support.os_helper import TESTFN, unlink
9+
from test.support.pty_helper import run_pty
710
from test.support import (
811
captured_stdout,
912
captured_stderr,
1013
captured_stdin,
1114
force_not_colorized,
15+
requires_subprocess,
1216
)
1317

14-
1518
class CommandLineInterface(unittest.TestCase):
1619

1720
def _do_test(self, *args, expect_success=True):
@@ -159,5 +162,36 @@ def test_interact_on_disk_file(self):
159162
self.assertIn("(0,)\n", out)
160163

161164

165+
@requires_subprocess()
166+
class Completer(unittest.TestCase):
167+
@classmethod
168+
def setUpClass(cls):
169+
# Ensure that the readline module is loaded
170+
# If this fails, the test is skipped because SkipTest will be raised
171+
readline = import_module("readline")
172+
if readline.backend == "editline":
173+
raise unittest.SkipTest("libedit readline is not supported")
174+
175+
def test_keyword_completion(self):
176+
script = "from sqlite3.__main__ import main; main()"
177+
# List candidates starting with 'S', there should be multiple matches.
178+
# Then add 'EL' and complete 'SEL' to 'SELECT'. Quit console in the end
179+
# to let run_pty() return.
180+
input = b"S\t\tEL\t 1;\n.quit\n"
181+
output = run_pty(script, input)
182+
# Remove control sequences that colorize typed prefix 'S'
183+
output = re.sub(rb"\x1b\[[0-9;]*[mK]", b"", output)
184+
self.assertIn(b"SELECT", output)
185+
self.assertIn(b"SET", output)
186+
self.assertIn(b"SAVEPOINT", output)
187+
self.assertIn(b"(1,)", output)
188+
189+
# Keywords are completed in upper case for even lower case user input
190+
input = b"sel\t\t 1;\n.quit\n"
191+
output = run_pty(script, input)
192+
output = re.sub(rb"\x1b\[[0-9;]*[mK]", b"", output)
193+
self.assertIn(b"SELECT", output)
194+
self.assertIn(b"(1,)", output)
195+
162196
if __name__ == "__main__":
163197
unittest.main()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Support keyword completion for :mod:`sqlite3` command-line interface.
1+
Support keyword completion in the :mod:`sqlite3` command-line interface.

0 commit comments

Comments
 (0)