Video-Scout / tests /test_memory.py
ashleshp's picture
first commit
fca155a
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"