Skip to content

Commit

Permalink
fix: use faux_conn rather than engine in unit tests (#431)
Browse files Browse the repository at this point in the history
Remove the engine fixture from unit tests and use faux_conn instead. Creating
an engine requires credentials, which prevents these tests from being pure unit
tests and running in any environment.

Fixes #430 🦕
  • Loading branch information
waltaskew authored Mar 21, 2022
1 parent 934e25f commit 275506f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
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`"

0 comments on commit 275506f

Please sign in to comment.