Skip to content

Commit 8df478b

Browse files
committed
confirm pretty and original query work the same, and differ only in whitespace
1 parent 13ddf3c commit 8df478b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tests/test_sqlite.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
import re
13
import sqlite3
24

35
import data_algebra
@@ -102,22 +104,32 @@ def test_sqllite_g2():
102104

103105
sql_model = data_algebra.SQLite.SQLiteModel()
104106

105-
q = ops.to_sql(db_model=sql_model)
107+
q = ops.to_sql(db_model=sql_model, pretty=False)
108+
q_pretty = ops.to_sql(db_model=sql_model, pretty=True)
106109

107-
conn = sqlite3.connect(":memory:")
108-
sql_model.prepare_connection(conn)
109-
sql_model.insert_table(conn, d, table_name="d")
110+
pattern_ws = re.compile(r'\s+')
111+
q_ns = re.sub(pattern_ws, '', q)
112+
q_pretty_ns = re.sub(pattern_ws, '', q_pretty)
113+
assert q_ns == q_pretty_ns
110114

111-
# conn.execute('CREATE TABLE res AS ' + q)
112-
# res_sql = sql_model.read_table(conn, 'res')
113-
res_sql = sql_model.read_query(conn, q)
115+
with sqlite3.connect(":memory:") as conn:
116+
sql_model.prepare_connection(conn)
117+
db_handle = sql_model.db_handle(conn)
118+
db_handle.insert_table(d, table_name="d")
114119

115-
conn.close()
120+
# conn.execute('CREATE TABLE res AS ' + q)
121+
# res_sql = sql_model.read_table(conn, 'res')
122+
res_sql = db_handle.read_query(q)
123+
res_sql_pretty = db_handle.read_query(q_pretty)
116124

117125
assert data_algebra.test_util.equivalent_frames(
118126
res_pandas, res_sql, check_row_order=True
119127
)
120128

129+
assert data_algebra.test_util.equivalent_frames(
130+
res_pandas, res_sql_pretty, check_row_order=True
131+
)
132+
121133

122134
def test_join_g2():
123135
d1 = data_algebra.default_data_model.pd.DataFrame(

0 commit comments

Comments
 (0)