Skip to content

Commit

Permalink
ploomber#892 pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallwhiteorg committed Oct 6, 2023
1 parent 5946e65 commit 826fd4e
Showing 1 changed file with 55 additions and 47 deletions.
102 changes: 55 additions & 47 deletions src/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,53 +1187,61 @@ def test_database_in_directory_that_doesnt_exist(tmp_empty, uri, expected):
assert expected in str(excinfo.value)


query_expected_outputs = [
("SELECT * FROM table", True),
("SUMMARIZE table", True),
("FROM table SELECT *", True),
("UPDATE table SET column=value", False),
("INSERT INTO table (column) VALUES (value)", False),
("INSERT INTO table SELECT * FROM table2", False),
("UPDATE table SET column=10 WHERE column IN (SELECT column FROM table2)", False),
("WITH x AS (SELECT * FROM table) SELECT * FROM x", True),
("WITH x AS (SELECT * FROM table) INSERT INTO y SELECT * FROM x", False),
("", False),
("DELETE FROM table", False),
("WITH summarize AS (SELECT * FROM table) SELECT * FROM summarize", True),
(
"WITH summarize AS (SELECT * FROM table) INSERT INTO y SELECT * FROM summarize",
False,
),
("UPDATE table SET column='SELECT'", False),
("CREATE TABLE SELECT (id INT)", False),
("CREATE TABLE x (SELECT VARCHAR(100))", False),
('INSTALL "x"', False),
("SELECT SUM(column) FILTER (WHERE column > 10) FROM table", True),
("SELECT column FROM (SELECT * FROM table WHERE column = 'SELECT') AS x", True),
# Invalid SQL returns false
("INSERT INTO table (column) VALUES ('SELECT')", False),
pytest.param(
"SELECT FROM table WHERE (column = 'value'",
False,
marks=pytest.mark.xfail(
reason="sqlparse does not notice the missing close paren"
@pytest.mark.parametrize(
"query, expected_output",
[
("SELECT * FROM table", True),
("SUMMARIZE table", True),
("FROM table SELECT *", True),
("UPDATE table SET column=value", False),
("INSERT INTO table (column) VALUES (value)", False),
("INSERT INTO table SELECT * FROM table2", False),
(
"UPDATE table SET column=10 WHERE column IN (SELECT column FROM table2)",
False,
),
("WITH x AS (SELECT * FROM table) SELECT * FROM x", True),
("WITH x AS (SELECT * FROM table) INSERT INTO y SELECT * FROM x", False),
("", False),
("DELETE FROM table", False),
("WITH summarize AS (SELECT * FROM table) SELECT * FROM summarize", True),
(
"""
WITH summarize AS (SELECT * FROM table)
INSERT INTO y SELECT * FROM summarize
""",
False,
),
("UPDATE table SET column='SELECT'", False),
("CREATE TABLE SELECT (id INT)", False),
("CREATE TABLE x (SELECT VARCHAR(100))", False),
('INSTALL "x"', False),
("SELECT SUM(column) FILTER (WHERE column > 10) FROM table", True),
("SELECT column FROM (SELECT * FROM table WHERE column = 'SELECT') AS x", True),
# Invalid SQL returns false
("INSERT INTO table (column) VALUES ('SELECT')", False),
# Comments have no effect
("-- SELECT * FROM table", False),
("-- SELECT * FROM table\nSELECT * FROM table", True),
("-- SELECT * FROM table\nINSERT INTO table SELECT * FROM table2", False),
("-- FROM table SELECT *", False),
("-- FROM table SELECT *\n/**/FROM/**/ table SELECT */**/", True),
("-- FROM table SELECT *\nINSERT INTO table FROM table2 SELECT *", False),
(
"""
-- INSERT INTO table SELECT * FROM table2
SELECT /**/ * FROM tbl /**/
""",
True,
),
),
# Comments have no effect
("-- SELECT * FROM table", False),
("-- SELECT * FROM table\nSELECT * FROM table", True),
("-- SELECT * FROM table\nINSERT INTO table SELECT * FROM table2", False),
("-- FROM table SELECT *", False),
("-- FROM table SELECT *\n/**/FROM/**/ table SELECT */**/", True),
("-- FROM table SELECT *\nINSERT INTO table FROM table2 SELECT *", False),
("-- INSERT INTO table SELECT * FROM table2\nSELECT /**/ * FROM tbl /**/", True),
(
"-- INSERT INTO table SELECT * FROM table2\n/**/SUMMARIZE/**/ /**//**/tbl/**/",
True,
),
]


@pytest.mark.parametrize("query, expected_output", query_expected_outputs)
(
"""
-- INSERT INTO table SELECT * FROM table2
/**/SUMMARIZE/**/ /**//**/tbl/**/
""",
True,
),
],
)
def test_detect_duckdb_summarize_or_select(query, expected_output):
assert detect_duckdb_summarize_or_select(query) == expected_output

0 comments on commit 826fd4e

Please sign in to comment.