1
- import pytest
2
1
from unittest .mock import Mock
3
- from src .agents .visualizations import get_main_graph , get_all_nodes , get_all_edges , draw_graph
4
- from src .agents .agent import Agent
2
+
5
3
import graphviz
4
+ import pytest
5
+
6
+ from src .agents .agent import Agent
7
+ from src .agents .visualizations import draw_graph , get_all_edges , get_all_nodes , get_main_graph
8
+
6
9
7
10
@pytest .fixture
8
11
def mock_agent ():
9
12
tool1 = Mock ()
10
13
tool1 .name = "Tool1"
11
14
tool2 = Mock ()
12
15
tool2 .name = "Tool2"
13
-
16
+
14
17
handoff1 = Mock ()
15
18
handoff1 .name = "Handoff1"
16
19
handoff1 .tools = []
@@ -20,28 +23,55 @@ def mock_agent():
20
23
agent .name = "Agent1"
21
24
agent .tools = [tool1 , tool2 ]
22
25
agent .handoffs = [handoff1 ]
23
-
26
+
24
27
return agent
25
28
29
+
26
30
def test_get_main_graph (mock_agent ):
27
31
result = get_main_graph (mock_agent )
28
32
assert "digraph G" in result
29
- assert ' graph [splines=true];' in result
33
+ assert " graph [splines=true];" in result
30
34
assert 'node [fontname="Arial"];' in result
31
- assert ' edge [penwidth=1.5];' in result
35
+ assert " edge [penwidth=1.5];" in result
32
36
assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
33
37
assert '"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
34
- assert '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];' in result
35
- assert '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
36
- assert '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
37
- assert '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];' in result
38
+ assert (
39
+ '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
40
+ in result
41
+ )
42
+ assert (
43
+ '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
44
+ in result
45
+ )
46
+ assert (
47
+ '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
48
+ in result
49
+ )
50
+ assert (
51
+ '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
52
+ in result
53
+ )
54
+
38
55
39
56
def test_get_all_nodes (mock_agent ):
40
57
result = get_all_nodes (mock_agent )
41
- assert '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];' in result
42
- assert '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
43
- assert '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
44
- assert '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];' in result
58
+ assert (
59
+ '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
60
+ in result
61
+ )
62
+ assert (
63
+ '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
64
+ in result
65
+ )
66
+ assert (
67
+ '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
68
+ in result
69
+ )
70
+ assert (
71
+ '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
72
+ in result
73
+ )
74
+
45
75
46
76
def test_get_all_edges (mock_agent ):
47
77
result = get_all_edges (mock_agent )
@@ -53,16 +83,29 @@ def test_get_all_edges(mock_agent):
53
83
assert '"Agent1" -> "Handoff1";' in result
54
84
assert '"Handoff1" -> "__end__";' in result
55
85
86
+
56
87
def test_draw_graph (mock_agent ):
57
88
graph = draw_graph (mock_agent )
58
89
assert isinstance (graph , graphviz .Source )
59
90
assert "digraph G" in graph .source
60
- assert ' graph [splines=true];' in graph .source
91
+ assert " graph [splines=true];" in graph .source
61
92
assert 'node [fontname="Arial"];' in graph .source
62
- assert ' edge [penwidth=1.5];' in graph .source
93
+ assert " edge [penwidth=1.5];" in graph .source
63
94
assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph .source
64
95
assert '"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph .source
65
- assert '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];' in graph .source
66
- assert '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in graph .source
67
- assert '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in graph .source
68
- assert '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];' in graph .source
96
+ assert (
97
+ '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
98
+ in graph .source
99
+ )
100
+ assert (
101
+ '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
102
+ in graph .source
103
+ )
104
+ assert (
105
+ '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
106
+ in graph .source
107
+ )
108
+ assert (
109
+ '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
110
+ in graph .source
111
+ )
0 commit comments