Skip to content

Commit b62dca6

Browse files
mdesmethashhar
authored andcommitted
Add TestTable utility class
1 parent 3291506 commit b62dca6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/integration/test_dbapi_integration.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
import math
13+
import uuid
1314
from datetime import date, datetime, time, timedelta, timezone
1415
from decimal import Decimal
16+
from typing import Tuple
1517

1618
import pytest
1719
import pytz
@@ -21,7 +23,7 @@
2123
import trino
2224
from tests.integration.conftest import trino_version
2325
from trino import constants
24-
from trino.dbapi import DescribeOutput
26+
from trino.dbapi import Cursor, DescribeOutput
2527
from trino.exceptions import NotSupportedError, TrinoQueryError, TrinoUserError
2628
from trino.transaction import IsolationLevel
2729

@@ -1273,3 +1275,23 @@ def assert_cursor_description(cur, trino_type, size=None, precision=None, scale=
12731275
assert cur.description[0][4] is precision
12741276
assert cur.description[0][5] is scale
12751277
assert cur.description[0][6] is None
1278+
1279+
1280+
class _TestTable:
1281+
def __init__(self, conn, table_name_prefix, table_definition) -> None:
1282+
self._conn = conn
1283+
self._table_name = table_name_prefix + '_' + str(uuid.uuid4().hex)
1284+
self._table_definition = table_definition
1285+
1286+
def __enter__(self) -> Tuple["_TestTable", Cursor]:
1287+
return (
1288+
self,
1289+
self._conn.cursor().execute(f"CREATE TABLE {self._table_name} {self._table_definition}")
1290+
)
1291+
1292+
def __exit__(self, exc_type, exc_value, exc_tb) -> None:
1293+
self._conn.cursor().execute(f"DROP TABLE {self._table_name}")
1294+
1295+
@property
1296+
def table_name(self):
1297+
return self._table_name

0 commit comments

Comments
 (0)