Skip to content

Commit 7d35afb

Browse files
committed
Run isort and ruff locally to fix pre commit hooks issue
Signed-off-by: Adrian Garcia <adrian.garcia@inceptionai.ai>
1 parent 4a10460 commit 7d35afb

File tree

6 files changed

+847
-670
lines changed

6 files changed

+847
-670
lines changed

tests/test_logger.py

Lines changed: 85 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from dataclasses import dataclass
1010
from json.decoder import JSONDecodeError
1111
from tempfile import NamedTemporaryFile
12-
from typing import Any, Sequence
13-
from unittest.mock import patch, MagicMock
12+
from typing import Any
13+
from unittest.mock import MagicMock, patch
1414
from uuid import uuid4
1515

1616
import pytest
@@ -138,16 +138,19 @@ def test_an_error_is_raised_when_custom_logging_config_is_invalid_json():
138138

139139

140140
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
141-
@pytest.mark.parametrize("unexpected_config", (
142-
"Invalid string",
143-
[{
144-
"version": 1,
145-
"loggers": []
146-
}],
147-
0,
148-
))
141+
@pytest.mark.parametrize(
142+
"unexpected_config",
143+
(
144+
"Invalid string",
145+
[{
146+
"version": 1,
147+
"loggers": []
148+
}],
149+
0,
150+
),
151+
)
149152
def test_an_error_is_raised_when_custom_logging_config_is_unexpected_json(
150-
unexpected_config: Any):
153+
unexpected_config: Any, ):
151154
"""This test calls _configure_vllm_root_logger again to test custom logging
152155
config behavior, however it fails before any change in behavior or
153156
configuration occurs."""
@@ -174,14 +177,16 @@ def test_custom_logging_config_is_parsed_and_used_when_provided():
174177
"propagate": False,
175178
}
176179
},
177-
"version": 1
180+
"version": 1,
178181
}
179182
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
180183
logging_config_file.write(json.dumps(valid_logging_config))
181184
logging_config_file.flush()
182-
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH",
183-
logging_config_file.name), patch(
184-
"vllm.logger.dictConfig") as dict_config_mock:
185+
with (
186+
patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH",
187+
logging_config_file.name),
188+
patch("vllm.logger.dictConfig") as dict_config_mock,
189+
):
185190
_configure_vllm_root_logger()
186191
dict_config_mock.assert_called_with(valid_logging_config)
187192

@@ -197,7 +202,7 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
197202
"handlers": [],
198203
}
199204
},
200-
"version": 1
205+
"version": 1,
201206
}
202207
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
203208
logging_config_file.write(json.dumps(valid_logging_config))
@@ -223,21 +228,22 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
223228

224229

225230
def test_prepare_object_to_dump():
226-
str_obj = 'str'
231+
str_obj = "str"
227232
assert prepare_object_to_dump(str_obj) == "'str'"
228233

229234
list_obj = [1, 2, 3]
230-
assert prepare_object_to_dump(list_obj) == '[1, 2, 3]'
235+
assert prepare_object_to_dump(list_obj) == "[1, 2, 3]"
231236

232-
dict_obj = {'a': 1, 'b': 'b'}
237+
dict_obj = {"a": 1, "b": "b"}
233238
assert prepare_object_to_dump(dict_obj) in [
234-
"{a: 1, b: 'b'}", "{b: 'b', a: 1}"
239+
"{a: 1, b: 'b'}",
240+
"{b: 'b', a: 1}",
235241
]
236242

237243
set_obj = {1, 2, 3}
238-
assert prepare_object_to_dump(set_obj) == '[1, 2, 3]'
244+
assert prepare_object_to_dump(set_obj) == "[1, 2, 3]"
239245

240-
tuple_obj = ('a', 'b', 'c')
246+
tuple_obj = ("a", "b", "c")
241247
assert prepare_object_to_dump(tuple_obj) == "['a', 'b', 'c']"
242248

243249
class CustomEnum(enum.Enum):
@@ -253,114 +259,115 @@ class CustomClass:
253259
b: str
254260

255261
assert (prepare_object_to_dump(CustomClass(
256-
1, 'b')) == "CustomClass(a=1, b='b')")
262+
1, "b")) == "CustomClass(a=1, b='b')")
257263

258264

