Skip to content

Commit

Permalink
Add skipif to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dwolfeu committed Aug 3, 2024
1 parent 0eeb278 commit 932b052
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/unit/sqlalchemy/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from sqlalchemy import Column, Integer, MetaData, String, Table, func, insert, select, try_cast
from sqlalchemy.schema import CreateTable
from sqlalchemy.sql import column, table

#from tests.unit.conftest import sqlalchemy_version
from trino.sqlalchemy.dialect import TrinoDialect

metadata = MetaData()
table_without_catalog = Table(
'table',
metadata,
Column('id', Integer),
Column('name', String),
)
table_with_catalog = Table(
'table',
metadata,
Column('id', Integer),
schema='default',
trino_catalog='other'
)

def test_try_cast(dialect):
statement = select(try_cast(table_without_catalog.c.id,String))
query = statement.compile(dialect=dialect)
assert str(query) == 'SELECT try_cast("table".id as VARCHAR) AS id \nFROM "table"'

test_try_cast(TrinoDialect())
4 changes: 4 additions & 0 deletions tests/unit/sqlalchemy/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def test_ignore_nulls(dialect, function, element):
f'SELECT {function}("table".id) OVER (PARTITION BY "table".name) AS window ' \
f'\nFROM "table"'

@pytest.mark.skipif(
sqlalchemy_version() < "2.0",
reason="ImportError: cannot import name 'try_cast' from 'sqlalchemy'"
)
def test_try_cast(dialect):
statement = select(try_cast(table_without_catalog.c.id,String))
query = statement.compile(dialect=dialect)
Expand Down

0 comments on commit 932b052

Please sign in to comment.