44import typing
55from datetime import datetime as Datetime
66from datetime import timezone
7- from redshift_connector .interval import IntervalYearToMonth , IntervalDayToSecond
87from math import isclose
98from test .integration .datatype ._generate_test_datatype_tables import ( # type: ignore
109 DATATYPES_WITH_MS ,
2221
2322import redshift_connector
2423from redshift_connector .config import ClientProtocolVersion
24+ from redshift_connector .interval import IntervalDayToSecond , IntervalYearToMonth
2525
2626conf = configparser .ConfigParser ()
2727root_path = os .path .dirname (os .path .dirname (os .path .abspath (os .path .join (__file__ , os .pardir ))))
@@ -120,9 +120,9 @@ def test_redshift_varbyte_insert(db_kwargs, _input, client_protocol) -> None:
120120 assert len (results [0 ]) == 2
121121 assert results [0 ][1 ] == bytes (data , encoding = "utf-8" ).hex ()
122122
123+
123124@pytest .mark .parametrize ("client_protocol" , ClientProtocolVersion .list ())
124- @pytest .mark .parametrize ("datatype" , [RedshiftDatatypes .intervaly2m .name ,
125- RedshiftDatatypes .intervald2s .name ])
125+ @pytest .mark .parametrize ("datatype" , [RedshiftDatatypes .intervaly2m .name , RedshiftDatatypes .intervald2s .name ])
126126def test_redshift_interval_insert (db_kwargs , datatype , client_protocol ) -> None :
127127 db_kwargs ["client_protocol_version" ] = client_protocol
128128 data = redshift_test_data [datatype ]
@@ -139,13 +139,13 @@ def test_redshift_interval_insert(db_kwargs, datatype, client_protocol) -> None:
139139 print (results )
140140 for idx , result in enumerate (results ):
141141 print (result [1 ], data [idx ][1 ])
142- assert ( isinstance (result [1 ], redshift_type ) )
143- assert ( result [1 ] == data [idx ][1 ])
142+ assert isinstance (result [1 ], redshift_type )
143+ assert result [1 ] == data [idx ][1 ]
144144 cursor .execute ("drop table t_interval" )
145145
146+
146147@pytest .mark .parametrize ("client_protocol" , ClientProtocolVersion .list ())
147- @pytest .mark .parametrize ("datatype" , [RedshiftDatatypes .intervaly2m .name ,
148- RedshiftDatatypes .intervald2s .name ])
148+ @pytest .mark .parametrize ("datatype" , [RedshiftDatatypes .intervaly2m .name , RedshiftDatatypes .intervald2s .name ])
149149def test_redshift_interval_prep_stmt (db_kwargs , datatype , client_protocol ) -> None :
150150 db_kwargs ["client_protocol_version" ] = client_protocol
151151 data = redshift_test_data [datatype ]
@@ -155,19 +155,20 @@ def test_redshift_interval_prep_stmt(db_kwargs, datatype, client_protocol) -> No
155155 with con .cursor () as cursor :
156156 cursor .execute ("create table t_interval_ps(id text, v1 {})" .format (datatype ))
157157 cursor .paramstyle = "pyformat"
158- cursor .executemany ("insert into t_interval_ps(id, v1) values (%(id_val)s, %(v1_val)s)" ,
159- ({"id_val" : row [- 1 ], "v1_val" : row [1 ]} for row in data [:2 ]))
158+ cursor .executemany (
159+ "insert into t_interval_ps(id, v1) values (%(id_val)s, %(v1_val)s)" ,
160+ ({"id_val" : row [- 1 ], "v1_val" : row [1 ]} for row in data [:2 ]),
161+ )
160162 cursor .paramstyle = "qmark"
161- cursor .executemany ("insert into t_interval_ps values (?, ?)" ,
162- ([row [- 1 ], row [1 ]] for row in data [2 :]))
163+ cursor .executemany ("insert into t_interval_ps values (?, ?)" , ([row [- 1 ], row [1 ]] for row in data [2 :]))
163164 cursor .execute ("select id, v1 from t_interval_ps" )
164165 results : typing .Tuple = cursor .fetchall ()
165166 assert len (results ) == len (data )
166167 print (results )
167168 for idx , result in enumerate (results ):
168169 print (result [1 ], data [idx ][1 ])
169- assert ( isinstance (result [1 ], redshift_type ) )
170- assert ( result [1 ] == data [idx ][1 ])
170+ assert isinstance (result [1 ], redshift_type )
171+ assert result [1 ] == data [idx ][1 ]
171172 cursor .execute ("drop table t_interval_ps" )
172173
173174
0 commit comments