2727sys .modules ["llguidance.hf" ] = mock_llguidancehf
2828sys .modules ["torch" ] = mock_torch
2929
30- # 导入要测试的模块
30+ # Import the module to be tested
3131from fastdeploy .model_executor .guided_decoding .guidance_backend import (
3232 LLGuidanceBackend ,
3333 LLGuidanceProcessor ,
3737
3838class TestProcessForAdditionalProperties (unittest .TestCase ):
3939 def test_process_json_string (self ):
40- # 测试字符串输入
40+ # Test string input
4141 json_str = '{"type": "object", "properties": {"name": {"type": "string"}}}'
4242 result = process_for_additional_properties (json_str )
4343 self .assertFalse (result ["additionalProperties" ])
4444
4545 def test_process_json_dict (self ):
46- # 测试字典输入
46+ # Test dictionary input
4747 json_dict = {"type" : "object" , "properties" : {"name" : {"type" : "string" }}}
4848 result = process_for_additional_properties (json_dict )
4949 self .assertFalse (result ["additionalProperties" ])
50- # 确保原始字典没有被修改
50+ # Ensure the original dictionary is not modified
5151 self .assertNotIn ("additionalProperties" , json_dict )
5252
5353 def test_nested_objects (self ):
54- # 测试嵌套对象
54+ # Test nested objects
5555 json_dict = {
5656 "type" : "object" ,
5757 "properties" : {"person" : {"type" : "object" , "properties" : {"name" : {"type" : "string" }}}},
@@ -69,7 +69,7 @@ def setUp(self):
6969 self .batch_size = 2
7070
7171 def test_initialization (self , mock_tokenizer , mock_matcher ):
72- # 测试初始化
72+ # Test initialization
7373 processor = LLGuidanceProcessor (
7474 ll_matcher = mock_matcher ,
7575 ll_tokenizer = mock_tokenizer ,
@@ -83,7 +83,7 @@ def test_initialization(self, mock_tokenizer, mock_matcher):
8383 self .assertFalse (processor .is_terminated )
8484
8585 def test_reset (self , mock_tokenizer , mock_matcher ):
86- # 测试重置功能
86+ # Test reset functionality
8787 processor = LLGuidanceProcessor (
8888 ll_matcher = mock_matcher ,
8989 ll_tokenizer = mock_tokenizer ,
@@ -99,7 +99,7 @@ def test_reset(self, mock_tokenizer, mock_matcher):
9999 self .assertFalse (processor .is_terminated )
100100
101101 def test_accept_token (self , mock_tokenizer , mock_matcher ):
102- # 测试接受token功能
102+ # Test accept_token functionality
103103 mock_matcher .is_stopped .return_value = False
104104 mock_matcher .consume_tokens .return_value = True
105105 mock_tokenizer .eos_token = 1
@@ -112,7 +112,7 @@ def test_accept_token(self, mock_tokenizer, mock_matcher):
112112 batch_size = self .batch_size ,
113113 )
114114
115- # 正常token
115+ # Normal token
116116 result = processor .accept_token (0 )
117117 self .assertTrue (result )
118118 mock_matcher .consume_tokens .assert_called_with ([0 ])
@@ -127,7 +127,7 @@ def test_accept_token(self, mock_tokenizer, mock_matcher):
127127@patch ("llguidance.hf.from_tokenizer" )
128128class TestLLGuidanceBackend (unittest .TestCase ):
129129 def setUp (self ):
130- # 创建一个模拟的FDConfig
130+ # Create a mock FDConfig
131131 self .fd_config = MagicMock ()
132132 self .fd_config .model_config .vocab_size = 100
133133 self .fd_config .scheduler_config .max_num_seqs = 2
@@ -136,7 +136,7 @@ def setUp(self):
136136 self .fd_config .structured_outputs_config .reasoning_parser = None
137137
138138 def test_initialization (self , mock_from_tokenizer , mock_matcher ):
139- # 测试后端初始化
139+ # Test backend initialization
140140 mock_tokenizer = MagicMock ()
141141 with patch .object (BackendBase , "_get_tokenizer_hf" , return_value = mock_tokenizer ):
142142 backend = LLGuidanceBackend (fd_config = self .fd_config )
@@ -147,11 +147,11 @@ def test_initialization(self, mock_from_tokenizer, mock_matcher):
147147
148148 @patch ("llguidance.LLMatcher" )
149149 def test_create_processor (self , mock_matcher_class , mock_from_tokenizer , mock_matcher ):
150- # 测试创建处理器
150+ # Test creating a processor
151151 with patch .object (LLGuidanceBackend , "__init__" , return_value = None ):
152- backend = LLGuidanceBackend (fd_config = None ) # 参数不重要,因为 __init__ 被模拟了
152+ backend = LLGuidanceBackend (fd_config = None ) # Arguments are not important because __init__ is mocked
153153
154- # 手动设置所有需要的属性
154+ # Manually set all required attributes
155155 backend .hf_tokenizer = MagicMock ()
156156 backend .ll_tokenizer = MagicMock ()
157157 backend .vocab_size = 100
0 commit comments