259265
def test_request_logger_log_outputs():
260266
"""Test the new log_outputs functionality."""
261267
# Create a mock logger to capture log calls
262268
mock_logger = MagicMock()
263-
264-
with patch('vllm.entrypoints.logger.logger', mock_logger):
269+
270+
with patch("vllm.entrypoints.logger.logger", mock_logger):
265271
request_logger = RequestLogger(max_log_len=None)
266-
272+
267273
# Test basic output logging
268274
request_logger.log_outputs(
269275
request_id="test-123",
270276
outputs="Hello, world!",
271277
output_token_ids=[1, 2, 3, 4],
272278
finish_reason="stop",
273279
is_streaming=False,
274-
delta=False
280+
delta=False,
275281
)
276-
282+
277283
mock_logger.info.assert_called_once()
278284
call_args = mock_logger.info.call_args[0]
279285
assert "Generated response test-123" in call_args[0]
280286
assert "Hello, world!" in call_args[1]
281-
assert [1, 2, 3, 4] == call_args[2]
282-
assert "stop" == call_args[3]
287+
assert call_args[2] == [1, 2, 3, 4]
288+
assert call_args[3] == "stop"
283289

284290

285291
def test_request_logger_log_outputs_streaming_delta():
286292
"""Test log_outputs with streaming delta mode."""
287293
mock_logger = MagicMock()
288-
289-
with patch('vllm.entrypoints.logger.logger', mock_logger):
294+
295+
with patch("vllm.entrypoints.logger.logger", mock_logger):
290296
request_logger = RequestLogger(max_log_len=None)
291-
297+
292298
# Test streaming delta logging
293299
request_logger.log_outputs(
294300
request_id="test-456",
295301
outputs="Hello",
296302
output_token_ids=[1],
297303
finish_reason=None,
298304
is_streaming=True,
299-
delta=True
305+
delta=True,
300306
)
301-
307+
302308
mock_logger.info.assert_called_once()
303309
call_args = mock_logger.info.call_args[0]
304310
assert "Generated response test-456 (streaming delta)" in call_args[0]
305-
assert "Hello" == call_args[1]
306-
assert [1] == call_args[2]
311+
assert call_args[1] == "Hello"
312+
assert call_args[2] == [1]
307313
assert call_args[3] is None
308314

309315

310316
def test_request_logger_log_outputs_streaming_complete():
311317
"""Test log_outputs with streaming complete mode."""
312318
mock_logger = MagicMock()
313-
314-
with patch('vllm.entrypoints.logger.logger', mock_logger):
319+
320+
with patch("vllm.entrypoints.logger.logger", mock_logger):
315321
request_logger = RequestLogger(max_log_len=None)
316-
322+
317323
# Test streaming complete logging
318324
request_logger.log_outputs(
319325
request_id="test-789",
320326
outputs="Complete response",
321327
output_token_ids=[1, 2, 3],
322328
finish_reason="length",
323329
is_streaming=True,
324-
delta=False
330+
delta=False,
325331
)
326-
332+
327333
mock_logger.info.assert_called_once()
328334
call_args = mock_logger.info.call_args[0]
329-
assert "Generated response test-789 (streaming complete)" in call_args[0]
330-
assert "Complete response" == call_args[1]
331-
assert [1, 2, 3] == call_args[2]
332-
assert "length" == call_args[3]
335+
assert ("Generated response test-789 (streaming complete)"
336+
in call_args[0])
337+
assert call_args[1] == "Complete response"
338+
assert call_args[2] == [1, 2, 3]
339+
assert call_args[3] == "length"
333340

334341

