Skip to content

Commit b473fe9

Browse files
committed
Handle empty string input; Add test; Improve news entry
1 parent 4023fb1 commit b473fe9

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Lib/sqlite3/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def runsource(self, source, filename="<input>", symbol="single"):
4848
Return True if more input is needed; buffering is done automatically.
4949
Return False if input is a complete statement ready for execution.
5050
"""
51+
if not source or source.isspace():
52+
return False
5153
if source[0] == ".":
5254
match source[1:].strip():
5355
case "version":
@@ -57,7 +59,8 @@ def runsource(self, source, filename="<input>", symbol="single"):
5759
case "quit":
5860
sys.exit(0)
5961
case _:
60-
print('Error: unknown command or invalid arguments: "spam". Enter ".help" for help')
62+
print('Error: unknown command or invalid arguments: '
63+
f'"{source[1:].strip()}". Enter ".help" for help')
6164
else:
6265
if not sqlite3.complete_statement(source):
6366
return True

Lib/test/test_sqlite3/test_cli.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,28 @@ def test_interact_version(self):
116116
self.assertEqual(out.count(self.PS2), 0)
117117
self.assertIn(sqlite3.sqlite_version, out)
118118

119-
def test_interact_dot_commands(self):
120-
# test dot commands with whitespaces and unknow dot commands
121-
out, err = self.run_cli(commands=(".version ", ". version", ".spam"))
119+
def test_interact_empty_source(self):
120+
out, err = self.run_cli(commands=("", " "))
121+
self.assertIn(self.MEMORY_DB_MSG, err)
122+
self.assertEndsWith(out, self.PS1)
123+
self.assertEqual(out.count(self.PS1), 3)
124+
self.assertEqual(out.count(self.PS2), 0)
125+
126+
def test_interact_dot_commands_unknown(self):
127+
out, err = self.run_cli(commands=(".unknown_command",))
128+
self.assertIn(self.MEMORY_DB_MSG, err)
129+
self.assertEndsWith(out, self.PS1)
130+
self.assertEqual(out.count(self.PS1), 2)
131+
self.assertEqual(out.count(self.PS2), 0)
132+
self.assertIn('Error: unknown command or invalid arguments: "unknown_command"', out)
133+
134+
def test_interact_dot_commands_with_whitespaces(self):
135+
out, err = self.run_cli(commands=(".version ", ". version"))
122136
self.assertIn(self.MEMORY_DB_MSG, err)
123137
self.assertEqual(out.count(sqlite3.sqlite_version + "\n"), 2)
124138
self.assertEndsWith(out, self.PS1)
125-
self.assertEqual(out.count(self.PS1), 4)
139+
self.assertEqual(out.count(self.PS1), 3)
126140
self.assertEqual(out.count(self.PS2), 0)
127-
self.assertIn("Error", out)
128141

129142
def test_interact_valid_sql(self):
130143
out, err = self.run_cli(commands=("SELECT 1;",))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
fix dot commands with trailing spaces are mistaken for multi-line SQL
2-
statements in the sqlite3 command-line interface
1+
Fix dot commands with trailing spaces are mistaken for multi-line SQL
2+
statements in the sqlite3 command-line interface.

0 commit comments

Comments
 (0)