|
1 | 1 | """sqlite3 CLI tests."""
|
| 2 | +importre |
2 | 3 | importsqlite3
|
3 | 4 | importunittest
|
4 | 5 |
|
5 | 6 | fromsqlite3.__main__importmainascli
|
| 7 | +fromtest.supportimportcaptured_stdout,captured_stderr,captured_stdin,requires_subprocess |
| 8 | +fromtest.support.import_helperimportimport_module |
6 | 9 | fromtest.support.os_helperimportTESTFN,unlink
|
7 |
| -fromtest.supportimportcaptured_stdout,captured_stderr,captured_stdin |
8 |
| - |
| 10 | +fromtest.support.pty_helperimportrun_pty |
9 | 11 |
|
10 | 12 | classCommandLineInterface(unittest.TestCase):
|
11 | 13 |
|
@@ -153,5 +155,36 @@ def test_interact_on_disk_file(self):
|
153 | 155 | self.assertIn("(0,)\n",out)
|
154 | 156 |
|
155 | 157 |
|
| 158 | +@requires_subprocess() |
| 159 | +classCompleter(unittest.TestCase): |
| 160 | +@classmethod |
| 161 | +defsetUpClass(cls): |
| 162 | +# Ensure that the readline module is loaded |
| 163 | +# If this fails, the test is skipped because SkipTest will be raised |
| 164 | +readline=import_module("readline") |
| 165 | +ifreadline.backend=="editline": |
| 166 | +raiseunittest.SkipTest("libedit readline is not supported") |
| 167 | + |
| 168 | +deftest_keyword_completion(self): |
| 169 | +script="from sqlite3.__main__ import main; main()" |
| 170 | +# List candidates starting with 'S', there should be multiple matches. |
| 171 | +# Then add 'EL' and complete 'SEL' to 'SELECT'. Quit console in the end |
| 172 | +# to let run_pty() return. |
| 173 | +input=b"S\t\tEL\t 1;\n.quit\n" |
| 174 | +output=run_pty(script,input) |
| 175 | +# Remove control sequences that colorize typed prefix 'S' |
| 176 | +output=re.sub(rb"\x1b\[[0-9;]*[mK]",b"",output) |
| 177 | +self.assertIn(b"SELECT",output) |
| 178 | +self.assertIn(b"SET",output) |
| 179 | +self.assertIn(b"SAVEPOINT",output) |
| 180 | +self.assertIn(b"(1,)",output) |
| 181 | + |
| 182 | +# Keywords are completed in upper case for even lower case user input |
| 183 | +input=b"sel\t\t 1;\n.quit\n" |
| 184 | +output=run_pty(script,input) |
| 185 | +output=re.sub(rb"\x1b\[[0-9;]*[mK]",b"",output) |
| 186 | +self.assertIn(b"SELECT",output) |
| 187 | +self.assertIn(b"(1,)",output) |
| 188 | + |
156 | 189 | if__name__=="__main__":
|
157 | 190 | unittest.main()
|