Skip to content

Commit

Permalink
Move test to postgres client test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-r-rose committed Sep 27, 2019
1 parent 3748ef9 commit 1b59daa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
30 changes: 29 additions & 1 deletion ibis/sql/postgres/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import ibis
import ibis.expr.datatypes as dt
import ibis.expr.types as ir
import ibis.sql.alchemy as alch # noqa: E402
from ibis.tests.util import assert_equal

pytest.importorskip('sqlalchemy')
sa = pytest.importorskip('sqlalchemy')
pytest.importorskip('psycopg2')

pytestmark = pytest.mark.postgresql
Expand Down Expand Up @@ -136,6 +137,33 @@ def test_schema_table():
assert isinstance(schema['tables'], ir.TableExpr)


def test_schema_unsupported_type_conversion(self):
typespec = [
# name, type, nullable
('json', sa.dialects.postgresql.JSON, True, dt.any),
('jsonb', sa.dialects.postgresql.JSONB, True, dt.any),
('uuid', sa.dialects.postgresql.UUID, True, dt.any),
]

sqla_types = []
ibis_types = []
for name, t, nullable, ibis_type in typespec:
sqla_type = sa.Column(name, t, nullable=nullable)
sqla_types.append(sqla_type)
ibis_types.append((name, ibis_type(nullable=nullable)))

# Create a table with placeholder stubs for JSON, JSONB, and UUID.
engine = sa.create_engine('postgresql://')
table = sa.Table('tname', sa.MetaData(bind=engine), *sqla_types)

# Check that we can correctly create a schema with dt.any for the
# missing types.
schema = alch.schema_from_table(table)
expected = ibis.schema(ibis_types)

assert_equal(schema, expected)


def test_interval_films_schema(con):
t = con.table("films")
assert t.len.type() == dt.Interval(unit="m")
Expand Down
26 changes: 0 additions & 26 deletions ibis/sql/tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,6 @@ def test_sqla_schema_conversion(self):

assert_equal(schema, expected)

def test_sqla_postgres_schema_conversion(self):
typespec = [
# name, type, nullable
('json', sa.dialects.postgresql.JSON, True, dt.any),
('jsonb', sa.dialects.postgresql.JSONB, True, dt.any),
('uuid', sa.dialects.postgresql.UUID, True, dt.any),
]

sqla_types = []
ibis_types = []
for name, t, nullable, ibis_type in typespec:
sqla_type = sa.Column(name, t, nullable=nullable)
sqla_types.append(sqla_type)
ibis_types.append((name, ibis_type(nullable=nullable)))

# Create a table with placeholder stubs for JSON, JSONB, and UUID.
engine = sa.create_engine('postgresql://')
table = sa.Table('tname', sa.MetaData(bind=engine), *sqla_types)

# Check that we can correctly create a schema with dt.any for the
# missing types.
schema = alch.schema_from_table(table)
expected = ibis.schema(ibis_types)

assert_equal(schema, expected)

@pytest.mark.xfail(raises=AssertionError, reason='NYT')
def test_ibis_to_sqla_conversion(self):
assert False
Expand Down

0 comments on commit 1b59daa

Please sign in to comment.