Convert formatting to use ruff instead of yapf + isort (#26247)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -16,8 +16,13 @@ from uuid import uuid4
|
||||
import pytest
|
||||
|
||||
from vllm.entrypoints.logger import RequestLogger
|
||||
from vllm.logger import (_DATE_FORMAT, _FORMAT, _configure_vllm_root_logger,
|
||||
enable_trace_function_call, init_logger)
|
||||
from vllm.logger import (
|
||||
_DATE_FORMAT,
|
||||
_FORMAT,
|
||||
_configure_vllm_root_logger,
|
||||
enable_trace_function_call,
|
||||
init_logger,
|
||||
)
|
||||
from vllm.logging_utils import NewLineFormatter
|
||||
from vllm.logging_utils.dump_input import prepare_object_to_dump
|
||||
|
||||
@@ -129,8 +134,7 @@ def test_an_error_is_raised_when_custom_logging_config_is_invalid_json():
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write("---\nloggers: []\nversion: 1")
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH",
|
||||
logging_config_file.name):
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name):
|
||||
with pytest.raises(JSONDecodeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == JSONDecodeError
|
||||
@@ -138,24 +142,24 @@ def test_an_error_is_raised_when_custom_logging_config_is_invalid_json():
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
|
||||
@pytest.mark.parametrize("unexpected_config", (
|
||||
"Invalid string",
|
||||
[{
|
||||
"version": 1,
|
||||
"loggers": []
|
||||
}],
|
||||
0,
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
"unexpected_config",
|
||||
(
|
||||
"Invalid string",
|
||||
[{"version": 1, "loggers": []}],
|
||||
0,
|
||||
),
|
||||
)
|
||||
def test_an_error_is_raised_when_custom_logging_config_is_unexpected_json(
|
||||
unexpected_config: Any):
|
||||
unexpected_config: Any,
|
||||
):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however it fails before any change in behavior or
|
||||
configuration occurs."""
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write(json.dumps(unexpected_config))
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH",
|
||||
logging_config_file.name):
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name):
|
||||
with pytest.raises(ValueError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == ValueError # noqa: E721
|
||||
@@ -174,14 +178,15 @@ def test_custom_logging_config_is_parsed_and_used_when_provided():
|
||||
"propagate": False,
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
"version": 1,
|
||||
}
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write(json.dumps(valid_logging_config))
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH",
|
||||
logging_config_file.name), patch(
|
||||
"vllm.logger.dictConfig") as dict_config_mock:
|
||||
with (
|
||||
patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name),
|
||||
patch("vllm.logger.dictConfig") as dict_config_mock,
|
||||
):
|
||||
_configure_vllm_root_logger()
|
||||
dict_config_mock.assert_called_with(valid_logging_config)
|
||||
|
||||
@@ -197,19 +202,19 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
|
||||
"handlers": [],
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
"version": 1,
|
||||
}
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write(json.dumps(valid_logging_config))
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH",
|
||||
logging_config_file.name):
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name):
|
||||
with pytest.raises(RuntimeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type is RuntimeError
|
||||
expected_message_snippet = (
|
||||
"VLLM_CONFIGURE_LOGGING evaluated to false, but "
|
||||
"VLLM_LOGGING_CONFIG_PATH was given.")
|
||||
"VLLM_LOGGING_CONFIG_PATH was given."
|
||||
)
|
||||
assert expected_message_snippet in str(ex_info)
|
||||
|
||||
# Remember! The root logger is assumed to have been configured as
|
||||
@@ -223,11 +228,11 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
|
||||
|
||||
|
||||
def test_prepare_object_to_dump():
|
||||
str_obj = 'str'
|
||||
str_obj = "str"
|
||||
assert prepare_object_to_dump(str_obj) == "'str'"
|
||||
|
||||
list_obj = [1, 2, 3]
|
||||
assert prepare_object_to_dump(list_obj) == '[1, 2, 3]'
|
||||
assert prepare_object_to_dump(list_obj) == "[1, 2, 3]"
|
||||
|
||||
dict_obj = {"a": 1, "b": "b"}
|
||||
assert prepare_object_to_dump(dict_obj) in [
|
||||
@@ -236,9 +241,9 @@ def test_prepare_object_to_dump():
|
||||
]
|
||||
|
||||
set_obj = {1, 2, 3}
|
||||
assert prepare_object_to_dump(set_obj) == '[1, 2, 3]'
|
||||
assert prepare_object_to_dump(set_obj) == "[1, 2, 3]"
|
||||
|
||||
tuple_obj = ('a', 'b', 'c')
|
||||
tuple_obj = ("a", "b", "c")
|
||||
assert prepare_object_to_dump(tuple_obj) == "['a', 'b', 'c']"
|
||||
|
||||
class CustomEnum(enum.Enum):
|
||||
@@ -253,8 +258,7 @@ def test_prepare_object_to_dump():
|
||||
a: int
|
||||
b: str
|
||||
|
||||
assert (prepare_object_to_dump(CustomClass(
|
||||
1, "b")) == "CustomClass(a=1, b='b')")
|
||||
assert prepare_object_to_dump(CustomClass(1, "b")) == "CustomClass(a=1, b='b')"
|
||||
|
||||
|
||||
def test_request_logger_log_outputs():
|
||||
@@ -467,7 +471,7 @@ def test_request_logger_log_outputs_integration():
|
||||
|
||||
def test_streaming_complete_logs_full_text_content():
|
||||
"""Test that streaming complete logging includes
|
||||
full accumulated text, not just token count."""
|
||||
full accumulated text, not just token count."""
|
||||
mock_logger = MagicMock()
|
||||
|
||||
with patch("vllm.entrypoints.logger.logger", mock_logger):
|
||||
|
||||
Reference in New Issue
Block a user