Skip to content

Commit b46e52a

Browse files
committed
test(datatype): handle geometry
1 parent 00f209a commit b46e52a

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

test/integration/datatype/_generate_test_datatype_tables.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,78 @@
1717
"""
1818

1919

20+
class RedshiftDatatypes(Enum):
21+
"""
22+
All redshift specific datatypes are defined here
23+
"""
24+
25+
super = auto()
26+
geometry = auto()
27+
28+
@classmethod
29+
def list(cls) -> typing.List["RedshiftDatatypes"]:
30+
return list(map(lambda p: p, cls)) # type: ignore
31+
32+
33+
redshift_test_data: typing.Dict[str, typing.Tuple[typing.Tuple[str, str], ...]] = {
34+
RedshiftDatatypes.geometry.name: (
35+
(
36+
"ST_GeomFromText('LINESTRING(1 2,3 4,5 6,7 8,9 10,11 12,13 14,15 16,17 18,19 20)')",
37+
(
38+
"01020000000A000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000"
39+
"000018400000000000001C400000000000002040000000000000224000000000000024400000000000002640000000000000284000"
40+
"00000000002A400000000000002C400000000000002E40000000000000304000000000000031400000000000003240000000000000"
41+
"33400000000000003440"
42+
),
43+
),
44+
(
45+
"ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326)",
46+
(
47+
"0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F00000000"
48+
"0000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000"
49+
),
50+
),
51+
(
52+
(
53+
"ST_GeomFromEWKB('0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000"
54+
"000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000')"
55+
),
56+
(
57+
"0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000"
58+
"000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000"
59+
),
60+
),
61+
(
62+
(
63+
"ST_GeomFromEWKB('01020000000A000000000000000000F03F0000000000000040000000000000084000000000000010400000000000001440000000"
64+
"00000018400000000000001C4000000000000020400000000000002240000000000000244000000000000026400000000000002840"
65+
"0000000000002A400000000000002C400000000000002E400000000000003040000000000000314000000000000032400000000000"
66+
"0033400000000000003440')"
67+
),
68+
(
69+
"01020000000A000000000000000000F03F0000000000000040000000000000084000000000000010400000000000001440000000"
70+
"00000018400000000000001C4000000000000020400000000000002240000000000000244000000000000026400000000000002840"
71+
"0000000000002A400000000000002C400000000000002E400000000000003040000000000000314000000000000032400000000000"
72+
"0033400000000000003440"
73+
),
74+
),
75+
(
76+
(
77+
"ST_GeomFromWKB('01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03"
78+
"F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000')"
79+
),
80+
(
81+
"01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03"
82+
"F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000"
83+
),
84+
),
85+
)
86+
}
87+
88+
2089
class Datatypes(Enum):
2190
"""
22-
All supported datatypes are defined here, so a test table can be created for each
91+
All non-redshift specific datatypes are defined here, so a test table can be created for each
2392
"""
2493

2594
int2 = auto()

test/integration/datatype/test_datatypes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
datatype_test_setup,
1010
datatype_test_teardown,
1111
get_table_name,
12+
redshift_test_data,
1213
test_data,
1314
)
1415

@@ -64,3 +65,23 @@ def test_datatype_recv_support(db_kwargs, datatype):
6465
assert isclose(results[ridx][1].microsecond, exp_row[-1].microsecond, rel_tol=1e1)
6566
else:
6667
assert results[ridx][1] == exp_row[-1]
68+
69+
70+
redshift_datatype_testcases: typing.List[typing.Tuple] = []
71+
for datatype in redshift_test_data:
72+
for test_case in redshift_test_data[datatype]:
73+
redshift_datatype_testcases.append((datatype, test_case))
74+
75+
76+
@pytest.mark.parametrize("_input", redshift_datatype_testcases)
77+
def test_redshift_specific_recv_support(db_kwargs, _input):
78+
datatype, data = _input
79+
test_val, exp_val = data
80+
81+
with redshift_connector.connect(**db_kwargs) as con:
82+
with con.cursor() as cursor:
83+
cursor.execute("select {}".format(test_val))
84+
results: typing.Tuple = cursor.fetchall()
85+
assert len(results) == 1
86+
assert len(results[0]) == 1
87+
assert results[0][0] == exp_val

test/unit/datatype/test_data_in.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Datatypes(Enum):
2323
time = type_utils.time_in
2424
timetz = type_utils.timetz_in
2525
date = type_utils.date_in
26+
geometry = type_utils.text_recv
2627

2728

2829
test_data: typing.Dict[Datatypes, typing.List[typing.Tuple]] = {
@@ -129,6 +130,20 @@ class Datatypes(Enum):
129130
date(year=2020, day=10, month=3),
130131
)
131132
],
133+
Datatypes.geometry: [
134+
(
135+
b"\x00\x01\x00\x00\x01R01020000000A000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C40000000000000204000000000000022400000000000002440000000000000264000000000000028400000000000002A400000000000002C400000000000002E4000000000000030400000000000003140000000000000324000000000000033400000000000003440",
136+
6,
137+
338,
138+
"01020000000A000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C40000000000000204000000000000022400000000000002440000000000000264000000000000028400000000000002A400000000000002C400000000000002E4000000000000030400000000000003140000000000000324000000000000033400000000000003440",
139+
),
140+
(
141+
b"\x00\x01\x00\x00\x00\xc20103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000",
142+
6,
143+
194,
144+
"0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000",
145+
),
146+
],
132147
}
133148

134149

0 commit comments

Comments
 (0)