13
13
from _pytest .capture import CaptureFixture
14
14
from _pytest .logging import LogCaptureFixture
15
15
from 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
17
18
from pytest_mock import MockFixture
18
19
from sqlalchemy import MetaData , Table , create_engine , inspect , select , text
19
20
from sqlalchemy .engine import Connection , CursorResult , Engine , Inspector , Row
@@ -31,21 +32,21 @@ class TestSQLite3toMySQL:
31
32
@pytest .mark .parametrize ("quiet" , [False , True ])
32
33
def test_no_sqlite_file_raises_exception (self , quiet : bool ) -> None :
33
34
with pytest .raises (ValueError ) as excinfo :
34
- SQLite3toMySQL (quiet = quiet )
35
+ SQLite3toMySQL (quiet = quiet ) # type: ignore
35
36
assert "Please provide an SQLite file" in str (excinfo .value )
36
37
37
38
@pytest .mark .init
38
39
@pytest .mark .parametrize ("quiet" , [False , True ])
39
40
def test_invalid_sqlite_file_raises_exception (self , faker : Faker , quiet : bool ) -> None :
40
41
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
42
43
assert "SQLite file does not exist" in str (excinfo .value )
43
44
44
45
@pytest .mark .init
45
46
@pytest .mark .parametrize ("quiet" , [False , True ])
46
47
def test_missing_mysql_user_raises_exception (self , sqlite_database : str , quiet : bool ) -> None :
47
48
with pytest .raises (ValueError ) as excinfo :
48
- SQLite3toMySQL (sqlite_file = sqlite_database , quiet = quiet )
49
+ SQLite3toMySQL (sqlite_file = sqlite_database , quiet = quiet ) # type: ignore
49
50
assert "Please provide a MySQL user" in str (excinfo .value )
50
51
51
52
@pytest .mark .init
@@ -59,7 +60,7 @@ def test_valid_sqlite_file_and_valid_mysql_credentials(
59
60
quiet : bool ,
60
61
):
61
62
with helpers .not_raises (FileNotFoundError ):
62
- SQLite3toMySQL (
63
+ SQLite3toMySQL ( # type: ignore
63
64
sqlite_file = sqlite_database ,
64
65
mysql_user = mysql_credentials .user ,
65
66
mysql_password = mysql_credentials .password ,
@@ -81,7 +82,7 @@ def test_valid_sqlite_file_and_invalid_mysql_credentials_raises_access_denied_ex
81
82
quiet : bool ,
82
83
) -> None :
83
84
with pytest .raises (mysql .connector .Error ) as excinfo :
84
- SQLite3toMySQL (
85
+ SQLite3toMySQL ( # type: ignore[call-arg]
85
86
sqlite_file = sqlite_database ,
86
87
mysql_user = faker .first_name ().lower (),
87
88
mysql_password = faker .password (length = 16 ),
@@ -112,7 +113,7 @@ def test_unspecified_mysql_error(
112
113
)
113
114
caplog .set_level (logging .DEBUG )
114
115
with pytest .raises (mysql .connector .Error ) as excinfo :
115
- SQLite3toMySQL (
116
+ SQLite3toMySQL ( # type: ignore[call-arg]
116
117
sqlite_file = sqlite_database ,
117
118
mysql_user = mysql_credentials .user ,
118
119
mysql_password = mysql_credentials .password ,
@@ -163,7 +164,7 @@ def cursor(
163
164
mocker .patch .object (mysql .connector , "connect" , return_value = FakeMySQLConnection ())
164
165
with pytest .raises (mysql .connector .Error ):
165
166
caplog .set_level (logging .DEBUG )
166
- SQLite3toMySQL (
167
+ SQLite3toMySQL ( # type: ignore[call-arg]
167
168
sqlite_file = sqlite_database ,
168
169
mysql_user = mysql_credentials .user ,
169
170
mysql_password = mysql_credentials .password ,
@@ -186,7 +187,7 @@ def test_bad_mysql_connection(
186
187
return_value = FakeConnector (is_connected = lambda : False ),
187
188
)
188
189
with pytest .raises ((ConnectionError , IOError )) as excinfo :
189
- SQLite3toMySQL (
190
+ SQLite3toMySQL ( # type: ignore[call-arg]
190
191
sqlite_file = sqlite_database ,
191
192
mysql_user = mysql_credentials .user ,
192
193
mysql_password = mysql_credentials .password ,
@@ -214,7 +215,7 @@ def test_log_to_file(
214
215
log_file : LocalPath = tmpdir .join (Path ("db.log" ))
215
216
with pytest .raises (mysql .connector .Error ):
216
217
caplog .set_level (logging .DEBUG )
217
- SQLite3toMySQL (
218
+ SQLite3toMySQL ( # type: ignore[call-arg]
218
219
sqlite_file = sqlite_database ,
219
220
mysql_user = faker .first_name ().lower (),
220
221
mysql_password = faker .password (length = 16 ),
@@ -276,7 +277,7 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
276
277
mysql_insert_method : str ,
277
278
ignore_duplicate_keys : bool ,
278
279
):
279
- proc : SQLite3toMySQL = SQLite3toMySQL (
280
+ proc : SQLite3toMySQL = SQLite3toMySQL ( # type: ignore[call-arg]
280
281
sqlite_file = sqlite_database ,
281
282
mysql_user = mysql_credentials .user ,
282
283
mysql_password = mysql_credentials .password ,
@@ -317,7 +318,9 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
317
318
mysql_inspect : Inspector = inspect (mysql_engine )
318
319
mysql_tables : t .List [str ] = mysql_inspect .get_table_names ()
319
320
320
- mysql_connector_connection : MySQLConnection = mysql .connector .connect (
321
+ mysql_connector_connection : t .Union [
322
+ PooledMySQLConnection , MySQLConnection , CMySQLConnection
323
+ ] = mysql .connector .connect (
321
324
user = mysql_credentials .user ,
322
325
password = mysql_credentials .password ,
323
326
host = mysql_credentials .host ,
@@ -339,7 +342,7 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
339
342
""" Test if all the tables have the same indices """
340
343
index_keys : t .Tuple [str , ...] = ("name" , "column_names" , "unique" )
341
344
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]
343
346
for index in (chain .from_iterable (mysql_inspect .get_indexes (table_name ) for table_name in mysql_tables ))
344
347
)
345
348
@@ -484,7 +487,7 @@ def test_transfer_specific_tables_transfers_only_specified_tables_from_sqlite_fi
484
487
random_sqlite_tables : t .List [str ] = sample (sqlite_tables , table_number )
485
488
random_sqlite_tables .sort ()
486
489
487
- proc : SQLite3toMySQL = SQLite3toMySQL (
490
+ proc : SQLite3toMySQL = SQLite3toMySQL ( # type: ignore[call-arg]
488
491
sqlite_file = sqlite_database ,
489
492
sqlite_tables = random_sqlite_tables ,
490
493
mysql_user = mysql_credentials .user ,
@@ -531,7 +534,7 @@ def test_transfer_specific_tables_transfers_only_specified_tables_from_sqlite_fi
531
534
""" Test if all the tables have the same indices """
532
535
index_keys : t .Tuple [str , ...] = ("name" , "column_names" , "unique" )
533
536
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]
535
538
for index in (chain .from_iterable (mysql_inspect .get_indexes (table_name ) for table_name in mysql_tables ))
536
539
)
537
540
0 commit comments