Skip to content

Commit 374bf77

Browse files
committed
refactor(test, connection): use mock py_types, pg_types
1 parent 32eb2da commit 374bf77

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

test/unit/test_connection.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
min_int4,
2323
min_int8,
2424
)
25-
from redshift_connector.utils.type_utils import py_types
25+
from redshift_connector.utils.type_utils import pg_types as PG_TYPES
26+
from redshift_connector.utils.type_utils import py_types as PY_TYPES
2627

2728
test_error_responses_data: typing.List[typing.Tuple[bytes, typing.Dict, typing.Type[Error]]] = [
2829
(
@@ -144,31 +145,32 @@ def test_handle_COPY_DONE():
144145

145146

146147
test_inspect_int_vals: typing.List[typing.Tuple[int, typing.Tuple[int, int, typing.Callable]]] = [
147-
(min_int2 - 1, py_types[23]),
148-
(min_int2, py_types[23]),
149-
(min_int2 + 1, py_types[21]),
150-
(max_int2 - 1, py_types[21]),
151-
(max_int2, py_types[23]),
152-
(max_int2 + 1, py_types[23]),
153-
(min_int4 - 1, py_types[20]),
154-
(min_int4, py_types[20]),
155-
(min_int4 + 1, py_types[23]),
156-
(max_int4 - 1, py_types[23]),
157-
(max_int4, py_types[20]),
158-
(max_int4 + 1, py_types[20]),
159-
(min_int8 - 1, py_types[Decimal]),
160-
(min_int8, py_types[Decimal]),
161-
(min_int8 + 1, py_types[20]),
162-
(max_int8 - 1, py_types[20]),
163-
(max_int8, py_types[Decimal]),
164-
(max_int8 + 1, py_types[Decimal]),
148+
(min_int2 - 1, PY_TYPES[23]),
149+
(min_int2, PY_TYPES[23]),
150+
(min_int2 + 1, PY_TYPES[21]),
151+
(max_int2 - 1, PY_TYPES[21]),
152+
(max_int2, PY_TYPES[23]),
153+
(max_int2 + 1, PY_TYPES[23]),
154+
(min_int4 - 1, PY_TYPES[20]),
155+
(min_int4, PY_TYPES[20]),
156+
(min_int4 + 1, PY_TYPES[23]),
157+
(max_int4 - 1, PY_TYPES[23]),
158+
(max_int4, PY_TYPES[20]),
159+
(max_int4 + 1, PY_TYPES[20]),
160+
(min_int8 - 1, PY_TYPES[Decimal]),
161+
(min_int8, PY_TYPES[Decimal]),
162+
(min_int8 + 1, PY_TYPES[20]),
163+
(max_int8 - 1, PY_TYPES[20]),
164+
(max_int8, PY_TYPES[Decimal]),
165+
(max_int8 + 1, PY_TYPES[Decimal]),
165166
]
166167

167168

168169
@pytest.mark.parametrize("_input", test_inspect_int_vals)
169170
def test_inspect_int(_input):
170171
input_val, expected_type = _input
171172
mock_connection = Connection.__new__(Connection)
173+
mock_connection.py_types = PY_TYPES
172174
assert mock_connection.inspect_int(input_val) == expected_type
173175

174176

@@ -205,6 +207,7 @@ def test_handle_ROW_DESCRIPTION_extended_metadata(_input, protocol):
205207
data, exp_result = _input
206208
mock_connection = Connection.__new__(Connection)
207209
mock_connection._client_protocol_version = protocol
210+
mock_connection.pg_types = dict(PG_TYPES)
208211
mock_cursor = Cursor.__new__(Cursor)
209212
mock_cursor.ps = {"row_desc": []}
210213

@@ -240,6 +243,7 @@ def test_handle_ROW_DESCRIPTION_base(_input):
240243
data, exp_result = _input
241244
mock_connection = Connection.__new__(Connection)
242245
mock_connection._client_protocol_version = ClientProtocolVersion.BASE_SERVER.value
246+
mock_connection.pg_types = dict(PG_TYPES)
243247
mock_cursor = Cursor.__new__(Cursor)
244248
mock_cursor.ps = {"row_desc": []}
245249

0 commit comments

Comments
 (0)