1313from _pytest .capture import CaptureFixture
1414from _pytest .logging import LogCaptureFixture
1515from faker import Faker
16- from mysql .connector import MySQLConnection , errorcode
16+ from mysql .connector import CMySQLConnection , MySQLConnection , errorcode
17+ from mysql .connector .pooling import PooledMySQLConnection
1718from pytest_mock import MockFixture
1819from sqlalchemy import MetaData , Table , create_engine , inspect , select , text
1920from sqlalchemy .engine import Connection , CursorResult , Engine , Inspector , Row
@@ -31,21 +32,21 @@ class TestSQLite3toMySQL:
3132 @pytest .mark .parametrize ("quiet" , [False , True ])
3233 def test_no_sqlite_file_raises_exception (self , quiet : bool ) -> None :
3334 with pytest .raises (ValueError ) as excinfo :
34- SQLite3toMySQL (quiet = quiet )
35+ SQLite3toMySQL (quiet = quiet ) # type: ignore
3536 assert "Please provide an SQLite file" in str (excinfo .value )
3637
3738 @pytest .mark .init
3839 @pytest .mark .parametrize ("quiet" , [False , True ])
3940 def test_invalid_sqlite_file_raises_exception (self , faker : Faker , quiet : bool ) -> None :
4041 with pytest .raises ((FileNotFoundError , IOError )) as excinfo :
41- SQLite3toMySQL (sqlite_file = faker .file_path (depth = 1 , extension = ".sqlite3" ), quiet = quiet )
42+ SQLite3toMySQL (sqlite_file = faker .file_path (depth = 1 , extension = ".sqlite3" ), quiet = quiet ) # type: ignore
4243 assert "SQLite file does not exist" in str (excinfo .value )
4344
4445 @pytest .mark .init
4546 @pytest .mark .parametrize ("quiet" , [False , True ])
4647 def test_missing_mysql_user_raises_exception (self , sqlite_database : str , quiet : bool ) -> None :
4748 with pytest .raises (ValueError ) as excinfo :
48- SQLite3toMySQL (sqlite_file = sqlite_database , quiet = quiet )
49+ SQLite3toMySQL (sqlite_file = sqlite_database , quiet = quiet ) # type: ignore
4950 assert "Please provide a MySQL user" in str (excinfo .value )
5051
5152 @pytest .mark .init
@@ -59,7 +60,7 @@ def test_valid_sqlite_file_and_valid_mysql_credentials(
5960 quiet : bool ,
6061 ):
6162 with helpers .not_raises (FileNotFoundError ):
62- SQLite3toMySQL (
63+ SQLite3toMySQL ( # type: ignore
6364 sqlite_file = sqlite_database ,
6465 mysql_user = mysql_credentials .user ,
6566 mysql_password = mysql_credentials .password ,
@@ -81,7 +82,7 @@ def test_valid_sqlite_file_and_invalid_mysql_credentials_raises_access_denied_ex
8182 quiet : bool ,
8283 ) -> None :
8384 with pytest .raises (mysql .connector .Error ) as excinfo :
84- SQLite3toMySQL (
85+ SQLite3toMySQL ( # type: ignore[call-arg]
8586 sqlite_file = sqlite_database ,
8687 mysql_user = faker .first_name ().lower (),
8788 mysql_password = faker .password (length = 16 ),
@@ -112,7 +113,7 @@ def test_unspecified_mysql_error(
112113 )
113114 caplog .set_level (logging .DEBUG )
114115 with pytest .raises (mysql .connector .Error ) as excinfo :
115- SQLite3toMySQL (
116+ SQLite3toMySQL ( # type: ignore[call-arg]
116117 sqlite_file = sqlite_database ,
117118 mysql_user = mysql_credentials .user ,
118119 mysql_password = mysql_credentials .password ,
@@ -163,7 +164,7 @@ def cursor(
163164 mocker .patch .object (mysql .connector , "connect" , return_value = FakeMySQLConnection ())
164165 with pytest .raises (mysql .connector .Error ):
165166 caplog .set_level (logging .DEBUG )
166- SQLite3toMySQL (
167+ SQLite3toMySQL ( # type: ignore[call-arg]
167168 sqlite_file = sqlite_database ,
168169 mysql_user = mysql_credentials .user ,
169170 mysql_password = mysql_credentials .password ,
@@ -186,7 +187,7 @@ def test_bad_mysql_connection(
186187 return_value = FakeConnector (is_connected = lambda : False ),
187188 )
188189 with pytest .raises ((ConnectionError , IOError )) as excinfo :
189- SQLite3toMySQL (
190+ SQLite3toMySQL ( # type: ignore[call-arg]
190191 sqlite_file = sqlite_database ,
191192 mysql_user = mysql_credentials .user ,
192193 mysql_password = mysql_credentials .password ,
@@ -214,7 +215,7 @@ def test_log_to_file(
214215 log_file : LocalPath = tmpdir .join (Path ("db.log" ))
215216 with pytest .raises (mysql .connector .Error ):
216217 caplog .set_level (logging .DEBUG )
217- SQLite3toMySQL (
218+ SQLite3toMySQL ( # type: ignore[call-arg]
218219 sqlite_file = sqlite_database ,
219220 mysql_user = faker .first_name ().lower (),
220221 mysql_password = faker .password (length = 16 ),
@@ -276,7 +277,7 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
276277 mysql_insert_method : str ,
277278 ignore_duplicate_keys : bool ,
278279 ):
279- proc : SQLite3toMySQL = SQLite3toMySQL (
280+ proc : SQLite3toMySQL = SQLite3toMySQL ( # type: ignore[call-arg]
280281 sqlite_file = sqlite_database ,
281282 mysql_user = mysql_credentials .user ,
282283 mysql_password = mysql_credentials .password ,
@@ -317,7 +318,9 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
317318 mysql_inspect : Inspector = inspect (mysql_engine )
318319 mysql_tables : t .List [str ] = mysql_inspect .get_table_names ()
319320
320- mysql_connector_connection : MySQLConnection = mysql .connector .connect (
321+ mysql_connector_connection : t .Union [
322+ PooledMySQLConnection , MySQLConnection , CMySQLConnection
323+ ] = mysql .connector .connect (
321324 user = mysql_credentials .user ,
322325 password = mysql_credentials .password ,
323326 host = mysql_credentials .host ,
@@ -339,7 +342,7 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
339342 """ Test if all the tables have the same indices """
340343 index_keys : t .Tuple [str , ...] = ("name" , "column_names" , "unique" )
341344 mysql_indices : t .Tuple [ReflectedIndex , ...] = tuple (
342- t .cast (ReflectedIndex , {key : index [key ] for key in index_keys })
345+ t .cast (ReflectedIndex , {key : index [key ] for key in index_keys }) # type: ignore[literal-required]
343346 for index in (chain .from_iterable (mysql_inspect .get_indexes (table_name ) for table_name in mysql_tables ))
344347 )
345348
@@ -484,7 +487,7 @@ def test_transfer_specific_tables_transfers_only_specified_tables_from_sqlite_fi
484487 random_sqlite_tables : t .List [str ] = sample (sqlite_tables , table_number )
485488 random_sqlite_tables .sort ()
486489
487- proc : SQLite3toMySQL = SQLite3toMySQL (
490+ proc : SQLite3toMySQL = SQLite3toMySQL ( # type: ignore[call-arg]
488491 sqlite_file = sqlite_database ,
489492 sqlite_tables = random_sqlite_tables ,
490493 mysql_user = mysql_credentials .user ,
@@ -531,7 +534,7 @@ def test_transfer_specific_tables_transfers_only_specified_tables_from_sqlite_fi
531534 """ Test if all the tables have the same indices """
532535 index_keys : t .Tuple [str , ...] = ("name" , "column_names" , "unique" )
533536 mysql_indices : t .Tuple [ReflectedIndex , ...] = tuple (
534- t .cast (ReflectedIndex , {key : index [key ] for key in index_keys })
537+ t .cast (ReflectedIndex , {key : index [key ] for key in index_keys }) # type: ignore[literal-required]
535538 for index in (chain .from_iterable (mysql_inspect .get_indexes (table_name ) for table_name in mysql_tables ))
536539 )
537540
0 commit comments