|
1 | 1 | # SPDX-License-Identifier: Apache-2.0
|
2 |
| - |
| 2 | +import enum |
3 | 3 | import json
|
4 | 4 | import logging
|
5 | 5 | import os
|
6 | 6 | import sys
|
7 | 7 | import tempfile
|
| 8 | +from dataclasses import dataclass |
8 | 9 | from json.decoder import JSONDecodeError
|
9 | 10 | from tempfile import NamedTemporaryFile
|
10 | 11 | from typing import Any
|
|
13 | 14 |
|
14 | 15 | import pytest
|
15 | 16 |
|
| 17 | +from vllm.logging_utils.dump_input import prepare_object_to_dump |
16 | 18 | from vllm.logger import (_DATE_FORMAT, _FORMAT, _configure_vllm_root_logger,
|
17 | 19 | enable_trace_function_call, init_logger)
|
18 | 20 | from vllm.logging_utils import NewLineFormatter
|
@@ -216,3 +218,34 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
|
216 | 218 | assert other_logger.handlers != root_logger.handlers
|
217 | 219 | assert other_logger.level != root_logger.level
|
218 | 220 | assert other_logger.propagate
|
| 221 | + |
| 222 | +def test_prepare_object_to_dump(): |
| 223 | + str_obj = 'str' |
| 224 | + assert prepare_object_to_dump(str_obj) == "'str'" |
| 225 | + |
| 226 | + list_obj = [1, 2, 3] |
| 227 | + assert prepare_object_to_dump(list_obj) == '[1, 2, 3]' |
| 228 | + |
| 229 | + dict_obj = {'a': 1, 'b': 'b'} |
| 230 | + assert prepare_object_to_dump(dict_obj) in ["{a: 1, b: 'b'}", |
| 231 | + "{b: 'b', a: 1}"] |
| 232 | + |
| 233 | + set_obj = {1, 2, 3} |
| 234 | + assert prepare_object_to_dump(set_obj) == '[1, 2, 3]' |
| 235 | + |
| 236 | + tuple_obj = ('a', 'b', 'c') |
| 237 | + assert prepare_object_to_dump(tuple_obj) == "['a', 'b', 'c']" |
| 238 | + |
| 239 | + class CustomEnum(enum.Enum): |
| 240 | + A = enum.auto() |
| 241 | + B = enum.auto() |
| 242 | + C = enum.auto() |
| 243 | + assert prepare_object_to_dump(CustomEnum.A) == repr(CustomEnum.A) |
| 244 | + |
| 245 | + @dataclass |
| 246 | + class CustomClass(object): |
| 247 | + a: int |
| 248 | + b: str |
| 249 | + |
| 250 | + assert (prepare_object_to_dump(CustomClass(1, 'b')) == |
| 251 | + "CustomClass(a=1, b='b')") |
0 commit comments