forked from databricks/databricks-sql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_extra.py
More file actions
70 lines (53 loc) · 1.91 KB
/
_extra.py
File metadata and controls
70 lines (53 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Additional tests authored by Databricks that use SQLAlchemy's test fixtures
"""
import datetime
from sqlalchemy.testing.suite.test_types import (
_LiteralRoundTripFixture,
fixtures,
testing,
eq_,
select,
Table,
Column,
config,
_DateFixture,
literal,
)
from databricks.sqlalchemy import TINYINT, TIMESTAMP
class TinyIntegerTest(_LiteralRoundTripFixture, fixtures.TestBase):
__backend__ = True
def test_literal(self, literal_round_trip):
literal_round_trip(TINYINT, [5], [5])
@testing.fixture
def integer_round_trip(self, metadata, connection):
def run(datatype, data):
int_table = Table(
"tiny_integer_table",
metadata,
Column(
"id",
TINYINT,
primary_key=True,
test_needs_autoincrement=False,
),
Column("tiny_integer_data", datatype),
)
metadata.create_all(config.db)
connection.execute(int_table.insert(), {"id": 1, "integer_data": data})
row = connection.execute(select(int_table.c.integer_data)).first()
eq_(row, (data,))
assert isinstance(row[0], int)
return run
class DateTimeTZTestCustom(_DateFixture, fixtures.TablesTest):
"""This test confirms that when a user uses the TIMESTAMP
type to store a datetime object, it retains its timezone
"""
__backend__ = True
datatype = TIMESTAMP
data = datetime.datetime(2012, 10, 15, 12, 57, 18, tzinfo=datetime.timezone.utc)
@testing.requires.datetime_implicit_bound
def test_select_direct(self, connection):
# We need to pass the TIMESTAMP type to the literal function
# so that the value is processed correctly.
result = connection.scalar(select(literal(self.data, TIMESTAMP)))
eq_(result, self.data)