55from pathlib import Path
66import tempfile
77import pytest
8+ from pytest_mock import MockerFixture
89from sqlalchemy .engine .base import Engine
910from sqlalchemy .orm import Session
1011
@@ -46,7 +47,7 @@ def base_postgres_config_fixture():
4647class TestGetEngine :
4748 """Test cases for get_engine function."""
4849
49- def test_get_engine_when_initialized (self , mocker ):
50+ def test_get_engine_when_initialized (self , mocker : MockerFixture ):
5051 """Test get_engine returns engine when initialized."""
5152 mock_engine = mocker .MagicMock (spec = Engine )
5253 database .engine = mock_engine
@@ -67,7 +68,7 @@ def test_get_engine_when_not_initialized(self):
6768class TestGetSession :
6869 """Test cases for get_session function."""
6970
70- def test_get_session_when_initialized (self , mocker ):
71+ def test_get_session_when_initialized (self , mocker : MockerFixture ):
7172 """Test get_session returns session when initialized."""
7273 mock_session_local = mocker .MagicMock ()
7374 mock_session = mocker .MagicMock (spec = Session )
@@ -90,7 +91,7 @@ def test_get_session_when_not_initialized(self):
9091class TestCreateTables :
9192 """Test cases for create_tables function."""
9293
93- def test_create_tables_success (self , mocker ):
94+ def test_create_tables_success (self , mocker : MockerFixture ):
9495 """Test create_tables calls Base.metadata.create_all with engine."""
9596 mock_base = mocker .patch ("app.database.Base" )
9697 mock_get_engine = mocker .patch ("app.database.get_engine" )
@@ -102,7 +103,7 @@ def test_create_tables_success(self, mocker):
102103 mock_get_engine .assert_called_once ()
103104 mock_base .metadata .create_all .assert_called_once_with (mock_engine )
104105
105- def test_create_tables_when_engine_not_initialized (self , mocker ):
106+ def test_create_tables_when_engine_not_initialized (self , mocker : MockerFixture ):
106107 """Test create_tables raises error when engine not initialized."""
107108 mock_get_engine = mocker .patch ("app.database.get_engine" )
108109 mock_get_engine .side_effect = RuntimeError ("Database engine not initialized" )
@@ -134,7 +135,7 @@ def test_create_sqlite_engine_directory_not_exists(self):
134135 ):
135136 database ._create_sqlite_engine (config )
136137
137- def test_create_sqlite_engine_creation_failure (self , mocker ):
138+ def test_create_sqlite_engine_creation_failure (self , mocker : MockerFixture ):
138139 """Test _create_sqlite_engine handles engine creation failure."""
139140 mock_create_engine = mocker .patch ("app.database.create_engine" )
140141 with tempfile .TemporaryDirectory () as temp_dir :
@@ -150,7 +151,7 @@ class TestCreatePostgresEngine:
150151 """Test cases for _create_postgres_engine function."""
151152
152153 def test_create_postgres_engine_success_default_schema (
153- self , mocker , base_postgres_config
154+ self , mocker : MockerFixture , base_postgres_config
154155 ):
155156 """Test _create_postgres_engine creates engine successfully with default schema."""
156157 mock_create_engine = mocker .patch ("app.database.create_engine" )
@@ -170,7 +171,7 @@ def test_create_postgres_engine_success_default_schema(
170171 assert expected_url == call_args [0 ][0 ]
171172
172173 def test_create_postgres_engine_success_custom_schema (
173- self , mocker , base_postgres_config
174+ self , mocker : MockerFixture , base_postgres_config
174175 ):
175176 """Test _create_postgres_engine creates engine successfully with custom schema."""
176177 mock_create_engine = mocker .patch ("app.database.create_engine" )
@@ -191,7 +192,9 @@ def test_create_postgres_engine_success_custom_schema(
191192 mock_connection .execute .assert_called_once ()
192193 mock_connection .commit .assert_called_once ()
193194
194- def test_create_postgres_engine_with_ca_cert (self , mocker , base_postgres_config ):
195+ def test_create_postgres_engine_with_ca_cert (
196+ self , mocker : MockerFixture , base_postgres_config
197+ ):
195198 """Test _create_postgres_engine with CA certificate path."""
196199 mock_create_engine = mocker .patch ("app.database.create_engine" )
197200 mock_engine = mocker .MagicMock (spec = Engine )
@@ -209,7 +212,7 @@ def test_create_postgres_engine_with_ca_cert(self, mocker, base_postgres_config)
209212 assert call_args [1 ]["connect_args" ]["sslrootcert" ] == cert_file .name
210213
211214 def test_create_postgres_engine_creation_failure (
212- self , mocker , base_postgres_config
215+ self , mocker : MockerFixture , base_postgres_config
213216 ):
214217 """Test _create_postgres_engine handles engine creation failure."""
215218 mock_create_engine = mocker .patch ("app.database.create_engine" )
@@ -219,7 +222,7 @@ def test_create_postgres_engine_creation_failure(
219222 database ._create_postgres_engine (base_postgres_config )
220223
221224 def test_create_postgres_engine_schema_creation_failure (
222- self , mocker , base_postgres_config
225+ self , mocker : MockerFixture , base_postgres_config
223226 ):
224227 """Test _create_postgres_engine handles schema creation failure."""
225228 mock_create_engine = mocker .patch ("app.database.create_engine" )
@@ -240,7 +243,12 @@ class TestInitializeDatabase:
240243 """Test cases for initialize_database function."""
241244
242245 def _setup_common_mocks (
243- self , * , mocker , mock_sessionmaker , mock_logger , enable_debug = False
246+ self ,
247+ * ,
248+ mocker : MockerFixture ,
249+ mock_sessionmaker ,
250+ mock_logger ,
251+ enable_debug = False ,
244252 ):
245253 """Setup common mocks for initialize_database tests."""
246254 mock_engine = mocker .MagicMock (spec = Engine )
@@ -261,7 +269,7 @@ def _verify_common_assertions(
261269
262270 def test_initialize_database_sqlite (
263271 self ,
264- mocker ,
272+ mocker : MockerFixture ,
265273 ):
266274 """Test initialize_database with SQLite configuration."""
267275 # Setup mocks
@@ -295,7 +303,7 @@ def test_initialize_database_sqlite(
295303
296304 def test_initialize_database_postgres (
297305 self ,
298- mocker ,
306+ mocker : MockerFixture ,
299307 base_postgres_config ,
300308 ):
301309 """Test initialize_database with PostgreSQL configuration."""
0 commit comments