-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into check_with
- Loading branch information
Showing
4 changed files
with
80 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
|
||
from sql_metadata import Parser | ||
|
||
|
||
def test_insert_query(): | ||
queries = [ | ||
"INSERT IGNORE /* foo */ INTO bar VALUES (1, '123', '2017-01-01');", | ||
"/* foo */ INSERT IGNORE INTO bar VALUES (1, '123', '2017-01-01');" | ||
"-- foo\nINSERT IGNORE INTO bar VALUES (1, '123', '2017-01-01');" | ||
"# foo\nINSERT IGNORE INTO bar VALUES (1, '123', '2017-01-01');", | ||
] | ||
|
||
for query in queries: | ||
assert "INSERT" == Parser(query).query_type | ||
|
||
|
||
def test_select_query(): | ||
queries = [ | ||
"SELECT /* foo */ foo FROM bar", | ||
"/* foo */ SELECT foo FROM bar" | ||
"-- foo\nSELECT foo FROM bar" | ||
"# foo\nSELECT foo FROM bar", | ||
] | ||
|
||
for query in queries: | ||
assert "SELECT" == Parser(query).query_type | ||
|
||
|
||
def test_unsupported_query(): | ||
queries = [ | ||
"FOO BAR", | ||
"DO SOMETHING", | ||
] | ||
|
||
for query in queries: | ||
with pytest.raises(ValueError) as ex: | ||
_ = Parser(query).query_type | ||
|
||
assert "Not supported query type!" in str(ex.value) | ||
|
||
|
||
def test_empty_query(): | ||
queries = ["", "/* empty query */"] | ||
|
||
for query in queries: | ||
with pytest.raises(ValueError) as ex: | ||
_ = Parser(query).query_type | ||
|
||
assert "Empty queries are not supported!" in str(ex.value) |
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