forked from catherinedevlin/ipython-sql
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16efc63
commit 2103e72
Showing
5 changed files
with
101 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import pytest | ||
|
||
from sqlalchemy.exc import OperationalError | ||
|
||
|
||
def test_syntax_error_no_suggestion(ip, capsys): | ||
ip.run_cell_magic( | ||
"sql", | ||
"", | ||
""" | ||
sqlite:// | ||
SELECT FROM author; | ||
""", | ||
) | ||
out, _ = capsys.readouterr() | ||
assert '(sqlite3.OperationalError) near "FROM": syntax error' in out | ||
assert ( | ||
"If you need help solving this issue, " | ||
"send us a message: https://ploomber.io/community" in out | ||
) | ||
|
||
|
||
def test_syntax_error_description(ip, capsys): | ||
ip.run_cell_magic( | ||
"sql", | ||
"", | ||
""" | ||
sqlite:// | ||
SELECT first_(name FROM author; | ||
""", | ||
) | ||
out, _ = capsys.readouterr() | ||
assert '(sqlite3.OperationalError) near "FROM": syntax error' in out | ||
assert "Syntax Error: Expecting ) at Line 1, Column 20" in out | ||
assert ( | ||
"If you need help solving this issue, " | ||
"send us a message: https://ploomber.io/community" in out | ||
) | ||
|
||
|
||
def test_syntax_error_suggestion(ip, capsys): | ||
ip.run_cell_magic( | ||
"sql", | ||
"", | ||
""" | ||
sqlite:// | ||
ALTER TABLE author RENAME new_author; | ||
""", | ||
) | ||
out, _ = capsys.readouterr() | ||
assert "Did you mean : ['ALTER TABLE author RENAME TO new_author']" in out | ||
assert ( | ||
"If you need help solving this issue, " | ||
"send us a message: https://ploomber.io/community" in out | ||
) | ||
|
||
|
||
def test_query_syntax_error(ip, capsys): | ||
ip.run_line_magic("config", "SqlMagic.short_errors = False") | ||
with pytest.raises(OperationalError): | ||
ip.run_cell_magic( | ||
"sql", | ||
"", | ||
""" | ||
sqlite:// | ||
SELECT FROM author; | ||
""", | ||
) | ||
out, _ = capsys.readouterr() | ||
assert ( | ||
"If you need help solving this issue, " | ||
"send us a message: https://ploomber.io/community" in out | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters