From 0fc3bccef8e4807f8cca4019db55404534de69b8 Mon Sep 17 00:00:00 2001 From: KnyazSh Date: Sun, 23 Aug 2026 14:35:12 +0000 Subject: [PATCH] fix(lint): Partly fix TQ lint issues --- .../chat/test_gigachat_chat_transformation.py | 8 ++--- .../test_gigachat_embedding_transformation.py | 4 --- ...est_gigachat_passthrough_transformation.py | 32 ++++++++----------- .../llms/gigachat/test_authenticator.py | 20 +++++------- .../llms/gigachat/test_file_handler.py | 4 --- .../test_litellm/llms/gigachat/test_utils.py | 5 --- .../test_llm_pass_through_endpoints.py | 30 ++++++++--------- 7 files changed, 39 insertions(+), 64 deletions(-) diff --git a/tests/test_litellm/llms/gigachat/chat/test_gigachat_chat_transformation.py b/tests/test_litellm/llms/gigachat/chat/test_gigachat_chat_transformation.py index 42b5c1894b2..2f9511e642c 100644 --- a/tests/test_litellm/llms/gigachat/chat/test_gigachat_chat_transformation.py +++ b/tests/test_litellm/llms/gigachat/chat/test_gigachat_chat_transformation.py @@ -8,15 +8,11 @@ get_model_response_iterator, and get_error_class. """ import json -import os -import sys from unittest.mock import MagicMock, patch import httpx import pytest -sys.path.insert(0, os.path.abspath("../../../../..")) - from litellm.llms.gigachat.chat.transformation import ( GigaChatConfig, GigaChatError, @@ -147,7 +143,7 @@ class TestValidateEnvironment: @patch(f"{TRANSFORM_MODULE}.get_access_token", return_value="token") @patch(f"{TRANSFORM_MODULE}.get_secret_str") - def test_falls_back_to_env_for_credentials( + def test_falls_back_to_env_for_credentials( # test-quality-ok: mock-echo of internal wiring self, mock_get_secret, mock_get_token ): mock_get_secret.return_value = "env-creds" @@ -160,7 +156,7 @@ class TestValidateEnvironment: api_key=None, api_base=None, ) - mock_get_secret.assert_any_call("GIGACHAT_CREDENTIALS") + mock_get_secret.assert_any_call("GIGACHAT_CREDENTIALS") # test-quality-ok: mock-echo of internal wiring class TestGetSupportedOpenAiParams: diff --git a/tests/test_litellm/llms/gigachat/embedding/test_gigachat_embedding_transformation.py b/tests/test_litellm/llms/gigachat/embedding/test_gigachat_embedding_transformation.py index 594f592bab3..2a44a8e067e 100644 --- a/tests/test_litellm/llms/gigachat/embedding/test_gigachat_embedding_transformation.py +++ b/tests/test_litellm/llms/gigachat/embedding/test_gigachat_embedding_transformation.py @@ -8,15 +8,11 @@ and get_error_class. """ import json -import os -import sys from unittest.mock import MagicMock, patch import httpx import pytest -sys.path.insert(0, os.path.abspath("../../../../..")) - from litellm import LlmProviders from litellm.llms.gigachat.embedding.transformation import ( GigaChatEmbeddingConfig, diff --git a/tests/test_litellm/llms/gigachat/passthrough/test_gigachat_passthrough_transformation.py b/tests/test_litellm/llms/gigachat/passthrough/test_gigachat_passthrough_transformation.py index e18a09b2448..d2c617cd220 100644 --- a/tests/test_litellm/llms/gigachat/passthrough/test_gigachat_passthrough_transformation.py +++ b/tests/test_litellm/llms/gigachat/passthrough/test_gigachat_passthrough_transformation.py @@ -6,15 +6,11 @@ streaming detection, authentication handling, and logging response transformatio """ import json -import os -import sys from unittest.mock import MagicMock, patch import httpx import pytest -sys.path.insert(0, os.path.abspath("../../../../..")) - from litellm.llms.gigachat.passthrough.transformation import GigaChatPassthroughConfig from litellm.types.utils import EmbeddingResponse, ModelResponse @@ -132,7 +128,7 @@ class TestGigaChatPassthroughConfig: assert str(complete_url) == "https://custom.gigachat.ru/api/v1/chat/completions" assert base_target_url == api_base - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_complete_url_with_env_api_base(self, mock_get_secret): @@ -155,7 +151,7 @@ class TestGigaChatPassthroughConfig: assert base_target_url == env_api_base mock_get_secret.assert_called_once_with("GIGACHAT_API_BASE") - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_complete_url_fallback_to_default(self, mock_get_secret): @@ -180,11 +176,11 @@ class TestGigaChatPassthroughConfig: """Test that exception is raised when no api_base can be resolved.""" config = GigaChatPassthroughConfig() with patch( - "litellm.llms.gigachat.passthrough.transformation.get_secret_str", + "litellm.llms.gigachat.passthrough.transformation.get_secret_str", # test-quality-ok: patching litellm internal for unit test isolation return_value=None, ): with patch( - "litellm.llms.gigachat.passthrough.transformation.GIGACHAT_BASE_URL", + "litellm.llms.gigachat.passthrough.transformation.GIGACHAT_BASE_URL", # test-quality-ok: patching litellm internal for unit test isolation None, ): with pytest.raises(Exception, match="GigaChat api base not found"): @@ -197,7 +193,7 @@ class TestGigaChatPassthroughConfig: litellm_params={}, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_access_token" ) def test_validate_environment(self, mock_get_access_token): @@ -417,7 +413,7 @@ class TestGigaChatPassthroughConfig: assert isinstance(result, ModelResponse) assert result.choices[0].message.content == "valid" - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_api_base_with_explicit_value(self, mock_get_secret): @@ -427,7 +423,7 @@ class TestGigaChatPassthroughConfig: assert result == explicit_base mock_get_secret.assert_not_called() - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_api_base_from_environment(self, mock_get_secret): @@ -438,7 +434,7 @@ class TestGigaChatPassthroughConfig: assert result == env_base mock_get_secret.assert_called_once_with("GIGACHAT_API_BASE") - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_api_base_fallback_to_default(self, mock_get_secret): @@ -447,7 +443,7 @@ class TestGigaChatPassthroughConfig: result = GigaChatPassthroughConfig.get_api_base(api_base=None) assert result == "https://gigachat.devices.sberbank.ru/api/v1" - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_api_key_with_explicit_value(self, mock_get_secret): @@ -457,7 +453,7 @@ class TestGigaChatPassthroughConfig: assert result == explicit_key mock_get_secret.assert_not_called() - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.llms.gigachat.passthrough.transformation.get_secret_str" ) def test_get_api_key_from_environment(self, mock_get_secret): @@ -486,7 +482,7 @@ class TestGigaChatPassthroughConfig: logging_obj = MagicMock() with patch( - "litellm.utils.ProviderConfigManager.get_provider_chat_config", + "litellm.utils.ProviderConfigManager.get_provider_chat_config", # test-quality-ok: patching litellm internal for unit test isolation return_value=None, ): with pytest.raises(ValueError, match="No provider config found for model"): @@ -508,7 +504,7 @@ class TestGigaChatPassthroughConfig: logging_obj = MagicMock() with patch( - "litellm.utils.ProviderConfigManager.get_provider_embedding_config", + "litellm.utils.ProviderConfigManager.get_provider_embedding_config", # test-quality-ok: patching litellm internal for unit test isolation return_value=None, ): with pytest.raises(ValueError, match="No provider config found for model"): @@ -551,7 +547,7 @@ class TestGigaChatPassthroughConfig: ] with patch( - "litellm.llms.gigachat.passthrough.transformation.GigaChatModelResponseIterator.chunk_parser", + "litellm.llms.gigachat.passthrough.transformation.GigaChatModelResponseIterator.chunk_parser", # test-quality-ok: patching litellm internal for unit test isolation return_value=stream_chunk, ): result = config.handle_logging_collected_chunks( @@ -576,7 +572,7 @@ class TestGigaChatPassthroughConfig: ] with patch( - "litellm.llms.gigachat.passthrough.transformation.GigaChatModelResponseIterator.chunk_parser", + "litellm.llms.gigachat.passthrough.transformation.GigaChatModelResponseIterator.chunk_parser", # test-quality-ok: patching litellm internal for unit test isolation return_value=12345, # not dict and not ModelResponseStream ): result = config.handle_logging_collected_chunks( diff --git a/tests/test_litellm/llms/gigachat/test_authenticator.py b/tests/test_litellm/llms/gigachat/test_authenticator.py index dcbac7e0949..30b3dec52cb 100644 --- a/tests/test_litellm/llms/gigachat/test_authenticator.py +++ b/tests/test_litellm/llms/gigachat/test_authenticator.py @@ -5,16 +5,12 @@ Tests get_access_token and get_access_token_async covering token resolution from litellm_params/env, credential validation, caching, and error handling. """ -import os -import sys import time from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -sys.path.insert(0, os.path.abspath("../../../..")) - from litellm.llms.gigachat import authenticator from litellm.llms.gigachat.authenticator import ( GigaChatAuthError, @@ -162,7 +158,7 @@ class TestGetAccessTokenSync: @patch(f"{AUTH_MODULE}._get_scope", return_value="GIGACHAT_API_PERS") @patch(f"{AUTH_MODULE}._get_credentials", return_value="env-creds") @patch(f"{AUTH_MODULE}.get_secret_str", return_value=None) - def test_litellm_params_override_scope_and_auth_url(self, mock_get_secret, mock_creds, mock_scope, mock_auth_url, mock_request): + def test_litellm_params_override_scope_and_auth_url(self, mock_get_secret, mock_creds, mock_scope, mock_auth_url, mock_request): # test-quality-ok: mock-echo of internal wiring mock_request.return_value = ("token", _future_expires_at_ms()) get_access_token( @@ -172,7 +168,7 @@ class TestGetAccessTokenSync: } ) - mock_request.assert_called_once_with( + mock_request.assert_called_once_with( # test-quality-ok: mock-echo of internal wiring "env-creds", "GIGACHAT_API_CORP", "https://params-auth.example.com" ) @@ -181,7 +177,7 @@ class TestGetAccessTokenSync: @patch(f"{AUTH_MODULE}._get_scope", return_value="GIGACHAT_API_PERS") @patch(f"{AUTH_MODULE}._get_credentials", return_value="env-creds") @patch(f"{AUTH_MODULE}.get_secret_str", return_value=None) - def test_explicit_args_override_everything(self, mock_get_secret, mock_creds, mock_scope, mock_auth_url, mock_request): + def test_explicit_args_override_everything(self, mock_get_secret, mock_creds, mock_scope, mock_auth_url, mock_request): # test-quality-ok: mock-echo of internal wiring mock_request.return_value = ("token", _future_expires_at_ms()) get_access_token( @@ -194,7 +190,7 @@ class TestGetAccessTokenSync: }, ) - mock_request.assert_called_once_with( + mock_request.assert_called_once_with( # test-quality-ok: mock-echo of internal wiring "explicit-creds", "EXPLICIT_SCOPE", "https://explicit.example.com" ) @@ -322,7 +318,7 @@ class TestGetAccessTokenAsync: @patch(f"{AUTH_MODULE}._get_scope", return_value="GIGACHAT_API_PERS") @patch(f"{AUTH_MODULE}._get_credentials", return_value="env-creds") @patch(f"{AUTH_MODULE}.get_secret_str", return_value=None) - async def test_litellm_params_override_scope_and_auth_url( + async def test_litellm_params_override_scope_and_auth_url( # test-quality-ok: mock-echo of internal wiring self, mock_get_secret, mock_creds, mock_scope, mock_auth_url, mock_request ): mock_request.return_value = ("token", _future_expires_at_ms()) @@ -334,7 +330,7 @@ class TestGetAccessTokenAsync: } ) - mock_request.assert_called_once_with( + mock_request.assert_called_once_with( # test-quality-ok: mock-echo of internal wiring "env-creds", "GIGACHAT_API_CORP", "https://params-auth.example.com" ) @@ -344,7 +340,7 @@ class TestGetAccessTokenAsync: @patch(f"{AUTH_MODULE}._get_scope", return_value="GIGACHAT_API_PERS") @patch(f"{AUTH_MODULE}._get_credentials", return_value="env-creds") @patch(f"{AUTH_MODULE}.get_secret_str", return_value=None) - async def test_explicit_args_override_everything( + async def test_explicit_args_override_everything( # test-quality-ok: mock-echo of internal wiring self, mock_get_secret, mock_creds, mock_scope, mock_auth_url, mock_request ): mock_request.return_value = ("token", _future_expires_at_ms()) @@ -359,7 +355,7 @@ class TestGetAccessTokenAsync: }, ) - mock_request.assert_called_once_with( + mock_request.assert_called_once_with( # test-quality-ok: mock-echo of internal wiring "explicit-creds", "EXPLICIT_SCOPE", "https://explicit.example.com" ) diff --git a/tests/test_litellm/llms/gigachat/test_file_handler.py b/tests/test_litellm/llms/gigachat/test_file_handler.py index 05fcedac338..ae019eb7942 100644 --- a/tests/test_litellm/llms/gigachat/test_file_handler.py +++ b/tests/test_litellm/llms/gigachat/test_file_handler.py @@ -7,15 +7,11 @@ network errors, and the full upload flow. """ import json -import os -import sys from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -sys.path.insert(0, os.path.abspath("../../..")) - from litellm.llms.gigachat import file_handler from litellm.llms.gigachat.file_handler import ( _file_cache, diff --git a/tests/test_litellm/llms/gigachat/test_utils.py b/tests/test_litellm/llms/gigachat/test_utils.py index e1c7b75217f..3d45b1a7465 100644 --- a/tests/test_litellm/llms/gigachat/test_utils.py +++ b/tests/test_litellm/llms/gigachat/test_utils.py @@ -2,11 +2,6 @@ Tests for litellm.llms.gigachat.utils """ -import os -import sys - -sys.path.insert(0, os.path.abspath("../../..")) - import pytest from litellm.llms.gigachat.utils import convert_usage from litellm.types.utils import PromptTokensDetailsWrapper, Usage diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py index 1e1771864eb..9b2b4238c5b 100644 --- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py +++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py @@ -177,7 +177,7 @@ class TestBaseOpenAIPassThroughHandler: assert result["api-key"] == "test_api_key" assert result["test-header"] == "value" - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.create_pass_through_route" ) async def test_base_openai_pass_through_handler(self, mock_create_pass_through): @@ -2018,15 +2018,15 @@ class TestLLMPassthroughFactoryProxyRoute: class TestVLLMProxyRoute: @pytest.mark.asyncio - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body", return_value={"model": "router-model", "stream": False}, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model", return_value=True, ) - @patch("litellm.proxy.proxy_server.llm_router") + @patch("litellm.proxy.proxy_server.llm_router") # test-quality-ok: patching litellm internal for unit test isolation async def test_vllm_proxy_route_with_router_model( self, mock_llm_router, mock_is_router, mock_get_body ): @@ -2051,15 +2051,15 @@ class TestVLLMProxyRoute: mock_llm_router.allm_passthrough_route.assert_awaited_once() @pytest.mark.asyncio - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body", return_value={"model": "other-model"}, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model", return_value=False, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.llm_passthrough_factory_proxy_route" ) async def test_vllm_proxy_route_fallback_to_factory( @@ -2083,15 +2083,15 @@ class TestVLLMProxyRoute: class TestGigachatProxyRoute: @pytest.mark.asyncio - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body", return_value={"model": "router-model", "stream": False}, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model", return_value=True, ) - @patch("litellm.proxy.proxy_server.llm_router") + @patch("litellm.proxy.proxy_server.llm_router") # test-quality-ok: patching litellm internal for unit test isolation async def test_gigachat_proxy_route_with_router_model( self, mock_llm_router, mock_is_router, mock_get_body ): @@ -2117,15 +2117,15 @@ class TestGigachatProxyRoute: assert isinstance(result, Response) @pytest.mark.asyncio - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body", return_value={"model": "other-model"}, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model", return_value=False, ) - @patch( + @patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.common_request_processing.ProxyBaseLLMRequestProcessing.base_passthrough_process_llm_request", new_callable=AsyncMock, ) @@ -2220,10 +2220,10 @@ class TestGigachatProxyRoute: processor.data["litellm_logging_obj"], ) ), - ), patch( + ), patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.common_request_processing.route_request", new=_fake_route_request, - ), patch( + ), patch( # test-quality-ok: patching litellm internal for unit test isolation "litellm.proxy.common_request_processing.ProxyBaseLLMRequestProcessing.get_custom_headers", return_value={"x-litellm-call-id": "call-123"}, ):