File size: 2,147 Bytes
fca155a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pytest
from src.memory.manager import SimpleMemoryManager
import json
import os

class TestMemoryManager:
    
    def test_initialize_storage(self, tmp_path):
        """Test that initialization creates a new empty structure."""
        # Using pytest's tmp_path fixture for isolated file IO
        manager = SimpleMemoryManager(storage_dir=tmp_path)
        video_id = "test_video_01"
        
        manager.initialize_storage(video_id)
        
        # Verify file creation
        expected_file = tmp_path / f"{video_id}_metadata.json"
        assert expected_file.exists()
        
        with open(expected_file) as f:
            data = json.load(f)
            assert data["video_id"] == video_id
            assert data["events"] == []
            assert data["entities"] == {}

    def test_commit_event(self, tmp_path):
        """Test adding an event to the timeline."""
        manager = SimpleMemoryManager(storage_dir=tmp_path)
        video_id = "test_video_01"
        manager.initialize_storage(video_id)
        
        manager.commit_event(
            video_id=video_id,
            timestamp="00:05",
            description="Man walks dog",
            metadata={"objects": ["man", "dog"]}
        )
        
        # Reload and check
        expected_file = tmp_path / f"{video_id}_metadata.json"
        with open(expected_file) as f:
            data = json.load(f)
            assert len(data["events"]) == 1
            assert data["events"][0]["description"] == "Man walks dog"
            assert data["events"][0]["timestamp"] == "00:05"

    def test_query_knowledge(self, tmp_path):
        """Test simple keyword search."""
        manager = SimpleMemoryManager(storage_dir=tmp_path)
        video_id = "test_video_01"
        manager.initialize_storage(video_id)
        
        manager.commit_event(video_id, "00:01", "Car drives by", {})
        manager.commit_event(video_id, "00:05", "Man walks dog", {})
        
        # Search for "dog"
        results = manager.query_knowledge(video_id, "dog")
        assert len(results) == 1
        assert results[0]["description"] == "Man walks dog"