Skip to content

Commit 9b5862c

Browse files
committed
Wrote unit tests
1 parent fd0243d commit 9b5862c

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/unit/test_util.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import decimal
2+
import datetime
3+
4+
from databricks.sql.utils import convert_to_assigned_datatypes_in_column_table
5+
6+
7+
class TestUtils:
8+
def get_column_table_and_description(self):
9+
table_description = [
10+
("id", "int", None, None, None, None, None),
11+
("varchar_column", "string", None, None, None, None, None),
12+
("boolean_column", "boolean", None, None, None, None, None),
13+
("integer_column", "int", None, None, None, None, None),
14+
("bigint_column", "bigint", None, None, None, None, None),
15+
("smallint_column", "smallint", None, None, None, None, None),
16+
("tinyint_column", "tinyint", None, None, None, None, None),
17+
("float_column", "float", None, None, None, None, None),
18+
("double_column", "double", None, None, None, None, None),
19+
("decimal_column", "decimal", None, None, 10, 2, None),
20+
("date_column", "date", None, None, None, None, None),
21+
("timestamp_column", "timestamp", None, None, None, None, None),
22+
("timestamp_ntz_column", "timestamp", None, None, None, None, None),
23+
("binary_column", "binary", None, None, None, None, None),
24+
("array_column", "array", None, None, None, None, None),
25+
("map_column", "map", None, None, None, None, None),
26+
("struct_column", "struct", None, None, None, None, None),
27+
("variant_column", "string", None, None, None, None, None),
28+
]
29+
30+
column_table = [
31+
(9,),
32+
("Test Varchar",),
33+
(True,),
34+
(123,),
35+
(9876543210,),
36+
(32000,),
37+
(120,),
38+
(1.23,),
39+
(4.56,),
40+
("7890.12",),
41+
("2023-12-31",),
42+
("2023-12-31 12:30:00",),
43+
("2023-12-31 12:30:00",),
44+
(b"\xde\xad\xbe\xef",),
45+
('["item1","item2"]',),
46+
('{"key1":"value1","key2":"value2"}',),
47+
('{"name":"John","age":30}',),
48+
('"semi-structured data"',),
49+
]
50+
51+
return column_table, table_description
52+
53+
def test_convert_to_assigned_datatypes_in_column_table(self):
54+
column_table, description = self.get_column_table_and_description()
55+
converted_column_table = convert_to_assigned_datatypes_in_column_table(
56+
column_table, description
57+
)
58+
59+
# (data , datatype)
60+
expected_convertion = [
61+
(9, int),
62+
("Test Varchar", str),
63+
(True, bool),
64+
(123, int),
65+
(9876543210, int),
66+
(32000, int),
67+
(120, int),
68+
(1.23, float),
69+
(4.56, float),
70+
(decimal.Decimal("7890.12"), decimal.Decimal),
71+
(datetime.date(2023, 12, 31), datetime.date),
72+
(datetime.datetime(2023, 12, 31, 12, 30, 0), datetime.datetime),
73+
(datetime.datetime(2023, 12, 31, 12, 30, 0), datetime.datetime),
74+
(b"\xde\xad\xbe\xef", bytes),
75+
('["item1","item2"]', str),
76+
('{"key1":"value1","key2":"value2"}', str),
77+
('{"name":"John","age":30}', str),
78+
('"semi-structured data"', str),
79+
]
80+
81+
for index, entry in enumerate(converted_column_table):
82+
assert entry[0] == expected_convertion[index][0]
83+
assert isinstance(entry[0], expected_convertion[index][1])

0 commit comments

Comments
 (0)