main
py 31 lines 1021 Bytes
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 from vllm.utils.jsontree import json_count_leaves
4
5
6 def test_json_count_leaves():
7 """Test json_count_leaves function from jsontree utility."""
8 # Single leaf values
9 assert json_count_leaves(42) == 1
10 assert json_count_leaves("hello") == 1
11 assert json_count_leaves(None) == 1
12
13 # Empty containers
14 assert json_count_leaves([]) == 0
15 assert json_count_leaves({}) == 0
16 assert json_count_leaves(()) == 0
17
18 # Flat structures
19 assert json_count_leaves([1, 2, 3]) == 3
20 assert json_count_leaves({"a": 1, "b": 2}) == 2
21 assert json_count_leaves((1, 2, 3)) == 3
22
23 # Nested structures
24 nested_dict = {"a": 1, "b": {"c": 2, "d": 3}}
25 assert json_count_leaves(nested_dict) == 3
26
27 nested_list = [1, [2, 3], 4]
28 assert json_count_leaves(nested_list) == 4
29
30 mixed_nested = {"list": [1, 2], "dict": {"x": 3}, "value": 4}
31 assert json_count_leaves(mixed_nested) == 4