Skip to content

Commit 708c7d2

Browse files
committed
Add test
1 parent 891364b commit 708c7d2

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Lib/test/test_sqlite3/test_cli.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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 captured_stdout, captured_stderr, captured_stdin, requires_subprocess
8+
from test.support.import_helper import import_module
69
from test.support.os_helper import TESTFN, unlink
7-
from test.support import captured_stdout, captured_stderr, captured_stdin
8-
10+
from test.support.pty_helper import run_pty
911

1012
class CommandLineInterface(unittest.TestCase):
1113

@@ -153,5 +155,34 @@ def test_interact_on_disk_file(self):
153155
self.assertIn("(0,)\n", out)
154156

155157

158+
@requires_subprocess()
159+
class Completer(unittest.TestCase):
160+
@classmethod
161+
def setUpClass(cls):
162+
# Ensure that the readline module is loaded
163+
# If this fails, the test is skipped because SkipTest will be raised
164+
import_module("readline")
165+
166+
def test_keyword_completion(self):
167+
script = "from sqlite3.__main__ import main; main()"
168+
# List candidates starting with 'S', there should be multiple matches.
169+
# Then add 'EL' and complete 'SEL' to 'SELECT'. Quit console in the end
170+
# to let run_pty() return.
171+
input = b"S\t\tEL\t 1;\n.quit\n"
172+
output = run_pty(script, input)
173+
# Remove control sequences that colorize typed prefix 'S'
174+
output = re.sub(rb"\x1b\[[0-9;]*[mK]", b"", output)
175+
self.assertIn(b"SELECT", output)
176+
self.assertIn(b"SET", output)
177+
self.assertIn(b"SAVEPOINT", output)
178+
self.assertIn(b"(1,)", output)
179+
180+
input = b"sel\t\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"(1,)", output)
186+
156187
if __name__ == "__main__":
157188
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)