style: black 格式化测试文件

CI lint 要求 Black 格式化,已应用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
oadank 2026-05-17 17:13:07 +08:00
parent a34ff69b70
commit af9d6c8fe5
2 changed files with 39 additions and 20 deletions

View file

@ -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()
unittest.main()

View file

@ -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()
unittest.main()