forked from catherinedevlin/ipython-sql
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ploomber:master' into 658-snippet-support-sqlcmd
- Loading branch information
Showing
6 changed files
with
209 additions
and
57 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 |
---|---|---|
@@ -1,29 +1,49 @@ | ||
import logging | ||
import pytest | ||
|
||
|
||
def test_auto_commit_mode_on(ip_with_duckDB, caplog): | ||
with caplog.at_level(logging.DEBUG): | ||
ip_with_duckDB.run_cell("%config SqlMagic.autocommit=True") | ||
ip_with_duckDB.run_cell("%sql CREATE TABLE weather4 (city VARCHAR,);") | ||
assert caplog.record_tuples == [ | ||
@pytest.mark.parametrize( | ||
"ip, exp", | ||
[ | ||
( | ||
"ip_with_duckDB", | ||
"'duckdb.DuckDBPyConnection' object has no attribute " | ||
"'set_isolation_level'\n", | ||
), | ||
( | ||
"root", | ||
logging.DEBUG, | ||
"The database driver doesn't support such AUTOCOMMIT " | ||
"execution option\nPerhaps you can try running a manual " | ||
"COMMIT command\nMessage from the database driver\n\t" | ||
"Exception: 'duckdb.DuckDBPyConnection' object has no attribute" | ||
" 'set_isolation_level'\n", | ||
) | ||
] | ||
"ip_with_duckDB_native", | ||
"'CustomSession' object has no attribute '_has_events'", | ||
), | ||
], | ||
) | ||
def test_auto_commit_mode_on(ip, exp, caplog, request): | ||
ip = request.getfixturevalue(ip) | ||
with caplog.at_level(logging.DEBUG): | ||
ip.run_cell("%config SqlMagic.autocommit=True") | ||
ip.run_cell("%sql CREATE TABLE weather4 (city VARCHAR,);") | ||
assert caplog.record_tuples[0][0] == "root" | ||
assert caplog.record_tuples[0][1] == logging.DEBUG | ||
assert ( | ||
"The database driver doesn't support such AUTOCOMMIT" | ||
in caplog.record_tuples[0][2] | ||
) | ||
assert exp in caplog.record_tuples[0][2] | ||
|
||
|
||
def test_auto_commit_mode_off(ip_with_duckDB, caplog): | ||
@pytest.mark.parametrize( | ||
"ip", | ||
[ | ||
("ip_with_duckDB"), | ||
("ip_with_duckDB_native"), | ||
], | ||
) | ||
def test_auto_commit_mode_off(ip, caplog, request): | ||
ip = request.getfixturevalue(ip) | ||
with caplog.at_level(logging.DEBUG): | ||
ip_with_duckDB.run_cell("%config SqlMagic.autocommit=False") | ||
ip_with_duckDB.run_cell("%sql CREATE TABLE weather (city VARCHAR,);") | ||
ip.run_cell("%config SqlMagic.autocommit=False") | ||
ip.run_cell("%sql CREATE TABLE weather (city VARCHAR,);") | ||
# Check there is no message gets printed | ||
assert caplog.record_tuples == [] | ||
# Check the tables is created | ||
tables_out = ip_with_duckDB.run_cell("%sql SHOW TABLES;").result | ||
tables_out = ip.run_cell("%sql SHOW TABLES;").result | ||
assert any("weather" == table[0] for table in tables_out) |
Oops, something went wrong.