Skip to content

Commit 8512558

Browse files
committed
Add code comments and unit tests
Signed-off-by: Jialin Ouyang <Jialin.Ouyang@gmail.com>
1 parent 1c632aa commit 8512558

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/v1/test_outputs.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
4+
5+
from vllm.v1.outputs import (
6+
convert_to_token_id_list,
7+
convert_to_token_ids,
8+
get_token_count,
9+
)
10+
11+
12+
def test_convert_to_token_id_list():
13+
assert convert_to_token_id_list(1) == [1]
14+
assert convert_to_token_id_list(2) == [2]
15+
16+
# Return the original list back without creating new lists
17+
vs = [3, 4]
18+
assert convert_to_token_id_list(vs) is vs
19+
vs = [5, 6, 7]
20+
assert convert_to_token_id_list(vs) is vs
21+
22+
23+
def test_convert_to_token_ids():
24+
assert convert_to_token_ids([10]) == 10
25+
assert convert_to_token_ids([20]) == 20
26+
27+
# Return the original list back without creating new lists
28+
vs = [30, 40]
29+
assert convert_to_token_ids(vs) is vs
30+
vs = [50, 60, 70]
31+
assert convert_to_token_ids(vs) is vs
32+
33+
34+
def test_get_token_count():
35+
assert get_token_count(100) == 1
36+
assert get_token_count(200) == 1
37+
assert get_token_count([300]) == 1
38+
assert get_token_count([400, 500]) == 2
39+
assert get_token_count([600, 700, 800]) == 3

0 commit comments

Comments
 (0)