-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-133390: Support SQL keyword completion for sqlite3 CLI #133393
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 1 commit
1b96be3
5e50871
c1941cb
47daca5
c54c2f6
8fff491
a766805
da55014
ca587e0
311b4f3
70f46e9
9d03730
bfcff38
805d997
276b4a7
09eeac8
fc57d71
c508069
231b9e7
121b069
90a86cf
5170733
b40982a
226ea9f
4eebbd9
3f9b2c1
0410fa2
bd0b9ce
35a17e7
3dd16b3
f3ea951
a493ad3
34cfc78
477b48b
68bb4f3
4c3b122
4f1221e
3865131
8d4f659
ccd98a5
d681425
ffd0f02
6188a6d
370dd8b
16b1674
ea108ba
13b527e
fafd1bb
140818c
fd6c89e
588fb6a
5623f16
88c8d59
b3a2b88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import unittest | ||
|
|
||
| from sqlite3.__main__ import main as cli | ||
| from sqlite3._completer import KEYWORDS | ||
| from test.support.import_helper import import_module | ||
| from test.support.os_helper import TESTFN, unlink | ||
| from test.support.pty_helper import run_pty | ||
|
|
@@ -205,22 +206,18 @@ def test_color(self): | |
| '\x1b[35mnear "sel": syntax error\x1b[0m', err) | ||
|
|
||
| @requires_subprocess() | ||
| class Completer(unittest.TestCase): | ||
| class CompletionTest(unittest.TestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| # Ensure that the readline module is loaded | ||
| # If this fails, the test is skipped because SkipTest will be raised | ||
| readline = import_module("readline") | ||
| if readline.backend == "editline": | ||
| raise unittest.SkipTest("libedit readline is not supported") | ||
|
picnixz marked this conversation as resolved.
|
||
|
|
||
| def test_keyword_completion(self): | ||
|
picnixz marked this conversation as resolved.
Outdated
|
||
| script = "from sqlite3.__main__ import main; main()" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just use run_cli from the interactiveconsole tests above?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then where are the completion candidates sent? The commands should be executed. |
||
| # List candidates starting with 'S', there should be multiple matches. | ||
| # Then add 'EL' and complete 'SEL' to 'SELECT'. Quit console in the end | ||
| # to let run_pty() return. | ||
| input = b"S\t\tEL\t 1;\n.quit\n" | ||
| output = run_pty(script, input) | ||
| output = run_pty(script, input, env={"NO_COLOR": "1"}) | ||
| # Remove control sequences that colorize typed prefix 'S' | ||
| output = re.sub(rb"\x1b\[[0-9;]*[mK]", b"", output) | ||
| self.assertIn(b"SELECT", output) | ||
|
|
@@ -235,5 +232,24 @@ def test_keyword_completion(self): | |
| self.assertIn(b"SELECT", output) | ||
| self.assertIn(b"(1,)", output) | ||
|
|
||
|
picnixz marked this conversation as resolved.
|
||
| def test_nothing_to_complete(self): | ||
| script = "from sqlite3.__main__ import main; main()" | ||
| input = b"zzzz\t;\n.quit\n" | ||
| output = run_pty(script, input, env={"NO_COLOR": "1"}) | ||
| output = re.sub(rb"\x1b\[[0-9;]*[mK]", b"", output) | ||
|
erlend-aasland marked this conversation as resolved.
Outdated
|
||
| for keyword in KEYWORDS: | ||
| self.assertNotRegex(output, rf"\b{keyword}\b".encode("utf-8")) | ||
|
|
||
| def test_completion_order(self): | ||
| script = "from sqlite3.__main__ import main; main()" | ||
| input = b"S\t\n.quit\n" | ||
| output = run_pty(script, input, env={"NO_COLOR": "1"}) | ||
| output = re.sub(rb"\x1b\[[0-9;]*[mK]", b"", output).strip() | ||
| savepoint_idx = output.find(b"SAVEPOINT") | ||
| select_idx = output.find(b"SELECT") | ||
| set_idx = output.find(b"SET") | ||
| self.assertTrue(0 <= savepoint_idx < select_idx < set_idx) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
picnixz marked this conversation as resolved.
|
||
| unittest.main() | ||

Uh oh!
There was an error while loading. Please reload this page.