335342
def test_request_logger_log_outputs_with_truncation():
336343
"""Test log_outputs respects max_log_len setting."""
337344
mock_logger = MagicMock()
338-
339-
with patch('vllm.entrypoints.logger.logger', mock_logger):
345+
346+
with patch("vllm.entrypoints.logger.logger", mock_logger):
340347
# Set max_log_len to 10
341348
request_logger = RequestLogger(max_log_len=10)
342-
349+
343350
# Test output truncation
344351
long_output = "This is a very long output that should be truncated"
345352
long_token_ids = list(range(20)) # 20 tokens
346-
353+
347354
request_logger.log_outputs(
348355
request_id="test-truncate",
349356
outputs=long_output,
350357
output_token_ids=long_token_ids,
351358
finish_reason="stop",
352359
is_streaming=False,
353-
delta=False
360+
delta=False,
354361
)
355-
362+
356363
mock_logger.info.assert_called_once()
357364
call_args = mock_logger.info.call_args
358-
365+
359366
# Check that output was truncated to first 10 characters
360367
logged_output = call_args[0][1]
361368
assert logged_output == "This is a "
362369
assert len(logged_output) == 10
363-
370+
364371
# Check that token IDs were truncated to first 10 tokens
365372
logged_token_ids = call_args[0][2]
366373
assert logged_token_ids == list(range(10))
@@ -370,60 +377,60 @@ def test_request_logger_log_outputs_with_truncation():
370377
def test_request_logger_log_outputs_none_values():
371378
"""Test log_outputs handles None values correctly."""
372379
mock_logger = MagicMock()
373-
374-
with patch('vllm.entrypoints.logger.logger', mock_logger):
380+
381+
with patch("vllm.entrypoints.logger.logger", mock_logger):
375382
request_logger = RequestLogger(max_log_len=None)
376-
383+
377384
# Test with None output_token_ids
378385
request_logger.log_outputs(
379386
request_id="test-none",
380387
outputs="Test output",
381388
output_token_ids=None,
382389
finish_reason="stop",
383390
is_streaming=False,
384-
delta=False
391+
delta=False,
385392
)
386-
393+
387394
mock_logger.info.assert_called_once()
388395
call_args = mock_logger.info.call_args[0]
389396
assert "Generated response test-none" in call_args[0]
390-
assert "Test output" == call_args[1]
397+
assert call_args[1] == "Test output"
391398
assert call_args[2] is None
392-
assert "stop" == call_args[3]
399+
assert call_args[3] == "stop"
393400

394401

395402
def test_request_logger_log_outputs_empty_output():
396403
"""Test log_outputs handles empty output correctly."""
397404
mock_logger = MagicMock()
398-
399-
with patch('vllm.entrypoints.logger.logger', mock_logger):
405+
406+
with patch("vllm.entrypoints.logger.logger", mock_logger):
400407
request_logger = RequestLogger(max_log_len=5)
401-
408+
402409
# Test with empty output
403410
request_logger.log_outputs(
404411
request_id="test-empty",
405412
outputs="",
406413
output_token_ids=[],
407414
finish_reason="stop",
408415
is_streaming=False,
409-
delta=False
416+
delta=False,
410417
)
411-
418+
412419
mock_logger.info.assert_called_once()
413420
call_args = mock_logger.info.call_args[0]
414421
assert "Generated response test-empty" in call_args[0]
415-
assert "" == call_args[1]
416-
assert [] == call_args[2]
417-
assert "stop" == call_args[3]
422+
assert call_args[1] == ""
423+
assert call_args[2] == []
424+
assert call_args[3] == "stop"
418425

419426

420427
def test_request_logger_log_outputs_integration():
421428
"""Test that log_outputs can be called alongside log_inputs."""
422429
mock_logger = MagicMock()
423-
424-
with patch('vllm.entrypoints.logger.logger', mock_logger):
430+
431+
with patch("vllm.entrypoints.logger.logger", mock_logger):
425432
request_logger = RequestLogger(max_log_len=None)
426-
433+
427434
# Test that both methods can be called without interference
428435
request_logger.log_inputs(
429436
request_id="test-integration",
@@ -432,24 +439,24 @@ def test_request_logger_log_outputs_integration():
432439
prompt_embeds=None,
433440
params=None,
434441
lora_request=None,
435-
prompt_adapter_request=None
442+
prompt_adapter_request=None,
436443
)
437-
444+
438445
request_logger.log_outputs(
439446
request_id="test-integration",
440447
outputs="Test output",
441448
output_token_ids=[4, 5, 6],
442449
finish_reason="stop",
443450
is_streaming=False,
444-
delta=False
451+
delta=False,
445452
)
446-
453+
447454
# Should have been called twice - once for inputs, once for outputs
448455
assert mock_logger.info.call_count == 2
449-
456+
450457
# Check that the calls were made with correct patterns
451458
input_call = mock_logger.info.call_args_list[0][0]
452459
output_call = mock_logger.info.call_args_list[1][0]
453-
460+
454461
assert "Received request test-integration" in input_call[0]
455462
assert "Generated response test-integration" in output_call[0]

0 commit comments

Comments
 (0)