1- import pytest
21from 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+
53import 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+
69
710@pytest .fixture
811def mock_agent ():
912 tool1 = Mock ()
1013 tool1 .name = "Tool1"
1114 tool2 = Mock ()
1215 tool2 .name = "Tool2"
13-
16+
1417 handoff1 = Mock ()
1518 handoff1 .name = "Handoff1"
1619 handoff1 .tools = []
@@ -20,28 +23,55 @@ def mock_agent():
2023 agent .name = "Agent1"
2124 agent .tools = [tool1 , tool2 ]
2225 agent .handoffs = [handoff1 ]
23-
26+
2427 return agent
2528
29+
2630def test_get_main_graph (mock_agent ):
2731 result = get_main_graph (mock_agent )
2832 assert "digraph G" in result
29- assert ' graph [splines=true];' in result
33+ assert " graph [splines=true];" in result
3034 assert 'node [fontname="Arial"];' in result
31- assert ' edge [penwidth=1.5];' in result
35+ assert " edge [penwidth=1.5];" in result
3236 assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
3337 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+
3855
3956def test_get_all_nodes (mock_agent ):
4057 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+
4575
4676def test_get_all_edges (mock_agent ):
4777 result = get_all_edges (mock_agent )
@@ -53,16 +83,29 @@ def test_get_all_edges(mock_agent):
5383 assert '"Agent1" -> "Handoff1";' in result
5484 assert '"Handoff1" -> "__end__";' in result
5585
86+
5687def test_draw_graph (mock_agent ):
5788 graph = draw_graph (mock_agent )
5889 assert isinstance (graph , graphviz .Source )
5990 assert "digraph G" in graph .source
60- assert ' graph [splines=true];' in graph .source
91+ assert " graph [splines=true];" in graph .source
6192 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
6394 assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph .source
6495 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