Skip to content

Commit

Permalink
test(cleanup): remove dead fixtures and prevent introducing new ones (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored Sep 1, 2024
1 parent d0e702a commit db8b447
Show file tree
Hide file tree
Showing 22 changed files with 21 additions and 246 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ibis-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ jobs:
- name: run doctests
run: just doctest --junitxml=junit.xml --cov=ibis --cov-report=xml:coverage.xml

- name: check for dead fixtures
run: poetry run pytest --dead-fixtures -m 'not flink'

- name: upload code coverage
if: success()
continue-on-error: true
Expand Down
48 changes: 0 additions & 48 deletions ibis/backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from packaging.version import parse as vparse

import ibis
import ibis.common.exceptions as com
from ibis import util
from ibis.backends import (
CanCreateCatalog,
Expand Down Expand Up @@ -486,12 +485,6 @@ def udf_backend(request, data_dir, tmp_path_factory, worker_id):
return cls.load_data(data_dir, tmp_path_factory, worker_id)


@pytest.fixture(scope="session")
def udf_con(udf_backend):
"""Instance of Client, already connected to the db (if applies)."""
return udf_backend.connection


@pytest.fixture(scope="session")
def alltypes(backend):
return backend.functional_alltypes
Expand All @@ -507,11 +500,6 @@ def struct(backend):
return backend.struct


@pytest.fixture(scope="session")
def sorted_alltypes(alltypes):
return alltypes.order_by("id")


@pytest.fixture(scope="session")
def udf_alltypes(udf_backend):
return udf_backend.functional_alltypes
Expand All @@ -527,11 +515,6 @@ def awards_players(backend):
return backend.awards_players


@pytest.fixture
def analytic_alltypes(alltypes):
return alltypes


@pytest.fixture(scope="session")
def df(alltypes):
return alltypes.execute()
Expand Down Expand Up @@ -562,13 +545,6 @@ def awards_players_df(awards_players):
return awards_players.execute(limit=None)


@pytest.fixture(scope="session")
def geo_df(geo):
if geo is not None:
return geo.execute(limit=None)
return None


@pytest.fixture
def temp_table(con):
"""Return a temporary table name.
Expand Down Expand Up @@ -623,30 +599,6 @@ def temp_view(ddl_con):
ddl_con.drop_view(name, force=True)


@pytest.fixture
def alternate_current_database(ddl_con, ddl_backend):
"""Create a temporary database and yield its name. Drops the created
database upon completion.
Parameters
----------
ddl_con : ibis.backends.Client
Yields
------
str
"""
name = util.gen_name("database")
try:
ddl_con.create_database(name)
except AttributeError:
pytest.skip(f"{ddl_backend.name()} doesn't have a `create_database` method.")
yield name

with contextlib.suppress(com.UnsupportedOperationError):
ddl_con.drop_database(name, force=True)


@pytest.fixture
def assert_sql(con, snapshot):
def checker(expr, file_name="out.sql"):
Expand Down
5 changes: 0 additions & 5 deletions ibis/backends/dask/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ def time_right(client):
return client.table("time_df2")


@pytest.fixture(scope="module")
def time_table(client):
return client.table("time_df3")


@pytest.fixture(scope="module")
def time_keyed_left(client):
return client.table("time_keyed_df1")
Expand Down
25 changes: 0 additions & 25 deletions ibis/backends/dask/tests/test_window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from datetime import date
from operator import methodcaller

import dask.dataframe as dd
Expand Down Expand Up @@ -500,27 +499,3 @@ def count_both(v1, v2):
t[control].count().over(row_window).execute(),
check_names=False,
)


@pytest.fixture
def events(npartitions) -> dd.DataFrame:
df = pd.DataFrame(
{
"event_id": [1] * 4 + [2] * 6 + [3] * 2,
"measured_on": map(
pd.Timestamp,
map(
date,
[2021] * 12,
[6] * 4 + [5] * 6 + [7] * 2,
range(1, 13),
),
),
"measurement": np.nan,
}
)
df.at[1, "measurement"] = 5.0
df.at[4, "measurement"] = 42.0
df.at[5, "measurement"] = 42.0
df.at[7, "measurement"] = 11.0
return dd.from_pandas(df, npartitions=npartitions)
6 changes: 0 additions & 6 deletions ibis/backends/druid/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from itertools import chain, repeat
from typing import TYPE_CHECKING, Any

import pytest
from requests import Session

import ibis
Expand Down Expand Up @@ -148,8 +147,3 @@ def _load_data(self, **_: Any) -> None:
@staticmethod
def connect(*, tmpdir, worker_id, **kw):
return ibis.connect(DRUID_URL, **kw)


@pytest.fixture(scope="session")
def con(data_dir, tmp_path_factory, worker_id):
return TestConf.load_data(data_dir, tmp_path_factory, worker_id).connection
5 changes: 0 additions & 5 deletions ibis/backends/flink/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ def functional_alltypes_schema():
return TEST_TABLES["functional_alltypes"]


@pytest.fixture
def batting_schema():
return TEST_TABLES["batting"]


@pytest.fixture
def csv_source_configs():
def generate_csv_configs(csv_file):
Expand Down
7 changes: 0 additions & 7 deletions ibis/backends/impala/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ def test_attr_name_conflict(temp_parquet_table, temp_parquet_table2):
assert left.join(right, ["id", "files"]) is not None


@pytest.fixture
def con2(env):
return ibis.impala.connect(
host=env.impala_host, port=env.impala_port, auth_mechanism=env.auth_mechanism
)


def test_day_of_week(con):
date_var = ibis.literal(datetime.date(2017, 1, 1), type=dt.date)
expr_index = date_var.day_of_week.index()
Expand Down
5 changes: 0 additions & 5 deletions ibis/backends/pandas/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,6 @@ def time_right(client):
return client.table("time_df2")


@pytest.fixture(scope="module")
def time_table(client):
return client.table("time_df3")


@pytest.fixture(scope="module")
def time_keyed_left(client):
return client.table("time_keyed_df1")
Expand Down
5 changes: 0 additions & 5 deletions ibis/backends/polars/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,3 @@ def con(data_dir, tmp_path_factory, worker_id):
@pytest.fixture(scope="session")
def alltypes(con):
return con.table("functional_alltypes")


@pytest.fixture(scope="session")
def alltypes_df(alltypes):
return alltypes.execute()
8 changes: 0 additions & 8 deletions ibis/backends/postgres/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,3 @@ def gdf(geotable):
@pytest.fixture(scope="module")
def intervals(con):
return con.table("intervals")


@pytest.fixture
def translate():
from ibis.backends.postgres import Backend

context = Backend.compiler.make_context()
return lambda expr: Backend.compiler.translator_class(expr, context).get_result()
25 changes: 0 additions & 25 deletions ibis/backends/postgres/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,31 +959,6 @@ def test_array_concat_mixed_types(array_types):
array_types.y + array_types.x.cast("array<double>")


@pytest.fixture
def t(con, temp_table):
with con.begin() as c:
c.execute(f"CREATE TABLE {temp_table} (id SERIAL PRIMARY KEY, name TEXT)")
return con.table(temp_table)


@pytest.fixture
def s(con, t, temp_table2):
temp_table = t.op().name
assert temp_table != temp_table2

with con.begin() as c:
c.execute(
f"""
CREATE TABLE {temp_table2} (
id SERIAL PRIMARY KEY,
left_t_id INTEGER REFERENCES {temp_table},
cost DOUBLE PRECISION
)
"""
)
return con.table(temp_table2)


@pytest.fixture
def trunc(con, temp_table):
quoted = temp_table
Expand Down
10 changes: 0 additions & 10 deletions ibis/backends/pyspark/tests/test_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@ def test_drop_view(con, created_view):
assert created_view not in con.list_tables()


@pytest.fixture
def table(con, temp_database):
table_name = f"table_{util.guid()}"
schema = ibis.schema([("foo", "string"), ("bar", "int64")])
yield con.create_table(
table_name, database=temp_database, schema=schema, format="parquet"
)
con.drop_table(table_name, database=temp_database)


@pytest.fixture
def keyword_t(con):
yield "distinct"
Expand Down
5 changes: 0 additions & 5 deletions ibis/backends/risingwave/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,3 @@ def alltypes(con):
@pytest.fixture(scope="module")
def df(alltypes):
return alltypes.execute()


@pytest.fixture(scope="module")
def intervals(con):
return con.table("intervals")
25 changes: 0 additions & 25 deletions ibis/backends/sqlite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import contextlib
import csv
import io
import sqlite3
from typing import Any

import pytest
Expand Down Expand Up @@ -55,30 +54,6 @@ def functional_alltypes(self) -> ir.Table:
return t.mutate(timestamp_col=t.timestamp_col.cast("timestamp"))


@pytest.fixture
def dbpath(tmp_path):
path = tmp_path / "test.db"
con = sqlite3.connect(path)
con.execute("CREATE TABLE t AS SELECT 1 a UNION SELECT 2 UNION SELECT 3")
con.execute("CREATE TABLE s AS SELECT 1 b UNION SELECT 2")
return path


@pytest.fixture(scope="session")
def con(data_dir, tmp_path_factory, worker_id):
return TestConf.load_data(data_dir, tmp_path_factory, worker_id).connection


@pytest.fixture(scope="session")
def translate(dialect):
return lambda expr: ibis.to_sql(expr, dialect="sqlite")


@pytest.fixture(scope="session")
def alltypes(con):
return con.table("functional_alltypes")


@pytest.fixture(scope="session")
def df(alltypes):
return alltypes.execute()
5 changes: 1 addition & 4 deletions ibis/backends/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from filelock import FileLock

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Mapping
from collections.abc import Iterable, Iterator

import ibis.expr.types as ir

Expand Down Expand Up @@ -307,9 +307,6 @@ def win(self) -> ir.Table | None:
def api(self):
return self.connection

def make_context(self, params: Mapping[ir.Value, Any] | None = None):
return self.api.compiler.make_context(params=params)

def _tpc_table(self, name: str, benchmark: Literal["h", "ds"]):
if not getattr(self, f"supports_tpc{benchmark}"):
pytest.skip(
Expand Down
5 changes: 0 additions & 5 deletions ibis/backends/tests/sql/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ def t2(con):
return con.table("t2")


@pytest.fixture(scope="module")
def where_uncorrelated_subquery(foo, bar):
return foo[foo.job.isin(bar.job)]


@pytest.fixture(scope="module")
def not_exists(foo_t, bar_t):
return foo_t[-(foo_t.key1 == bar_t.key1).any()]
Expand Down
18 changes: 0 additions & 18 deletions ibis/backends/tests/test_dot_sql.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import contextlib
import getpass

import pytest
Expand Down Expand Up @@ -293,23 +292,6 @@ def test_dot_sql_limit(con):
assert result.iat[0, 0] == "abc"


@pytest.fixture(scope="module")
def mem_t(con):
if con.name == "druid":
pytest.xfail("druid does not support create_table")

name = ibis.util.gen_name(con.name)

# flink only supports memtables if `temp` is True, seems like we should
# address that for users
con.create_table(
name, ibis.memtable({"a": list("def")}), temp=con.name == "flink" or None
)
yield name
with contextlib.suppress(NotImplementedError):
con.drop_table(name, force=True)


@dot_sql_never
@pytest.mark.notyet(
["druid"],
Expand Down
Loading

0 comments on commit db8b447

Please sign in to comment.