Skip to content

Commit 06cf0a7

Browse files
committed
Add comment why use plain prompt for test assertion in test_cli.Completion
1 parent ff4bcf6 commit 06cf0a7

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

Lib/test/test_sqlite3/test_cli.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ def test_color(self):
212212
@requires_subprocess()
213213
@force_not_colorized_test_class
214214
class Completion(unittest.TestCase):
215-
PS1_NO_COLOR = "sqlite> "
215+
# run_pty() creates a real terminal environment, where sqlite3 CLI
216+
# SqliteInteractiveConsole invokes GNU Readline for input. Readline's
217+
# _rl_strip_prompt() strips \001 and \002 from the output, so test
218+
# assertions use the plain prompt. See
219+
# https://cgit.git.savannah.gnu.org/cgit/readline.git/tree/display.c
220+
PS1 = "sqlite> "
216221

217222
@classmethod
218223
def setUpClass(cls):
@@ -288,7 +293,7 @@ def test_complete_table_indexes_triggers_views(self):
288293
output = self.write_input(input_)
289294
lines = output.decode().splitlines()
290295
indices = [i for i, line in enumerate(lines)
291-
if line.startswith(self.PS1_NO_COLOR)]
296+
if line.startswith(self.PS1)]
292297
start, end = indices[-3], indices[-2]
293298
candidates = [l.strip() for l in lines[start+1:end]]
294299
self.assertEqual(candidates,
@@ -327,7 +332,7 @@ def test_complete_columns(self):
327332
output = self.write_input(input_)
328333
lines = output.decode().splitlines()
329334
indices = [
330-
i for i, line in enumerate(lines) if line.startswith(self.PS1_NO_COLOR)
335+
i for i, line in enumerate(lines) if line.startswith(self.PS1)
331336
]
332337
start, end = indices[-3], indices[-2]
333338
candidates = [l.strip() for l in lines[start+1:end]]
@@ -365,7 +370,7 @@ def test_complete_schemata(self):
365370
output = self.write_input(input_)
366371
lines = output.decode().splitlines()
367372
indices = [
368-
i for i, line in enumerate(lines) if line.startswith(self.PS1_NO_COLOR)
373+
i for i, line in enumerate(lines) if line.startswith(self.PS1)
369374
]
370375
start, end = indices[-4], indices[-3]
371376
candidates = [l.strip() for l in lines[start+1:end]]
@@ -385,7 +390,7 @@ def test_complete_no_match(self):
385390
lines = output.decode().splitlines()
386391
indices = (
387392
i for i, line in enumerate(lines, 1)
388-
if line.startswith(f"{self.PS1_NO_COLOR}xyzzy")
393+
if line.startswith(f"{self.PS1}xyzzy")
389394
)
390395
line_num = next(indices, -1)
391396
self.assertNotEqual(line_num, -1)
@@ -419,7 +424,7 @@ def test_complete_no_input(self):
419424
lines = output.decode().splitlines()
420425
indices = [
421426
i for i, line in enumerate(lines)
422-
if line.startswith(self.PS1_NO_COLOR)
427+
if line.startswith(self.PS1)
423428
]
424429
self.assertEqual(len(indices), 2)
425430
start, end = indices

0 commit comments

Comments
 (0)