fix: Resolve TypeError in SSL verification tests by mocking Model class

This commit is contained in:
Paul Gauthier (aider) 2025-03-05 18:42:03 -08:00
parent e5a85108d7
commit 85b9bdd8f4
2 changed files with 37 additions and 24 deletions

View file

@ -687,6 +687,12 @@ class TestMain(TestCase):
@patch("aider.models.ModelInfoManager.set_verify_ssl") @patch("aider.models.ModelInfoManager.set_verify_ssl")
def test_no_verify_ssl_sets_model_info_manager(self, mock_set_verify_ssl): def test_no_verify_ssl_sets_model_info_manager(self, mock_set_verify_ssl):
with GitTemporaryDirectory(): with GitTemporaryDirectory():
# Mock Model class to avoid actual model initialization
with patch("aider.models.Model") as mock_model:
# Configure the mock to avoid the TypeError
mock_model.return_value.info = {}
mock_model.return_value.validate_environment.return_value = {"missing_keys": [], "keys_in_environment": []}
main( main(
["--no-verify-ssl", "--exit", "--yes"], ["--no-verify-ssl", "--exit", "--yes"],
input=DummyInput(), input=DummyInput(),

View file

@ -19,7 +19,7 @@ class TestSSLVerification(TestCase):
os.environ.clear() os.environ.clear()
os.environ.update(self.original_env) os.environ.update(self.original_env)
@patch("aider.models.model_info_manager.set_verify_ssl") @patch("aider.models.ModelInfoManager.set_verify_ssl")
@patch("aider.llm.litellm._load_litellm") @patch("aider.llm.litellm._load_litellm")
@patch("httpx.Client") @patch("httpx.Client")
@patch("httpx.AsyncClient") @patch("httpx.AsyncClient")
@ -29,6 +29,13 @@ class TestSSLVerification(TestCase):
# Mock the litellm._lazy_module to avoid AttributeError # Mock the litellm._lazy_module to avoid AttributeError
mock_load_litellm.return_value = None mock_load_litellm.return_value = None
mock_module = MagicMock() mock_module = MagicMock()
# Mock Model class to avoid actual model initialization
with patch("aider.models.Model") as mock_model:
# Configure the mock to avoid the TypeError
mock_model.return_value.info = {}
mock_model.return_value.validate_environment.return_value = {"missing_keys": [], "keys_in_environment": []}
with patch("aider.llm.litellm._lazy_module", mock_module): with patch("aider.llm.litellm._lazy_module", mock_module):
# Run main with --no-verify-ssl flag # Run main with --no-verify-ssl flag
main( main(