Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup in python bindings tests #2750

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions bindings/python/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
import pandas as pd


def test_default_conn_uses_same_db():
# Create table
glaredb.execute("create table other (a int)")
# Try to query it. This would error if we weren't using the same db.
glaredb.execute("select * from other")
glaredb.execute("drop table other")


def test_with_context():
with glaredb.connect() as con:
con.execute("select 1")


def test_default_connection_sql():
out = glaredb.sql("select 1 as a").to_pandas()
expected = pd.DataFrame({"a": [1]})
assert out.equals(expected)
with glaredb.connect() as db:
out = db.sql("select 1 as a").to_pandas()
expected = pd.DataFrame({"a": [1]})
assert out.equals(expected)


def test_default_connection_execute():
out = glaredb.execute("select 1 as a").to_pandas()
expected = pd.DataFrame({"a": [1]})
assert out.equals(expected)


# def test_default_conn_uses_same_db():
# # Create table
# glaredb.execute("create table hello (a int)")
# # Try to query it. This would error if we weren't using the same db.
# glaredb.execute("select * from hello")
with glaredb.connect() as db:
out = db.execute("select 1 as a").to_pandas()
expected = pd.DataFrame({"a": [1]})
assert out.equals(expected)
25 changes: 12 additions & 13 deletions bindings/python/tests/test_logical_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@


def test_compose():
con = glaredb.connect()
con.execute("create table tbl (a int, b int);")
con.execute("insert into tbl values (1, 2);")
con.execute("insert into tbl values (3, 4);")
con.execute("insert into tbl values (5, 6);")
intermediate = con.sql("select * from tbl where a > 2 order by a;")
out_1 = intermediate.to_arrow().to_pydict()
expected = {"a": [3, 5], "b": [4, 6]}
assert out_1 == expected
out_2 = con.sql("select * from intermediate where b > 4;").to_arrow().to_pydict()
expected = {"a": [5], "b": [6]}
assert out_2 == expected
con.close()
with glaredb.connect() as con:
con.execute("create table tbl (a int, b int);")
con.execute("insert into tbl (a, b) values (1, 2);")
con.execute("insert into tbl values (3, 4);")
con.execute("insert into tbl values (5, 6);")
intermediate = con.sql("select * from tbl where a > 2 order by a;")
out_1 = intermediate.to_arrow().to_pydict()
expected = {"a": [3, 5], "b": [4, 6]}
assert out_1 == expected
out_2 = con.sql("select * from intermediate where b > 4;").to_arrow().to_pydict()
expected = {"a": [5], "b": [6]}
assert out_2 == expected