-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from slidoapp/gkaretka/update-tests-to-pytest
Move tests from unstructured to pytest
- Loading branch information
Showing
10 changed files
with
181 additions
and
123 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
import pytest | ||
|
||
from duckberg.sqlparser import DuckBergSQLParser | ||
|
||
|
||
@pytest.fixture | ||
def get_parser() -> DuckBergSQLParser: | ||
return DuckBergSQLParser() | ||
|
||
|
||
def test_basic_select_1(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
assert len(res) == 1 | ||
assert list(map(lambda x: str(x), res)) == ["this_is_awesome_table (None)"] | ||
|
||
|
||
def test_basic_select_2(get_parser): | ||
sql = """SELECT * FROM 'this_is_awesome_table'""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
print(str(sql_parsed.tokens)) | ||
res = get_parser.extract_tables(sql_parsed) | ||
print(res) | ||
assert len(res) == 1 | ||
assert list(map(lambda x: str(x), res)) == ["this_is_awesome_table (None)"] | ||
|
||
|
||
def test_basic_select_3(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table, second_awesome_table""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
assert len(res) == 2 | ||
assert list(map(lambda x: str(x), res)) == ["this_is_awesome_table (None)", "second_awesome_table (None)"] | ||
|
||
|
||
def test_basic_select_4(get_parser): | ||
sql = """SELECT * FROM (SELECT * FROM (SELECT * FROM this_is_awesome_table))""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
assert len(res) == 1 | ||
assert list(map(lambda x: str(x), res)) == ["this_is_awesome_table (None)"] | ||
|
||
|
||
def test_basic_select_5(get_parser): | ||
sql = """SELECT * FROM (SELECT * FROM (SELECT * FROM this_is_awesome_table), second_awesome_table)""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
assert len(res) == 2 | ||
assert list(map(lambda x: str(x), res)) == ["this_is_awesome_table (None)", "second_awesome_table (None)"] | ||
|
||
|
||
def test_basic_select_6(get_parser): | ||
sql = """SELECT * FROM (SELECT * FROM (SELECT * FROM this_is_awesome_table tiat, second_awesome_table))""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
assert len(res) == 2 | ||
assert list(map(lambda x: str(x), res)) == ["this_is_awesome_table (tiat)", "second_awesome_table (None)"] |
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,60 @@ | ||
import pytest | ||
|
||
from duckberg.sqlparser import DuckBergSQLParser | ||
|
||
|
||
@pytest.fixture | ||
def get_parser(): | ||
return DuckBergSQLParser() | ||
|
||
|
||
def test_select_where_1(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table WHERE a > 15""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
res_where = str(res[0].comparisons) | ||
assert "GreaterThan(term=Reference(name='a'), literal=LongLiteral(15))" == res_where | ||
|
||
|
||
def test_select_where_2(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table WHERE a > 15 AND a < 16""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
res_where = str(res[0].comparisons) | ||
assert ( | ||
"And(left=GreaterThan(term=Reference(name='a'), literal=LongLiteral(15)), right=LessThan(term=Reference(name='a'), literal=LongLiteral(16)))" | ||
== res_where | ||
) | ||
|
||
|
||
def test_select_where_3(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table WHERE (a > 15 AND a < 16) OR c > 15""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
res_where = str(res[0].comparisons) | ||
assert ( | ||
"Or(left=And(left=GreaterThan(term=Reference(name='a'), literal=LongLiteral(15)), right=LessThan(term=Reference(name='a'), literal=LongLiteral(16))), right=GreaterThan(term=Reference(name='c'), literal=LongLiteral(15)))" | ||
== res_where | ||
) | ||
|
||
|
||
def test_select_where_4(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table WHERE (b = "test string" AND a < 16) OR c > 15""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
res_where = str(res[0].comparisons) | ||
assert ( | ||
"Or(left=And(left=EqualTo(term=Reference(name='b'), literal=literal('test string')), right=LessThan(term=Reference(name='a'), literal=LongLiteral(16))), right=GreaterThan(term=Reference(name='c'), literal=LongLiteral(15)))" | ||
== res_where | ||
) | ||
|
||
|
||
def test_select_where_4(get_parser): | ||
sql = """SELECT * FROM this_is_awesome_table WHERE (b = "test string" AND column = '108e6307-f23a-4e10-9e38-1866d58b4355') OR c > 15""" | ||
sql_parsed = get_parser.parse_first_query(sql=sql) | ||
res = get_parser.extract_tables(sql_parsed) | ||
res_where = str(res[0].comparisons) | ||
assert ( | ||
"Or(left=And(left=EqualTo(term=Reference(name='b'), literal=literal('test string')), right=EqualTo(term=Reference(name='column'), literal=literal('108e6307-f23a-4e10-9e38-1866d58b4355'))), right=GreaterThan(term=Reference(name='c'), literal=LongLiteral(15)))" | ||
== res_where | ||
) |
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
import pytest | ||
|
||
from duckberg import DuckBerg | ||
|
||
|
||
@pytest.fixture | ||
def get_duckberg() -> DuckBerg: | ||
MINIO_URI = "http://localhost:9000/" | ||
MINIO_USER = "admin" | ||
MINIO_PASSWORD = "password" | ||
|
||
catalog_config: dict[str, str] = { | ||
"type": "rest", | ||
"uri": "http://localhost:8181/", | ||
"credentials": "admin:password", | ||
"s3.endpoint": MINIO_URI, | ||
"s3.access-key-id": MINIO_USER, | ||
"s3.secret-access-key": MINIO_PASSWORD, | ||
} | ||
|
||
catalog_name = "warehouse" | ||
return DuckBerg(catalog_name=catalog_name, catalog_config=catalog_config) | ||
|
||
|
||
def test_list_tables(get_duckberg): | ||
tables = get_duckberg.list_tables() | ||
assert len(tables) == 1 | ||
|
||
|
||
def test_select_1(get_duckberg): | ||
# New way of quering data without partition filter | ||
query: str = "SELECT count(*) FROM (SELECT * FROM 'nyc.taxis' WHERE trip_distance > 40 ORDER BY tolls_amount DESC)" | ||
df = get_duckberg.select(sql=query).read_pandas() | ||
assert df["count_star()"][0] == 2614 | ||
|
||
|
||
def test_select_2(get_duckberg): | ||
# New way of quering data | ||
query: str = "SELECT count(*) FROM (SELECT * FROM 'nyc.taxis' WHERE payment_type = 1 AND trip_distance > 40 ORDER BY tolls_amount DESC)" | ||
df = get_duckberg.select(sql=query).read_pandas() | ||
assert df["count_star()"][0] == 1673 | ||
|
||
|
||
def test_select_3(get_duckberg): | ||
# Old way of quering data | ||
query: str = "SELECT count(*) FROM (SELECT * FROM 'nyc.taxis' WHERE payment_type = 1 AND trip_distance > 40 ORDER BY tolls_amount DESC)" | ||
df = get_duckberg.select(sql=query, table="nyc.taxis", partition_filter="payment_type = 1").read_pandas() | ||
assert df["count_star()"][0] == 1673 |