1414@patch .dict (os .environ , {"REGION" : "" }, clear = False )
1515def test_create_qwen_model_qwq (mock_chat_qwq ):
1616 """Test QwQ model creation uses ChatQwQ."""
17- mock_instance = Mock ()
18- mock_chat_qwq .return_value = mock_instance
19-
20- result = create_qwen_model ("qwq-32b-preview" , api_key = "test-key" )
21-
22- assert result == mock_instance
17+ assert mock_chat_qwq .return_value == create_qwen_model ("qwq-32b-preview" , api_key = "test-key" )
2318 mock_chat_qwq .assert_called_once_with (model = "qwq-32b-preview" , api_key = "test-key" )
2419
2520
2621@patch ("common.models.qwen.ChatQwQ" )
2722@patch .dict (os .environ , {"REGION" : "" }, clear = False )
2823def test_create_qwen_model_qvq (mock_chat_qwq ):
2924 """Test QvQ model creation also uses ChatQwQ."""
30- mock_instance = Mock ()
31- mock_chat_qwq .return_value = mock_instance
32-
33- result = create_qwen_model ("qvq-72b-preview" , api_key = "test-key" )
34-
35- assert result == mock_instance
25+ assert mock_chat_qwq .return_value == create_qwen_model ("qvq-72b-preview" , api_key = "test-key" )
3626 mock_chat_qwq .assert_called_once_with (model = "qvq-72b-preview" , api_key = "test-key" )
3727
3828
3929@patch ("common.models.qwen.ChatQwen" )
4030@patch .dict (os .environ , {"REGION" : "" }, clear = False )
4131def test_create_qwen_model_qwen_plus (mock_chat_qwen ):
4232 """Test Qwen+ model creation uses ChatQwen."""
43- mock_instance = Mock ()
44- mock_chat_qwen .return_value = mock_instance
45-
46- result = create_qwen_model ("qwen-plus" , api_key = "test-key" )
47-
48- assert result == mock_instance
33+ assert mock_chat_qwen .return_value == create_qwen_model ("qwen-plus" , api_key = "test-key" )
4934 mock_chat_qwen .assert_called_once_with (model = "qwen-plus" , api_key = "test-key" )
5035
5136
5237@patch ("common.models.qwen.ChatQwQ" )
5338def test_create_qwen_model_qwq_with_prc_region (mock_chat_qwq ):
5439 """Test QwQ model creation with PRC region."""
55- mock_instance = Mock ()
56- mock_chat_qwq .return_value = mock_instance
57-
58- result = create_qwen_model ("qwq-32b-preview" , api_key = "test-key" , region = "prc" )
59-
60- assert result == mock_instance
40+ assert mock_chat_qwq .return_value == create_qwen_model ("qwq-32b-preview" , api_key = "test-key" , region = "prc" )
6141 mock_chat_qwq .assert_called_once_with (
6242 model = "qwq-32b-preview" ,
6343 api_key = "test-key" ,
@@ -68,12 +48,7 @@ def test_create_qwen_model_qwq_with_prc_region(mock_chat_qwq):
6848@patch ("common.models.qwen.ChatQwen" )
6949def test_create_qwen_model_qwen_plus_with_international_region (mock_chat_qwen ):
7050 """Test Qwen+ model creation with international region."""
71- mock_instance = Mock ()
72- mock_chat_qwen .return_value = mock_instance
73-
74- result = create_qwen_model ("qwen-plus" , api_key = "test-key" , region = "international" )
75-
76- assert result == mock_instance
51+ assert mock_chat_qwen .return_value == create_qwen_model ("qwen-plus" , api_key = "test-key" , region = "international" )
7752 mock_chat_qwen .assert_called_once_with (
7853 model = "qwen-plus" ,
7954 api_key = "test-key" ,
@@ -85,25 +60,15 @@ def test_create_qwen_model_qwen_plus_with_international_region(mock_chat_qwen):
8560@patch .dict (os .environ , {"DASHSCOPE_API_KEY" : "env-key" , "REGION" : "" })
8661def test_create_qwen_model_with_env_key (mock_chat_qwen ):
8762 """Test Qwen model creation using environment variable for API key."""
88- mock_instance = Mock ()
89- mock_chat_qwen .return_value = mock_instance
90-
91- result = create_qwen_model ("qwen-plus" )
92-
93- assert result == mock_instance
63+ assert mock_chat_qwen .return_value == create_qwen_model ("qwen-plus" )
9464 mock_chat_qwen .assert_called_once_with (model = "qwen-plus" , api_key = "env-key" )
9565
9666
9767@patch ("common.models.qwen.ChatQwen" )
9868@patch .dict (os .environ , {"DASHSCOPE_API_KEY" : "env-key" , "REGION" : "prc" })
9969def test_create_qwen_model_with_env_region_prc (mock_chat_qwen ):
10070 """Test Qwen model creation using environment variable for region (PRC)."""
101- mock_instance = Mock ()
102- mock_chat_qwen .return_value = mock_instance
103-
104- result = create_qwen_model ("qwen-plus" )
105-
106- assert result == mock_instance
71+ assert mock_chat_qwen .return_value == create_qwen_model ("qwen-plus" )
10772 mock_chat_qwen .assert_called_once_with (
10873 model = "qwen-plus" ,
10974 api_key = "env-key" ,
@@ -115,12 +80,7 @@ def test_create_qwen_model_with_env_region_prc(mock_chat_qwen):
11580@patch .dict (os .environ , {"DASHSCOPE_API_KEY" : "env-key" , "REGION" : "international" })
11681def test_create_qwq_model_with_env_region_international (mock_chat_qwq ):
11782 """Test QwQ model creation using environment variable for region (international)."""
118- mock_instance = Mock ()
119- mock_chat_qwq .return_value = mock_instance
120-
121- result = create_qwen_model ("qwq-32b-preview" )
122-
123- assert result == mock_instance
83+ assert mock_chat_qwq .return_value == create_qwen_model ("qwq-32b-preview" )
12484 mock_chat_qwq .assert_called_once_with (
12585 model = "qwq-32b-preview" ,
12686 api_key = "env-key" ,
@@ -131,15 +91,10 @@ def test_create_qwq_model_with_env_region_international(mock_chat_qwq):
13191@patch ("common.models.qwen.ChatQwQ" )
13292def test_create_qwq_model_with_custom_base_url (mock_chat_qwq ):
13393 """Test QwQ model creation with custom base URL."""
134- mock_instance = Mock ()
135- mock_chat_qwq .return_value = mock_instance
136-
13794 custom_url = "https://custom.example.com/v1"
138- result = create_qwen_model (
95+ assert mock_chat_qwq . return_value = = create_qwen_model (
13996 "qwq-32b-preview" , api_key = "test-key" , base_url = custom_url
14097 )
141-
142- assert result == mock_instance
14398 mock_chat_qwq .assert_called_once_with (
14499 model = "qwq-32b-preview" , api_key = "test-key" , base_url = custom_url
145100 )
@@ -148,12 +103,7 @@ def test_create_qwq_model_with_custom_base_url(mock_chat_qwq):
148103@patch ("common.models.create_qwen_model" )
149104def test_load_chat_model_qwen_provider (mock_create_qwen ):
150105 """Test load_chat_model with Qwen provider."""
151- mock_instance = Mock ()
152- mock_create_qwen .return_value = mock_instance
153-
154- result = load_chat_model ("qwen:qwq-32b-preview" )
155-
156- assert result == mock_instance
106+ assert mock_create_qwen .return_value == load_chat_model ("qwen:qwq-32b-preview" )
157107 mock_create_qwen .assert_called_once_with ("qwq-32b-preview" )
158108
159109
@@ -162,12 +112,7 @@ def test_load_chat_model_qwen_provider(mock_create_qwen):
162112@patch .dict (os .environ , {"REGION" : "" }, clear = False )
163113def test_create_siliconflow_model_basic (mock_chat_siliconflow ):
164114 """Test basic SiliconFlow model creation."""
165- mock_instance = Mock ()
166- mock_chat_siliconflow .return_value = mock_instance
167-
168- result = create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" )
169-
170- assert result == mock_instance
115+ assert mock_chat_siliconflow .return_value == create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" )
171116 mock_chat_siliconflow .assert_called_once_with (
172117 model = "Qwen/Qwen2.5-72B-Instruct" ,
173118 api_key = "test-key" ,
@@ -177,14 +122,9 @@ def test_create_siliconflow_model_basic(mock_chat_siliconflow):
177122@patch ("common.models.siliconflow.ChatSiliconFlow" )
178123def test_create_siliconflow_model_with_prc_region (mock_chat_siliconflow ):
179124 """Test SiliconFlow model creation with PRC region."""
180- mock_instance = Mock ()
181- mock_chat_siliconflow .return_value = mock_instance
182-
183- result = create_siliconflow_model (
125+ assert mock_chat_siliconflow .return_value == create_siliconflow_model (
184126 "Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" , region = "prc"
185127 )
186-
187- assert result == mock_instance
188128 mock_chat_siliconflow .assert_called_once_with (
189129 model = "Qwen/Qwen2.5-72B-Instruct" ,
190130 api_key = "test-key" ,
@@ -195,14 +135,9 @@ def test_create_siliconflow_model_with_prc_region(mock_chat_siliconflow):
195135@patch ("common.models.siliconflow.ChatSiliconFlow" )
196136def test_create_siliconflow_model_with_international_region (mock_chat_siliconflow ):
197137 """Test SiliconFlow model creation with international region."""
198- mock_instance = Mock ()
199- mock_chat_siliconflow .return_value = mock_instance
200-
201- result = create_siliconflow_model (
138+ assert mock_chat_siliconflow .return_value == create_siliconflow_model (
202139 "Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" , region = "international"
203140 )
204-
205- assert result == mock_instance
206141 mock_chat_siliconflow .assert_called_once_with (
207142 model = "Qwen/Qwen2.5-72B-Instruct" ,
208143 api_key = "test-key" ,
@@ -213,14 +148,9 @@ def test_create_siliconflow_model_with_international_region(mock_chat_siliconflo
213148@patch ("common.models.siliconflow.ChatSiliconFlow" )
214149def test_create_siliconflow_model_with_cn_alias (mock_chat_siliconflow ):
215150 """Test SiliconFlow model creation with 'cn' alias for PRC."""
216- mock_instance = Mock ()
217- mock_chat_siliconflow .return_value = mock_instance
218-
219- result = create_siliconflow_model (
151+ assert mock_chat_siliconflow .return_value == create_siliconflow_model (
220152 "Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" , region = "cn"
221153 )
222-
223- assert result == mock_instance
224154 mock_chat_siliconflow .assert_called_once_with (
225155 model = "Qwen/Qwen2.5-72B-Instruct" ,
226156 api_key = "test-key" ,
@@ -231,14 +161,9 @@ def test_create_siliconflow_model_with_cn_alias(mock_chat_siliconflow):
231161@patch ("common.models.siliconflow.ChatSiliconFlow" )
232162def test_create_siliconflow_model_with_en_alias (mock_chat_siliconflow ):
233163 """Test SiliconFlow model creation with 'en' alias for international."""
234- mock_instance = Mock ()
235- mock_chat_siliconflow .return_value = mock_instance
236-
237- result = create_siliconflow_model (
164+ assert mock_chat_siliconflow .return_value == create_siliconflow_model (
238165 "Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" , region = "en"
239166 )
240-
241- assert result == mock_instance
242167 mock_chat_siliconflow .assert_called_once_with (
243168 model = "Qwen/Qwen2.5-72B-Instruct" ,
244169 api_key = "test-key" ,
@@ -250,12 +175,7 @@ def test_create_siliconflow_model_with_en_alias(mock_chat_siliconflow):
250175@patch .dict (os .environ , {"SILICONFLOW_API_KEY" : "env-key" , "REGION" : "" })
251176def test_create_siliconflow_model_with_env_key (mock_chat_siliconflow ):
252177 """Test SiliconFlow model creation using environment variable for API key."""
253- mock_instance = Mock ()
254- mock_chat_siliconflow .return_value = mock_instance
255-
256- result = create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" )
257-
258- assert result == mock_instance
178+ assert mock_chat_siliconflow .return_value == create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" )
259179 mock_chat_siliconflow .assert_called_once_with (
260180 model = "Qwen/Qwen2.5-72B-Instruct" ,
261181 api_key = "env-key" ,
@@ -266,12 +186,7 @@ def test_create_siliconflow_model_with_env_key(mock_chat_siliconflow):
266186@patch .dict (os .environ , {"SILICONFLOW_API_KEY" : "env-key" , "REGION" : "prc" })
267187def test_create_siliconflow_model_with_env_region_prc (mock_chat_siliconflow ):
268188 """Test SiliconFlow model creation using environment variable for region (PRC)."""
269- mock_instance = Mock ()
270- mock_chat_siliconflow .return_value = mock_instance
271-
272- result = create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" )
273-
274- assert result == mock_instance
189+ assert mock_chat_siliconflow .return_value == create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" )
275190 mock_chat_siliconflow .assert_called_once_with (
276191 model = "Qwen/Qwen2.5-72B-Instruct" ,
277192 api_key = "env-key" ,
@@ -283,12 +198,7 @@ def test_create_siliconflow_model_with_env_region_prc(mock_chat_siliconflow):
283198@patch .dict (os .environ , {"SILICONFLOW_API_KEY" : "env-key" , "REGION" : "international" })
284199def test_create_siliconflow_model_with_env_region_international (mock_chat_siliconflow ):
285200 """Test SiliconFlow model creation using environment variable for region (international)."""
286- mock_instance = Mock ()
287- mock_chat_siliconflow .return_value = mock_instance
288-
289- result = create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" )
290-
291- assert result == mock_instance
201+ assert mock_chat_siliconflow .return_value == create_siliconflow_model ("Qwen/Qwen2.5-72B-Instruct" )
292202 mock_chat_siliconflow .assert_called_once_with (
293203 model = "Qwen/Qwen2.5-72B-Instruct" ,
294204 api_key = "env-key" ,
@@ -299,15 +209,10 @@ def test_create_siliconflow_model_with_env_region_international(mock_chat_silico
299209@patch ("common.models.siliconflow.ChatSiliconFlow" )
300210def test_create_siliconflow_model_with_custom_base_url (mock_chat_siliconflow ):
301211 """Test SiliconFlow model creation with custom base URL."""
302- mock_instance = Mock ()
303- mock_chat_siliconflow .return_value = mock_instance
304-
305212 custom_url = "https://custom.example.com/v1"
306- result = create_siliconflow_model (
213+ assert mock_chat_siliconflow . return_value = = create_siliconflow_model (
307214 "Qwen/Qwen2.5-72B-Instruct" , api_key = "test-key" , base_url = custom_url
308215 )
309-
310- assert result == mock_instance
311216 mock_chat_siliconflow .assert_called_once_with (
312217 model = "Qwen/Qwen2.5-72B-Instruct" ,
313218 api_key = "test-key" ,
@@ -318,24 +223,14 @@ def test_create_siliconflow_model_with_custom_base_url(mock_chat_siliconflow):
318223@patch ("common.models.create_siliconflow_model" )
319224def test_load_chat_model_siliconflow_provider (mock_create_siliconflow ):
320225 """Test load_chat_model with SiliconFlow provider."""
321- mock_instance = Mock ()
322- mock_create_siliconflow .return_value = mock_instance
323-
324- result = load_chat_model ("siliconflow:Qwen/Qwen2.5-72B-Instruct" )
325-
326- assert result == mock_instance
226+ assert mock_create_siliconflow .return_value == load_chat_model ("siliconflow:Qwen/Qwen2.5-72B-Instruct" )
327227 mock_create_siliconflow .assert_called_once_with ("Qwen/Qwen2.5-72B-Instruct" )
328228
329229
330230@patch ("common.utils.init_chat_model" )
331231def test_load_chat_model_standard_provider (mock_init_chat_model ):
332232 """Test load_chat_model with standard provider (non-QwQ)."""
333- mock_instance = Mock ()
334- mock_init_chat_model .return_value = mock_instance
335-
336- result = load_chat_model ("openai:gpt-4o-mini" )
337-
338- assert result == mock_instance
233+ assert mock_init_chat_model .return_value == load_chat_model ("openai:gpt-4o-mini" )
339234 mock_init_chat_model .assert_called_once_with ("gpt-4o-mini" , model_provider = "openai" )
340235
341236
0 commit comments