Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
5a2c76cb
Unverified
Commit
5a2c76cb
authored
May 26, 2025
by
Ning Xie
Committed by
GitHub
May 26, 2025
Browse files
[CI] fix dump_input for str type (#18697)
Signed-off-by:
Andy Xie
<
andy.xning@gmail.com
>
parent
38b13dfe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
4 deletions
+40
-4
tests/test_logger.py
tests/test_logger.py
+37
-1
vllm/logging_utils/dump_input.py
vllm/logging_utils/dump_input.py
+3
-3
No files found.
tests/test_logger.py
View file @
5a2c76cb
# SPDX-License-Identifier: Apache-2.0
import
enum
import
json
import
logging
import
os
import
sys
import
tempfile
from
dataclasses
import
dataclass
from
json.decoder
import
JSONDecodeError
from
tempfile
import
NamedTemporaryFile
from
typing
import
Any
...
...
@@ -16,6 +17,7 @@ import pytest
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
def
f1
(
x
):
...
...
@@ -216,3 +218,37 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
assert
other_logger
.
handlers
!=
root_logger
.
handlers
assert
other_logger
.
level
!=
root_logger
.
level
assert
other_logger
.
propagate
def
test_prepare_object_to_dump
():
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]'
dict_obj
=
{
'a'
:
1
,
'b'
:
'b'
}
assert
prepare_object_to_dump
(
dict_obj
)
in
[
"{a: 1, b: 'b'}"
,
"{b: 'b', a: 1}"
]
set_obj
=
{
1
,
2
,
3
}
assert
prepare_object_to_dump
(
set_obj
)
==
'[1, 2, 3]'
tuple_obj
=
(
'a'
,
'b'
,
'c'
)
assert
prepare_object_to_dump
(
tuple_obj
)
==
"['a', 'b', 'c']"
class
CustomEnum
(
enum
.
Enum
):
A
=
enum
.
auto
()
B
=
enum
.
auto
()
C
=
enum
.
auto
()
assert
prepare_object_to_dump
(
CustomEnum
.
A
)
==
repr
(
CustomEnum
.
A
)
@
dataclass
class
CustomClass
:
a
:
int
b
:
str
assert
(
prepare_object_to_dump
(
CustomClass
(
1
,
'b'
))
==
"CustomClass(a=1, b='b')"
)
vllm/logging_utils/dump_input.py
View file @
5a2c76cb
...
...
@@ -18,7 +18,7 @@ logger = init_logger(__name__)
def
prepare_object_to_dump
(
obj
)
->
str
:
if
isinstance
(
obj
,
str
):
return
"'{obj}'"
# Double quotes
return
f
"'
{
obj
}
'"
# Double quotes
elif
isinstance
(
obj
,
dict
):
dict_str
=
', '
.
join
({
f
'
{
str
(
k
)
}
:
{
prepare_object_to_dump
(
v
)
}
'
\
for
k
,
v
in
obj
.
items
()})
...
...
@@ -42,9 +42,9 @@ def prepare_object_to_dump(obj) -> str:
return
obj
.
anon_repr
()
elif
hasattr
(
obj
,
'__dict__'
):
items
=
obj
.
__dict__
.
items
()
dict_str
=
','
.
join
([
f
'
{
str
(
k
)
}
=
{
prepare_object_to_dump
(
v
)
}
'
\
dict_str
=
',
'
.
join
([
f
'
{
str
(
k
)
}
=
{
prepare_object_to_dump
(
v
)
}
'
\
for
k
,
v
in
items
])
return
(
f
"
{
type
(
obj
).
__name__
}
(
{
dict_str
}
)"
)
return
f
"
{
type
(
obj
).
__name__
}
(
{
dict_str
}
)"
else
:
# Hacky way to make sure we can serialize the object in JSON format
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment