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

fix: use faux_conn rather than engine in unit tests #431

Merged
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
5 changes: 0 additions & 5 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
)


@pytest.fixture()
def engine():
return sqlalchemy.create_engine("bigquery://myproject/mydataset")


@pytest.fixture()
def faux_conn():
test_data = dict(execute=[])
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test__struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def _col():
),
],
)
def test_struct_traversal_project(engine, expr, sql):
def test_struct_traversal_project(faux_conn, expr, sql):
sql = f"SELECT {sql} AS `anon_1` \nFROM `t`"
assert str(sqlalchemy.select([expr]).compile(engine)) == sql
assert str(sqlalchemy.select([expr]).compile(faux_conn.engine)) == sql


@pytest.mark.parametrize(
Expand Down Expand Up @@ -113,13 +113,13 @@ def test_struct_traversal_project(engine, expr, sql):
),
],
)
def test_struct_traversal_filter(engine, expr, sql, param=1):
def test_struct_traversal_filter(faux_conn, expr, sql, param=1):
want = f"SELECT `t`.`person` \nFROM `t`, `t` \nWHERE {sql}"
got = str(sqlalchemy.select([_col()]).where(expr).compile(engine))
got = str(sqlalchemy.select([_col()]).where(expr).compile(faux_conn.engine))
assert got == want


def test_struct_insert_type_info(engine, metadata):
def test_struct_insert_type_info(faux_conn, metadata):
t = sqlalchemy.Table("t", metadata, sqlalchemy.Column("person", _test_struct()))
got = str(
t.insert()
Expand All @@ -129,7 +129,7 @@ def test_struct_insert_type_info(engine, metadata):
children=[dict(name="billy", bdate=datetime.date(2020, 1, 1))],
)
)
.compile(engine)
.compile(faux_conn.engine)
)

assert got == (
Expand All @@ -139,14 +139,14 @@ def test_struct_insert_type_info(engine, metadata):
)


def test_struct_non_string_field_access(engine):
def test_struct_non_string_field_access(faux_conn):
with pytest.raises(
TypeError,
match="STRUCT fields can only be accessed with strings field names, not 42",
):
_col()[42]


def test_struct_bad_name(engine):
def test_struct_bad_name(faux_conn):
with pytest.raises(KeyError, match="42"):
_col()["42"]
4 changes: 2 additions & 2 deletions tests/unit/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ def test_unnest_w_no_table_references(faux_conn, alias):
)


def test_array_indexing(engine, metadata):
def test_array_indexing(faux_conn, metadata):
t = sqlalchemy.Table(
"t", metadata, sqlalchemy.Column("a", sqlalchemy.ARRAY(sqlalchemy.String)),
)
got = str(sqlalchemy.select([t.c.a[0]]).compile(engine))
got = str(sqlalchemy.select([t.c.a[0]]).compile(faux_conn.engine))
assert got == "SELECT `t`.`a`[OFFSET(%(a_1:INT64)s)] AS `anon_1` \nFROM `t`"