Skip to content

Commit ecb2bf0

Browse files
pythongh-108617: Extend interactive session tests for sqlite3 (pythonGH-108556)
1 parent c884784 commit ecb2bf0

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

Lib/test/test_sqlite3/test_cli.py

+32-6
Original file line numberDiff line numberDiff line change
@@ -87,42 +87,68 @@ def run_cli(self, *args, commands=()):
8787
def test_interact(self):
8888
out, err = self.run_cli()
8989
self.assertIn(self.MEMORY_DB_MSG, err)
90-
self.assertIn(self.PS1, out)
90+
self.assertIn(self.MEMORY_DB_MSG, err)
91+
self.assertTrue(out.endswith(self.PS1))
92+
self.assertEqual(out.count(self.PS1), 1)
93+
self.assertEqual(out.count(self.PS2), 0)
9194

9295
def test_interact_quit(self):
9396
out, err = self.run_cli(commands=(".quit",))
94-
self.assertIn(self.PS1, out)
97+
self.assertIn(self.MEMORY_DB_MSG, err)
98+
self.assertTrue(out.endswith(self.PS1))
99+
self.assertEqual(out.count(self.PS1), 1)
100+
self.assertEqual(out.count(self.PS2), 0)
95101

96102
def test_interact_version(self):
97103
out, err = self.run_cli(commands=(".version",))
98104
self.assertIn(self.MEMORY_DB_MSG, err)
105+
self.assertIn(sqlite3.sqlite_version + "\n", out)
106+
self.assertTrue(out.endswith(self.PS1))
107+
self.assertEqual(out.count(self.PS1), 2)
108+
self.assertEqual(out.count(self.PS2), 0)
99109
self.assertIn(sqlite3.sqlite_version, out)
100110

101111
def test_interact_valid_sql(self):
102112
out, err = self.run_cli(commands=("SELECT 1;",))
103113
self.assertIn(self.MEMORY_DB_MSG, err)
104-
self.assertIn("(1,)", out)
114+
self.assertIn("(1,)\n", out)
115+
self.assertTrue(out.endswith(self.PS1))
116+
self.assertEqual(out.count(self.PS1), 2)
117+
self.assertEqual(out.count(self.PS2), 0)
118+
119+
def test_interact_incomplete_multiline_sql(self):
120+
out, err = self.run_cli(commands=("SELECT 1",))
121+
self.assertIn(self.MEMORY_DB_MSG, err)
122+
self.assertTrue(out.endswith(self.PS2))
123+
self.assertEqual(out.count(self.PS1), 1)
124+
self.assertEqual(out.count(self.PS2), 1)
105125

106126
def test_interact_valid_multiline_sql(self):
107127
out, err = self.run_cli(commands=("SELECT 1\n;",))
108128
self.assertIn(self.MEMORY_DB_MSG, err)
109129
self.assertIn(self.PS2, out)
110-
self.assertIn("(1,)", out)
130+
self.assertIn("(1,)\n", out)
131+
self.assertTrue(out.endswith(self.PS1))
132+
self.assertEqual(out.count(self.PS1), 2)
133+
self.assertEqual(out.count(self.PS2), 1)
111134

112135
def test_interact_invalid_sql(self):
113136
out, err = self.run_cli(commands=("sel;",))
114137
self.assertIn(self.MEMORY_DB_MSG, err)
115138
self.assertIn("OperationalError (SQLITE_ERROR)", err)
139+
self.assertTrue(out.endswith(self.PS1))
140+
self.assertEqual(out.count(self.PS1), 2)
141+
self.assertEqual(out.count(self.PS2), 0)
116142

117143
def test_interact_on_disk_file(self):
118144
self.addCleanup(unlink, TESTFN)
119145

120146
out, err = self.run_cli(TESTFN, commands=("CREATE TABLE t(t);",))
121147
self.assertIn(TESTFN, err)
122-
self.assertIn(self.PS1, out)
148+
self.assertTrue(out.endswith(self.PS1))
123149

124150
out, _ = self.run_cli(TESTFN, commands=("SELECT count(t) FROM t;",))
125-
self.assertIn("(0,)", out)
151+
self.assertIn("(0,)\n", out)
126152

127153

128154
if __name__ == "__main__":

0 commit comments

Comments
 (0)