| 173 | |
| 174 | |
| 175 | def test_batch_predict_string_warning(): |
| 176 | api = ls.test_examples.SimpleBatchedAPI(max_batch_size=2, batch_timeout=0.1) |
| 177 | api.request_timeout = 30 |
| 178 | api.pre_setup(spec=None) |
| 179 | api.predict = MagicMock(return_value="This is a string") |
| 180 | |
| 181 | mock_input = torch.tensor([[1.0], [2.0]]) |
| 182 | |
| 183 | # Simulate the behavior in run_batched_loop |
| 184 | y = api.predict(mock_input) |
| 185 | with pytest.warns( |
| 186 | UserWarning, |
| 187 | match="When batching is enabled, 'predict' must return a list to handle multiple inputs correctly.", |
| 188 | ): |
| 189 | api.unbatch(y) |
| 190 | |
| 191 | |
| 192 | class FakeResponseQueue: |