|
10 | 10 | # See the License for the specific language governing permissions and
|
11 | 11 | # limitations under the License.
|
12 | 12 | import math
|
| 13 | +import uuid |
13 | 14 | from datetime import date, datetime, time, timedelta, timezone
|
14 | 15 | from decimal import Decimal
|
| 16 | +from typing import Tuple |
15 | 17 |
|
16 | 18 | import pytest
|
17 | 19 | import pytz
|
|
21 | 23 | import trino
|
22 | 24 | from tests.integration.conftest import trino_version
|
23 | 25 | from trino import constants
|
24 |
| -from trino.dbapi import DescribeOutput |
| 26 | +from trino.dbapi import Cursor, DescribeOutput |
25 | 27 | from trino.exceptions import NotSupportedError, TrinoQueryError, TrinoUserError
|
26 | 28 | from trino.transaction import IsolationLevel
|
27 | 29 |
|
@@ -1273,3 +1275,23 @@ def assert_cursor_description(cur, trino_type, size=None, precision=None, scale=
|
1273 | 1275 | assert cur.description[0][4] is precision
|
1274 | 1276 | assert cur.description[0][5] is scale
|
1275 | 1277 | 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