From af9d6c8fe5f736a358a1d2f270ce8db406e7d7c0 Mon Sep 17 00:00:00 2001 From: oadank Date: Sun, 17 May 2026 17:13:07 +0800 Subject: [PATCH] =?UTF-8?q?style:=20black=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI lint 要求 Black 格式化,已应用 Co-Authored-By: Claude Opus 4.7 --- .../llms/domestic/test_domestic_utils.py | 24 +++++++++---- .../test_handler_json_arguments.py | 35 +++++++++++-------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/tests/test_litellm/llms/domestic/test_domestic_utils.py b/tests/test_litellm/llms/domestic/test_domestic_utils.py index cdd38325ff7..0fdff3b8594 100644 --- a/tests/test_litellm/llms/domestic/test_domestic_utils.py +++ b/tests/test_litellm/llms/domestic/test_domestic_utils.py @@ -142,25 +142,37 @@ class TestIsDomesticModelOrEndpoint(unittest.TestCase): def test_domestic_model_non_domestic_endpoint(self): """Test domestic model with non-domestic endpoint.""" - self.assertTrue(is_domestic_model_or_endpoint("qwen3.5-plus", "https://api.openai.com/v1")) + self.assertTrue( + is_domestic_model_or_endpoint("qwen3.5-plus", "https://api.openai.com/v1") + ) def test_non_domestic_model_domestic_endpoint(self): """Test non-domestic model with domestic endpoint.""" - self.assertTrue(is_domestic_model_or_endpoint("gpt-4", "https://dashscope.aliyuncs.com/v1")) + self.assertTrue( + is_domestic_model_or_endpoint("gpt-4", "https://dashscope.aliyuncs.com/v1") + ) def test_both_domestic(self): """Test both model and endpoint are domestic.""" - self.assertTrue(is_domestic_model_or_endpoint("deepseek-coder", "https://api.deepseek.com/v1")) + self.assertTrue( + is_domestic_model_or_endpoint( + "deepseek-coder", "https://api.deepseek.com/v1" + ) + ) def test_both_non_domestic(self): """Test both model and endpoint are non-domestic.""" - self.assertFalse(is_domestic_model_or_endpoint("gpt-4", "https://api.openai.com/v1")) + self.assertFalse( + is_domestic_model_or_endpoint("gpt-4", "https://api.openai.com/v1") + ) def test_none_values(self): """Test None values.""" self.assertFalse(is_domestic_model_or_endpoint(None, None)) self.assertTrue(is_domestic_model_or_endpoint("minimax", None)) - self.assertFalse(is_domestic_model_or_endpoint(None, "https://api.openai.com/v1")) + self.assertFalse( + is_domestic_model_or_endpoint(None, "https://api.openai.com/v1") + ) def test_empty_values(self): """Test empty values.""" @@ -224,4 +236,4 @@ class TestDisableCompatibility(unittest.TestCase): if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() diff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_handler_json_arguments.py b/tests/test_litellm/responses/litellm_completion_transformation/test_handler_json_arguments.py index 3eb05fdaabf..a5cb25f1860 100644 --- a/tests/test_litellm/responses/litellm_completion_transformation/test_handler_json_arguments.py +++ b/tests/test_litellm/responses/litellm_completion_transformation/test_handler_json_arguments.py @@ -43,7 +43,9 @@ class TestEnsureToolCallsValidJsonArguments(unittest.TestCase): } ] result = self.handler._ensure_all_tool_calls_have_valid_json_arguments(messages) - self.assertEqual(result[0]["tool_calls"][0]["function"]["arguments"], '{"key": "value"}') + self.assertEqual( + result[0]["tool_calls"][0]["function"]["arguments"], '{"key": "value"}' + ) def test_empty_arguments(self): """Test that empty arguments are converted to '{}'.""" @@ -128,7 +130,10 @@ class TestEnsureToolCallsValidJsonArguments(unittest.TestCase): ] result = self.handler._ensure_all_tool_calls_have_valid_json_arguments(messages) # dict should be converted to JSON string - self.assertEqual(result[0]["tool_calls"][0]["function"]["arguments"], '{"key": "value", "number": 42}') + self.assertEqual( + result[0]["tool_calls"][0]["function"]["arguments"], + '{"key": "value", "number": 42}', + ) def test_whitespace_arguments(self): """Test that whitespace-only arguments are converted to '{}'.""" @@ -206,7 +211,9 @@ class TestEnsureToolCallsValidJsonArguments(unittest.TestCase): ] result = self.handler._ensure_all_tool_calls_have_valid_json_arguments(messages) # First should be preserved (valid) - self.assertEqual(result[0]["tool_calls"][0]["function"]["arguments"], '{"valid": true}') + self.assertEqual( + result[0]["tool_calls"][0]["function"]["arguments"], '{"valid": true}' + ) # Second should be fixed (invalid -> {}) self.assertEqual(result[0]["tool_calls"][1]["function"]["arguments"], "{}") # Third should be fixed (None -> {}) @@ -219,15 +226,13 @@ class TestEnsureToolCallsValidJsonArguments(unittest.TestCase): def test_complex_valid_json(self): """Test that complex valid JSON is preserved.""" - complex_json = json.dumps({ - "nested": { - "deep": { - "value": [1, 2, 3] - } - }, - "string": "with \"escaped\" quotes", - "number": 123.456 - }) + complex_json = json.dumps( + { + "nested": {"deep": {"value": [1, 2, 3]}}, + "string": 'with "escaped" quotes', + "number": 123.456, + } + ) messages = [ { "role": "assistant", @@ -245,8 +250,10 @@ class TestEnsureToolCallsValidJsonArguments(unittest.TestCase): } ] result = self.handler._ensure_all_tool_calls_have_valid_json_arguments(messages) - self.assertEqual(result[0]["tool_calls"][0]["function"]["arguments"], complex_json) + self.assertEqual( + result[0]["tool_calls"][0]["function"]["arguments"], complex_json + ) if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main()