|
4 | 4 |
|
5 | 5 | from sqlite3.__main__ import main as cli
|
6 | 6 | from test.support.os_helper import TESTFN, unlink
|
| 7 | +from test.support.testcase import ExtraAssertions |
7 | 8 | from test.support import captured_stdout, captured_stderr, captured_stdin
|
8 | 9 |
|
9 | 10 |
|
@@ -61,7 +62,7 @@ def test_cli_on_disk_db(self):
|
61 | 62 | self.assertIn("(0,)", out)
|
62 | 63 |
|
63 | 64 |
|
64 |
| -class InteractiveSession(unittest.TestCase): |
| 65 | +class InteractiveSession(unittest.TestCase, ExtraAssertions): |
65 | 66 | MEMORY_DB_MSG = "Connected to a transient in-memory database"
|
66 | 67 | PS1 = "sqlite> "
|
67 | 68 | PS2 = "... "
|
@@ -108,6 +109,38 @@ def test_interact_version(self):
|
108 | 109 | self.assertEqual(out.count(self.PS2), 0)
|
109 | 110 | self.assertIn(sqlite3.sqlite_version, out)
|
110 | 111 |
|
| 112 | + def test_interact_empty_source(self): |
| 113 | + out, err = self.run_cli(commands=("", " ")) |
| 114 | + self.assertIn(self.MEMORY_DB_MSG, err) |
| 115 | + self.assertEndsWith(out, self.PS1) |
| 116 | + self.assertEqual(out.count(self.PS1), 3) |
| 117 | + self.assertEqual(out.count(self.PS2), 0) |
| 118 | + |
| 119 | + def test_interact_dot_commands_unknown(self): |
| 120 | + out, err = self.run_cli(commands=(".unknown_command", )) |
| 121 | + self.assertIn(self.MEMORY_DB_MSG, err) |
| 122 | + self.assertEndsWith(out, self.PS1) |
| 123 | + self.assertEqual(out.count(self.PS1), 2) |
| 124 | + self.assertEqual(out.count(self.PS2), 0) |
| 125 | + self.assertIn("Error", err) |
| 126 | + # test "unknown_command" is pointed out in the error message |
| 127 | + self.assertIn("unknown_command", err) |
| 128 | + |
| 129 | + def test_interact_dot_commands_empty(self): |
| 130 | + out, err = self.run_cli(commands=(".")) |
| 131 | + self.assertIn(self.MEMORY_DB_MSG, err) |
| 132 | + self.assertEndsWith(out, self.PS1) |
| 133 | + self.assertEqual(out.count(self.PS1), 2) |
| 134 | + self.assertEqual(out.count(self.PS2), 0) |
| 135 | + |
| 136 | + def test_interact_dot_commands_with_whitespaces(self): |
| 137 | + out, err = self.run_cli(commands=(".version ", ". version")) |
| 138 | + self.assertIn(self.MEMORY_DB_MSG, err) |
| 139 | + self.assertEqual(out.count(sqlite3.sqlite_version + "\n"), 2) |
| 140 | + self.assertEndsWith(out, self.PS1) |
| 141 | + self.assertEqual(out.count(self.PS1), 3) |
| 142 | + self.assertEqual(out.count(self.PS2), 0) |
| 143 | + |
111 | 144 | def test_interact_valid_sql(self):
|
112 | 145 | out, err = self.run_cli(commands=("SELECT 1;",))
|
113 | 146 | self.assertIn(self.MEMORY_DB_MSG, err)
|
|
0 commit comments