()
| 153 | |
| 154 | |
| 155 | def test_generate_and_chat_branches(): |
| 156 | llm = _make_llm(_make_engine(is_master=False)) |
| 157 | llm._check_master = lambda: False |
| 158 | with pytest.raises(ValueError, match="master node"): |
| 159 | llm.generate("hi") |
| 160 | |
| 161 | llm = _make_llm(_make_engine()) |
| 162 | llm._check_master = lambda: True |
| 163 | llm._run_engine_stream = lambda *_, **__: "streamed" |
| 164 | llm._add_request = lambda **_: ["r1"] |
| 165 | with pytest.raises(ValueError, match="input dict"): |
| 166 | llm.generate({"x": 1}, sampling_params=SamplingParams(max_tokens=1), use_tqdm=False) |
| 167 | assert llm.generate("hi", sampling_params=SamplingParams(max_tokens=1), use_tqdm=False, stream=True) == "streamed" |
| 168 | |
| 169 | llm._check_master = lambda: False |
| 170 | with pytest.raises(ValueError, match="master node"): |
| 171 | llm.chat(messages=[[{"role": "user", "content": "hi"}]], sampling_params=SamplingParams(), use_tqdm=False) |
| 172 | |
| 173 | llm._check_master = lambda: True |
| 174 | llm._validate_tools = lambda *_: (_ for _ in ()).throw(ValueError("bad tools")) |
| 175 | with pytest.raises(RuntimeError, match="Failed to validate"): |
| 176 | llm.chat( |
| 177 | messages=[[{"role": "user", "content": "hi"}]], tools=1, sampling_params=SamplingParams(), use_tqdm=False |
| 178 | ) |
| 179 | assert ( |
| 180 | llm.chat( |
| 181 | messages=[[{"role": "user", "content": "hi"}]], |
| 182 | sampling_params=SamplingParams(max_tokens=1), |
| 183 | use_tqdm=False, |
| 184 | stream=True, |
| 185 | ) |
| 186 | == "streamed" |
| 187 | ) |
| 188 | |
| 189 | |
| 190 | def test_add_request_validations_and_guided_decoding(monkeypatch): |
nothing calls this directly
no test coverage detected