-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_mock_check.py
More file actions
54 lines (39 loc) · 1.78 KB
/
test_mock_check.py
File metadata and controls
54 lines (39 loc) · 1.78 KB
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
"""Test if mock is being applied correctly."""
from unittest.mock import patch, Mock
# Test 1: Can we patch TestWorkerAgent at all?
print("Test 1: Basic patch test")
with patch("codeframe.agents.test_worker_agent.TestWorkerAgent") as MockCls:
mock_instance = Mock()
MockCls.return_value = mock_instance
from codeframe.agents.test_worker_agent import TestWorkerAgent
agent = TestWorkerAgent(agent_id="test-001")
print(f"agent type: {type(agent)}")
print(f"agent is mock_instance: {agent is mock_instance}")
print(f"MockCls called: {MockCls.called}")
print(f"MockCls call count: {MockCls.call_count}")
print("\n" + "=" * 80)
# Test 2: Patch at import location
print("\nTest 2: Patch at import location (agent_pool_manager)")
with patch("codeframe.agents.agent_pool_manager.TestWorkerAgent") as MockCls:
mock_instance = Mock()
MockCls.return_value = mock_instance
# Import AFTER patching
from codeframe.agents.agent_pool_manager import AgentPoolManager
from codeframe.persistence.database import Database
from codeframe.core.models import ProjectStatus
db = Database(":memory:")
db.initialize()
project_id = db.create_project("test", ProjectStatus.ACTIVE)
pool = AgentPoolManager(
project_id=project_id, db=db, ws_manager=None, max_agents=5, api_key="test-key"
)
print("Creating agent...")
agent_id = pool.create_agent("test-engineer")
print(f"agent_id: {agent_id}")
print(f"MockCls called: {MockCls.called}")
print(f"MockCls call count: {MockCls.call_count}")
agent_instance = pool.get_agent_instance(agent_id)
print(f"agent_instance type: {type(agent_instance)}")
print(f"agent_instance is mock_instance: {agent_instance is mock_instance}")
db.close()
print("\n✅ All tests passed!")