|
1 |
| -import os, datetime, decimal |
2 |
| -import pytest |
| 1 | +import datetime |
| 2 | +import decimal |
| 3 | +import os |
| 4 | +from typing import Tuple, Union |
3 | 5 | from unittest import skipIf
|
| 6 | + |
| 7 | +import pytest |
4 | 8 | from sqlalchemy import (
|
5 |
| - create_engine, |
6 |
| - select, |
7 |
| - insert, |
8 | 9 | Column,
|
9 | 10 | MetaData,
|
10 | 11 | Table,
|
11 | 12 | Text,
|
| 13 | + create_engine, |
| 14 | + insert, |
| 15 | + select, |
12 | 16 | text,
|
13 | 17 | )
|
14 |
| -from sqlalchemy.orm import Session, DeclarativeBase, Mapped, mapped_column |
15 |
| -from sqlalchemy.types import SMALLINT, Integer, BOOLEAN, String, DECIMAL, Date |
16 | 18 | from sqlalchemy.engine import Engine
|
17 |
| - |
18 |
| -from typing import Tuple, Union |
| 19 | +from sqlalchemy.engine.reflection import Inspector |
| 20 | +from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column |
| 21 | +from sqlalchemy.types import BOOLEAN, DECIMAL, Date, DateTime, Integer, String |
19 | 22 |
|
20 | 23 | try:
|
21 | 24 | from sqlalchemy.orm import declarative_base
|
@@ -344,8 +347,6 @@ class Base(DeclarativeBase):
|
344 | 347 | def test_inspector_smoke_test(samples_engine: Engine):
|
345 | 348 | """It does not appear that 3L namespace is supported here"""
|
346 | 349 |
|
347 |
| - from sqlalchemy.engine.reflection import Inspector |
348 |
| - |
349 | 350 | schema, table = "nyctaxi", "trips"
|
350 | 351 |
|
351 | 352 | try:
|
@@ -431,3 +432,34 @@ def get_conn_user_agent(conn):
|
431 | 432 | c2.close()
|
432 | 433 |
|
433 | 434 | assert same_ua, f"User agents didn't match \n {ua1} \n {ua2}"
|
| 435 | + |
| 436 | + |
| 437 | +@pytest.fixture |
| 438 | +def sample_table(metadata_obj: MetaData, db_engine: Engine): |
| 439 | + """This fixture creates a sample table and cleans it up after the test is complete.""" |
| 440 | + from databricks.sqlalchemy._parse import GET_COLUMNS_TYPE_MAP |
| 441 | + |
| 442 | + table_name = "PySQLTest_{}".format(datetime.datetime.utcnow().strftime("%s")) |
| 443 | + |
| 444 | + args = [ |
| 445 | + Column(colname, coltype) for colname, coltype in GET_COLUMNS_TYPE_MAP.items() |
| 446 | + ] |
| 447 | + |
| 448 | + SampleTable = Table(table_name, metadata_obj, *args) |
| 449 | + |
| 450 | + metadata_obj.create_all(db_engine) |
| 451 | + |
| 452 | + yield table_name |
| 453 | + |
| 454 | + metadata_obj.drop_all(db_engine) |
| 455 | + |
| 456 | + |
| 457 | +def test_get_columns(db_engine, sample_table: str): |
| 458 | + """Created after PECO-1297 and Github Issue #295 to verify that get_columsn behaves like it should for all known SQLAlchemy types""" |
| 459 | + |
| 460 | + inspector = Inspector.from_engine(db_engine) |
| 461 | + |
| 462 | + # this raises an exception if `parse_column_info_from_tgetcolumnsresponse` fails a lookup |
| 463 | + columns = inspector.get_columns(sample_table) |
| 464 | + |
| 465 | + assert True |
0 commit comments