AC2513 commited on
Commit
bd80f38
·
1 Parent(s): 7641a99

added history testing

Browse files
Files changed (1) hide show
  1. tests/test_media.py +134 -1
tests/test_media.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
5
  from pathlib import Path
6
  import tempfile
7
 
8
- from src.app import get_frames, process_video, process_user_input
9
 
10
  # Get the project root directory
11
  ROOT_DIR = Path(__file__).parent.parent
@@ -234,3 +234,136 @@ def test_process_user_input_max_images_effect():
234
  assert frames_few <= 2
235
  assert frames_many <= 5
236
  assert frames_few < frames_many
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from pathlib import Path
6
  import tempfile
7
 
8
+ from src.app import get_frames, process_video, process_user_input, process_history
9
 
10
  # Get the project root directory
11
  ROOT_DIR = Path(__file__).parent.parent
 
234
  assert frames_few <= 2
235
  assert frames_many <= 5
236
  assert frames_few < frames_many
237
+
238
+ def test_empty_history():
239
+ """Test processing empty history."""
240
+ history = []
241
+ result = process_history(history)
242
+ assert result == []
243
+
244
+ def test_single_user_message_text():
245
+ """Test processing a single user text message."""
246
+ history = [
247
+ {"role": "user", "content": "Hello, AI!"}
248
+ ]
249
+
250
+ result = process_history(history)
251
+
252
+ assert len(result) == 1
253
+ assert result[0]["role"] == "user"
254
+ assert len(result[0]["content"]) == 1
255
+ assert result[0]["content"][0]["type"] == "text"
256
+ assert result[0]["content"][0]["text"] == "Hello, AI!"
257
+
258
+ def test_single_user_message_image():
259
+ """Test processing a single user image message."""
260
+ history = [
261
+ {"role": "user", "content": ["path/to/image.jpg"]}
262
+ ]
263
+
264
+ result = process_history(history)
265
+
266
+ assert len(result) == 1
267
+ assert result[0]["role"] == "user"
268
+ assert len(result[0]["content"]) == 1
269
+ assert result[0]["content"][0]["type"] == "image"
270
+ assert result[0]["content"][0]["url"] == "path/to/image.jpg"
271
+
272
+ def test_single_assistant_message():
273
+ """Test processing a single assistant message."""
274
+ history = [
275
+ {"role": "assistant", "content": "I'm an AI assistant."}
276
+ ]
277
+
278
+ result = process_history(history)
279
+
280
+ assert len(result) == 1
281
+ assert result[0]["role"] == "assistant"
282
+ assert len(result[0]["content"]) == 1
283
+ assert result[0]["content"][0]["type"] == "text"
284
+ assert result[0]["content"][0]["text"] == "I'm an AI assistant."
285
+
286
+ def test_alternating_messages():
287
+ """Test processing alternating user and assistant messages."""
288
+ history = [
289
+ {"role": "user", "content": "Hello"},
290
+ {"role": "assistant", "content": "Hi there"},
291
+ {"role": "user", "content": "How are you?"},
292
+ {"role": "assistant", "content": "I'm doing well, thanks!"}
293
+ ]
294
+
295
+ result = process_history(history)
296
+
297
+ assert len(result) == 4
298
+ assert [item["role"] for item in result] == ["user", "assistant", "user", "assistant"]
299
+ assert result[0]["content"][0]["text"] == "Hello"
300
+ assert result[1]["content"][0]["text"] == "Hi there"
301
+ assert result[2]["content"][0]["text"] == "How are you?"
302
+ assert result[3]["content"][0]["text"] == "I'm doing well, thanks!"
303
+
304
+ def test_consecutive_user_messages():
305
+ """Test processing consecutive user messages - they should be grouped."""
306
+ history = [
307
+ {"role": "user", "content": "First message"},
308
+ {"role": "user", "content": "Second message"},
309
+ {"role": "user", "content": "Third message"},
310
+ {"role": "assistant", "content": "I got your messages"}
311
+ ]
312
+
313
+ result = process_history(history)
314
+
315
+ # Should be combined into a single user message with multiple content items
316
+ assert len(result) == 2
317
+ assert result[0]["role"] == "user"
318
+ assert len(result[0]["content"]) == 3
319
+ assert [item["text"] for item in result[0]["content"]] == [
320
+ "First message", "Second message", "Third message"
321
+ ]
322
+
323
+ def test_mixed_content_types():
324
+ """Test processing mixed content types (text and images)."""
325
+ history = [
326
+ {"role": "user", "content": "Look at this:"},
327
+ {"role": "user", "content": ["image.jpg"]},
328
+ {"role": "assistant", "content": "Nice image!"}
329
+ ]
330
+
331
+ result = process_history(history)
332
+
333
+ assert len(result) == 2
334
+ assert result[0]["role"] == "user"
335
+ assert len(result[0]["content"]) == 2
336
+ assert result[0]["content"][0]["type"] == "text"
337
+ assert result[0]["content"][1]["type"] == "image"
338
+
339
+ def test_ending_with_user_messages():
340
+ """Test history that ends with user messages."""
341
+ history = [
342
+ {"role": "user", "content": "Hello"},
343
+ {"role": "assistant", "content": "Hi there"},
344
+ {"role": "user", "content": "Another question"},
345
+ {"role": "user", "content": ["image.png"]}
346
+ ]
347
+
348
+ result = process_history(history)
349
+
350
+ assert len(result) == 3
351
+ assert result[2]["role"] == "user"
352
+ assert len(result[2]["content"]) == 2
353
+ assert result[2]["content"][0]["type"] == "text"
354
+ assert result[2]["content"][1]["type"] == "image"
355
+
356
+ def test_empty_messages():
357
+ """Test handling of empty content messages."""
358
+ history = [
359
+ {"role": "user", "content": ""},
360
+ {"role": "assistant", "content": ""},
361
+ {"role": "user", "content": "Hello"}
362
+ ]
363
+
364
+ result = process_history(history)
365
+
366
+ assert len(result) == 3
367
+ assert result[0]["content"][0]["text"] == ""
368
+ assert result[1]["content"][0]["text"] == ""
369
+ assert result[2]["content"][0]["text"] == "Hello"