lionagi 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,7 +44,7 @@ class BranchExecutor(Branch, BaseExecutor):
44
44
  it processes starts, nodes, node lists, conditions, or ends, accordingly executing different functions.
45
45
  """
46
46
  for key in list(self.mailbox.pending_ins.keys()):
47
- while self.mailbox.pending_ins[key].size() > 0:
47
+ while self.mailbox.pending_ins.get(key, Pile()).size() > 0:
48
48
  mail_id = self.mailbox.pending_ins[key].popleft()
49
49
  mail = self.mailbox.pile.pop(mail_id)
50
50
  if mail.category == "start":
@@ -57,7 +57,7 @@ class BranchExecutor(Branch, BaseExecutor):
57
57
  await self._process_condition(mail)
58
58
  elif mail.category == "end":
59
59
  self._process_end(mail)
60
- if self.mailbox.pending_ins[key].size() == 0:
60
+ if key in self.mailbox.pending_ins and self.mailbox.pending_ins.get(key, Pile()).size() == 0:
61
61
  self.mailbox.pending_ins.pop(key)
62
62
 
63
63
  async def execute(self, refresh_time=1) -> None:
@@ -118,8 +118,8 @@ class BranchExecutor(Branch, BaseExecutor):
118
118
  package=node.ln_id,
119
119
  request_source=self.ln_id,
120
120
  )
121
- except:
122
- raise ValueError(f"Invalid mail to process. Mail:{mail}")
121
+ except Exception as e:
122
+ raise ValueError(f"Invalid mail to process. Mail:{mail}, Error: {e}")
123
123
 
124
124
  def _process_node_list(self, mail: Mail):
125
125
  """
File without changes
File without changes
@@ -0,0 +1,28 @@
1
+ import pytest
2
+ from api.apicore import _connect as _connect_
3
+ from api.apicore import _config as _config_
4
+
5
+
6
+ """
7
+ Setup the testing construct to ease future testing cases
8
+ """
9
+
10
+
11
+ @pytest.fixture()
12
+ def config():
13
+ _config = _config_.ConfigSingleton()
14
+ _config.config["MOCK"] = True # turn on mock mode
15
+ yield _config
16
+
17
+
18
+ @pytest.fixture
19
+ def test_s3_conn(config):
20
+ yield _connect_.get_object("AWSS3")
21
+
22
+
23
+ @pytest.fixture
24
+ def test_ec2_conn(config):
25
+ yield _connect_.get_object("AWSEC2")
26
+
27
+
28
+
@@ -0,0 +1,7 @@
1
+ from moto import mock_aws
2
+
3
+
4
+ @mock_aws
5
+ def test_awss3_list_bucket_pass(test_s3_conn):
6
+ assert test_s3_conn.list_bucket_names() == []
7
+
@@ -1,193 +1,194 @@
1
- import unittest
2
- from lionagi.core.generic.structure import *
3
-
4
- class TestCondition(Condition):
5
- def check(self, node: Node) -> bool:
6
- return True
7
-
8
- class TestBaseStructure(unittest.TestCase):
9
- def setUp(self):
10
- self.structure = BaseStructure(id_="test_structure")
11
- self.node1 = Node(id_="node1", content="Node 1 content")
12
- self.node2 = Node(id_="node2", content="Node 2 content")
13
- self.node3 = Node(id_="node3", content="Node 3 content")
14
-
15
- def test_internal_edges(self):
16
- self.structure.add_node([self.node1, self.node2])
17
- self.structure.relate_nodes(self.node1, self.node2)
18
- self.assertEqual(len(self.structure.internal_edges), 1)
19
-
20
- def test_is_empty(self):
21
- self.assertTrue(self.structure.is_empty)
22
- self.structure.add_node(self.node1)
23
- self.assertFalse(self.structure.is_empty)
24
-
25
- def test_add_node_single(self):
26
- self.structure.add_node(self.node1)
27
- self.assertIn(self.node1.id_, self.structure.internal_nodes)
28
-
29
- def test_add_node_list(self):
30
- self.structure.add_node([self.node1, self.node2])
31
- self.assertIn(self.node1.id_, self.structure.internal_nodes)
32
- self.assertIn(self.node2.id_, self.structure.internal_nodes)
33
-
34
- def test_add_node_dict(self):
35
- self.structure.add_node({self.node1.id_: self.node1, self.node2.id_: self.node2})
36
- self.assertIn(self.node1.id_, self.structure.internal_nodes)
37
- self.assertIn(self.node2.id_, self.structure.internal_nodes)
38
-
39
- def test_add_node_duplicate(self):
40
- self.structure.add_node(self.node1)
41
- with self.assertRaises(ValueError):
42
- self.structure.add_node(self.node1)
43
-
44
- def test_get_node_str(self):
45
- self.structure.add_node(self.node1)
46
- self.assertEqual(self.structure.get_node(self.node1.id_), self.node1)
47
-
48
- def test_get_node_node(self):
49
- self.structure.add_node(self.node1)
50
- self.assertEqual(self.structure.get_node(self.node1), self.node1)
51
-
52
- def test_get_node_list(self):
53
- self.structure.add_node([self.node1, self.node2])
54
- self.assertEqual(self.structure.get_node([self.node1.id_, self.node2.id_]), [self.node1, self.node2])
55
-
56
- def test_get_node_dict(self):
57
- self.structure.add_node([self.node1, self.node2])
58
- self.assertEqual(self.structure.get_node({self.node1.id_: self.node1, self.node2.id_: self.node2}), [self.node1, self.node2])
59
-
60
- def test_get_node_not_found(self):
61
- with self.assertRaises(KeyError):
62
- self.structure.get_node("nonexistent_node")
63
-
64
- def test_get_node_default(self):
65
- self.assertIsNone(self.structure.get_node("nonexistent_node", default=None))
66
-
67
- def test_remove_node_node(self):
68
- self.structure.add_node(self.node1)
69
- self.structure.remove_node(self.node1)
70
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
71
-
72
- def test_remove_node_str(self):
73
- self.structure.add_node(self.node1)
74
- self.structure.remove_node(self.node1.id_)
75
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
76
-
77
- def test_remove_node_list(self):
78
- self.structure.add_node([self.node1, self.node2])
79
- self.structure.remove_node([self.node1, self.node2])
80
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
81
- self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
82
-
83
- def test_remove_node_dict(self):
84
- self.structure.add_node([self.node1, self.node2])
85
- self.structure.remove_node({self.node1.id_: self.node1, self.node2.id_: self.node2})
86
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
87
- self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
88
-
89
- def test_pop_node_node(self):
90
- self.structure.add_node(self.node1)
91
- popped_node = self.structure.pop_node(self.node1)
92
- self.assertEqual(popped_node, self.node1)
93
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
94
-
95
- def test_pop_node_str(self):
96
- self.structure.add_node(self.node1)
97
- popped_node = self.structure.pop_node(self.node1.id_)
98
- self.assertEqual(popped_node, self.node1)
99
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
100
-
101
- def test_pop_node_list(self):
102
- self.structure.add_node([self.node1, self.node2])
103
- popped_nodes = self.structure.pop_node([self.node1, self.node2])
104
- self.assertEqual(popped_nodes, [self.node1, self.node2])
105
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
106
- self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
107
-
108
- def test_pop_node_dict(self):
109
- self.structure.add_node([self.node1, self.node2])
110
- popped_nodes = self.structure.pop_node({self.node1.id_: self.node1, self.node2.id_: self.node2})
111
- self.assertEqual(popped_nodes, [self.node1, self.node2])
112
- self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
113
- self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
114
-
115
- def test_pop_node_default(self):
116
- self.assertIsNone(self.structure.pop_node("nonexistent_node", default=None))
117
-
118
- def test_remove_edge_edge(self):
119
- self.structure.add_node([self.node1, self.node2])
120
- self.structure.relate_nodes(self.node1, self.node2)
121
- edge = list(self.node1.edges.values())[0]
122
- self.structure.remove_edge(edge)
123
- self.assertNotIn(edge.id_, self.structure.internal_edges)
124
-
125
- def test_remove_edge_str(self):
126
- self.structure.add_node([self.node1, self.node2])
127
- self.structure.relate_nodes(self.node1, self.node2)
128
- edge = list(self.node1.edges.values())[0]
129
- self.structure.remove_edge(edge.id_)
130
- self.assertNotIn(edge.id_, self.structure.internal_edges)
131
-
132
- def test_remove_edge_list(self):
133
- self.structure.add_node([self.node1, self.node2, self.node3])
134
- self.structure.relate_nodes(self.node1, self.node2)
135
- self.structure.relate_nodes(self.node2, self.node3)
136
- edges = list(self.node2.edges.values())
137
-
138
- self.structure.remove_edge(edges)
139
- self.assertNotIn(edges[0].id_, self.structure.internal_edges)
140
- self.assertNotIn(edges[1].id_, self.structure.internal_edges)
141
-
142
- def test_remove_edge_dict(self):
143
- self.structure.add_node([self.node1, self.node2, self.node3])
144
- self.structure.relate_nodes(self.node1, self.node2)
145
- self.structure.relate_nodes(self.node2, self.node3)
146
-
147
- edge_dict = self.node2.edges
148
- edge_list = list(edge_dict.values())
149
-
150
- self.structure.remove_edge(edge_dict)
151
- self.assertNotIn(edge_list[0].id_, self.structure.internal_edges)
152
- self.assertNotIn(edge_list[1].id_, self.structure.internal_edges)
153
-
154
- def test_remove_edge_not_found(self):
155
- with self.assertRaises(ValueError):
156
- self.structure.remove_edge("nonexistent_edge")
157
-
158
- def test_clear(self):
159
- self.structure.add_node([self.node1, self.node2])
160
- self.structure.clear()
161
- self.assertTrue(self.structure.is_empty)
162
-
163
- def test_get_node_edges_head(self):
164
- self.structure.add_node([self.node1, self.node2])
165
- self.structure.relate_nodes(self.node1, self.node2)
166
- edges = self.structure.get_node_edges(self.node1, node_as="head")
167
- self.assertEqual(len(edges), 1)
168
-
169
- def test_get_node_edges_tail(self):
170
- self.structure.add_node([self.node1, self.node2])
171
- self.structure.relate_nodes(self.node1, self.node2)
172
- edges = self.structure.get_node_edges(self.node2, node_as="tail")
173
- self.assertEqual(len(edges), 1)
174
-
175
- def test_get_node_edges_label(self):
176
- self.structure.add_node([self.node1, self.node2])
177
- self.structure.relate_nodes(self.node1, self.node2, label="test_label")
178
- edges = self.structure.get_node_edges(self.node1, node_as="head", label="test_label")
179
- self.assertEqual(len(edges), 1)
180
-
181
- def test_add_edge(self):
182
- self.structure.relate_nodes(self.node1, self.node2)
183
- self.assertIn(self.node1.id_, self.structure.internal_nodes)
184
- self.assertIn(self.node2.id_, self.structure.internal_nodes)
185
- self.assertEqual(len(self.structure.internal_edges), 1)
186
-
187
- def test_add_edge_with_label(self):
188
- self.structure.relate_nodes(self.node1, self.node2, label="test_label")
189
- edge = list(self.structure.internal_edges.values())[0]
190
- self.assertEqual(edge.label, "test_label")
191
-
192
- if __name__ == "__main__":
193
- unittest.main()
1
+ #TODO
2
+ # import unittest
3
+ # from lionagi.core.generic.structure import *
4
+ #
5
+ # class TestCondition(Condition):
6
+ # def check(self, node: Node) -> bool:
7
+ # return True
8
+ #
9
+ # class TestBaseStructure(unittest.TestCase):
10
+ # def setUp(self):
11
+ # self.structure = BaseStructure(id_="test_structure")
12
+ # self.node1 = Node(id_="node1", content="Node 1 content")
13
+ # self.node2 = Node(id_="node2", content="Node 2 content")
14
+ # self.node3 = Node(id_="node3", content="Node 3 content")
15
+ #
16
+ # def test_internal_edges(self):
17
+ # self.structure.add_node([self.node1, self.node2])
18
+ # self.structure.relate_nodes(self.node1, self.node2)
19
+ # self.assertEqual(len(self.structure.internal_edges), 1)
20
+ #
21
+ # def test_is_empty(self):
22
+ # self.assertTrue(self.structure.is_empty)
23
+ # self.structure.add_node(self.node1)
24
+ # self.assertFalse(self.structure.is_empty)
25
+ #
26
+ # def test_add_node_single(self):
27
+ # self.structure.add_node(self.node1)
28
+ # self.assertIn(self.node1.id_, self.structure.internal_nodes)
29
+ #
30
+ # def test_add_node_list(self):
31
+ # self.structure.add_node([self.node1, self.node2])
32
+ # self.assertIn(self.node1.id_, self.structure.internal_nodes)
33
+ # self.assertIn(self.node2.id_, self.structure.internal_nodes)
34
+ #
35
+ # def test_add_node_dict(self):
36
+ # self.structure.add_node({self.node1.id_: self.node1, self.node2.id_: self.node2})
37
+ # self.assertIn(self.node1.id_, self.structure.internal_nodes)
38
+ # self.assertIn(self.node2.id_, self.structure.internal_nodes)
39
+ #
40
+ # def test_add_node_duplicate(self):
41
+ # self.structure.add_node(self.node1)
42
+ # with self.assertRaises(ValueError):
43
+ # self.structure.add_node(self.node1)
44
+ #
45
+ # def test_get_node_str(self):
46
+ # self.structure.add_node(self.node1)
47
+ # self.assertEqual(self.structure.get_node(self.node1.id_), self.node1)
48
+ #
49
+ # def test_get_node_node(self):
50
+ # self.structure.add_node(self.node1)
51
+ # self.assertEqual(self.structure.get_node(self.node1), self.node1)
52
+ #
53
+ # def test_get_node_list(self):
54
+ # self.structure.add_node([self.node1, self.node2])
55
+ # self.assertEqual(self.structure.get_node([self.node1.id_, self.node2.id_]), [self.node1, self.node2])
56
+ #
57
+ # def test_get_node_dict(self):
58
+ # self.structure.add_node([self.node1, self.node2])
59
+ # self.assertEqual(self.structure.get_node({self.node1.id_: self.node1, self.node2.id_: self.node2}), [self.node1, self.node2])
60
+ #
61
+ # def test_get_node_not_found(self):
62
+ # with self.assertRaises(KeyError):
63
+ # self.structure.get_node("nonexistent_node")
64
+ #
65
+ # def test_get_node_default(self):
66
+ # self.assertIsNone(self.structure.get_node("nonexistent_node", default=None))
67
+ #
68
+ # def test_remove_node_node(self):
69
+ # self.structure.add_node(self.node1)
70
+ # self.structure.remove_node(self.node1)
71
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
72
+ #
73
+ # def test_remove_node_str(self):
74
+ # self.structure.add_node(self.node1)
75
+ # self.structure.remove_node(self.node1.id_)
76
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
77
+ #
78
+ # def test_remove_node_list(self):
79
+ # self.structure.add_node([self.node1, self.node2])
80
+ # self.structure.remove_node([self.node1, self.node2])
81
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
82
+ # self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
83
+ #
84
+ # def test_remove_node_dict(self):
85
+ # self.structure.add_node([self.node1, self.node2])
86
+ # self.structure.remove_node({self.node1.id_: self.node1, self.node2.id_: self.node2})
87
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
88
+ # self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
89
+ #
90
+ # def test_pop_node_node(self):
91
+ # self.structure.add_node(self.node1)
92
+ # popped_node = self.structure.pop_node(self.node1)
93
+ # self.assertEqual(popped_node, self.node1)
94
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
95
+ #
96
+ # def test_pop_node_str(self):
97
+ # self.structure.add_node(self.node1)
98
+ # popped_node = self.structure.pop_node(self.node1.id_)
99
+ # self.assertEqual(popped_node, self.node1)
100
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
101
+ #
102
+ # def test_pop_node_list(self):
103
+ # self.structure.add_node([self.node1, self.node2])
104
+ # popped_nodes = self.structure.pop_node([self.node1, self.node2])
105
+ # self.assertEqual(popped_nodes, [self.node1, self.node2])
106
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
107
+ # self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
108
+ #
109
+ # def test_pop_node_dict(self):
110
+ # self.structure.add_node([self.node1, self.node2])
111
+ # popped_nodes = self.structure.pop_node({self.node1.id_: self.node1, self.node2.id_: self.node2})
112
+ # self.assertEqual(popped_nodes, [self.node1, self.node2])
113
+ # self.assertNotIn(self.node1.id_, self.structure.internal_nodes)
114
+ # self.assertNotIn(self.node2.id_, self.structure.internal_nodes)
115
+ #
116
+ # def test_pop_node_default(self):
117
+ # self.assertIsNone(self.structure.pop_node("nonexistent_node", default=None))
118
+ #
119
+ # def test_remove_edge_edge(self):
120
+ # self.structure.add_node([self.node1, self.node2])
121
+ # self.structure.relate_nodes(self.node1, self.node2)
122
+ # edge = list(self.node1.edges.values())[0]
123
+ # self.structure.remove_edge(edge)
124
+ # self.assertNotIn(edge.id_, self.structure.internal_edges)
125
+ #
126
+ # def test_remove_edge_str(self):
127
+ # self.structure.add_node([self.node1, self.node2])
128
+ # self.structure.relate_nodes(self.node1, self.node2)
129
+ # edge = list(self.node1.edges.values())[0]
130
+ # self.structure.remove_edge(edge.id_)
131
+ # self.assertNotIn(edge.id_, self.structure.internal_edges)
132
+ #
133
+ # def test_remove_edge_list(self):
134
+ # self.structure.add_node([self.node1, self.node2, self.node3])
135
+ # self.structure.relate_nodes(self.node1, self.node2)
136
+ # self.structure.relate_nodes(self.node2, self.node3)
137
+ # edges = list(self.node2.edges.values())
138
+ #
139
+ # self.structure.remove_edge(edges)
140
+ # self.assertNotIn(edges[0].id_, self.structure.internal_edges)
141
+ # self.assertNotIn(edges[1].id_, self.structure.internal_edges)
142
+ #
143
+ # def test_remove_edge_dict(self):
144
+ # self.structure.add_node([self.node1, self.node2, self.node3])
145
+ # self.structure.relate_nodes(self.node1, self.node2)
146
+ # self.structure.relate_nodes(self.node2, self.node3)
147
+ #
148
+ # edge_dict = self.node2.edges
149
+ # edge_list = list(edge_dict.values())
150
+ #
151
+ # self.structure.remove_edge(edge_dict)
152
+ # self.assertNotIn(edge_list[0].id_, self.structure.internal_edges)
153
+ # self.assertNotIn(edge_list[1].id_, self.structure.internal_edges)
154
+ #
155
+ # def test_remove_edge_not_found(self):
156
+ # with self.assertRaises(ValueError):
157
+ # self.structure.remove_edge("nonexistent_edge")
158
+ #
159
+ # def test_clear(self):
160
+ # self.structure.add_node([self.node1, self.node2])
161
+ # self.structure.clear()
162
+ # self.assertTrue(self.structure.is_empty)
163
+ #
164
+ # def test_get_node_edges_head(self):
165
+ # self.structure.add_node([self.node1, self.node2])
166
+ # self.structure.relate_nodes(self.node1, self.node2)
167
+ # edges = self.structure.get_node_edges(self.node1, node_as="head")
168
+ # self.assertEqual(len(edges), 1)
169
+ #
170
+ # def test_get_node_edges_tail(self):
171
+ # self.structure.add_node([self.node1, self.node2])
172
+ # self.structure.relate_nodes(self.node1, self.node2)
173
+ # edges = self.structure.get_node_edges(self.node2, node_as="tail")
174
+ # self.assertEqual(len(edges), 1)
175
+ #
176
+ # def test_get_node_edges_label(self):
177
+ # self.structure.add_node([self.node1, self.node2])
178
+ # self.structure.relate_nodes(self.node1, self.node2, label="test_label")
179
+ # edges = self.structure.get_node_edges(self.node1, node_as="head", label="test_label")
180
+ # self.assertEqual(len(edges), 1)
181
+ #
182
+ # def test_add_edge(self):
183
+ # self.structure.relate_nodes(self.node1, self.node2)
184
+ # self.assertIn(self.node1.id_, self.structure.internal_nodes)
185
+ # self.assertIn(self.node2.id_, self.structure.internal_nodes)
186
+ # self.assertEqual(len(self.structure.internal_edges), 1)
187
+ #
188
+ # def test_add_edge_with_label(self):
189
+ # self.structure.relate_nodes(self.node1, self.node2, label="test_label")
190
+ # edge = list(self.structure.internal_edges.values())[0]
191
+ # self.assertEqual(edge.label, "test_label")
192
+ #
193
+ # if __name__ == "__main__":
194
+ # unittest.main()
@@ -1,70 +1,71 @@
1
- import unittest
2
- from unittest.mock import MagicMock, patch
3
- from lionagi.core.graph.graph import Graph
4
- from lionagi.core.generic.node import Node
5
- from lionagi.core.generic.edge import Edge
6
-
7
- class TestGraph(unittest.TestCase):
8
-
9
- def setUp(self):
10
- self.graph = Graph()
11
- self.node1 = Node(id_="node1", content="Node 1 content")
12
- self.node2 = Node(id_="node2", content="Node 2 content")
13
- self.node3 = Node(id_="node3", content="Node 3 content")
14
- self.graph.add_node(self.node1)
15
- self.graph.add_node(self.node2)
16
- self.graph.add_node(self.node3)
17
-
18
- def test_graph_heads(self):
19
- self.graph.relate_nodes(self.node1, self.node2)
20
- self.assertEqual(["node1"], self.graph.graph_heads)
21
-
22
-
23
- def test_acyclic(self):
24
- self.graph.relate_nodes(self.node1, self.node2)
25
- self.assertTrue(self.graph.acyclic)
26
-
27
- self.graph.relate_nodes(self.node2, self.node1) # Creating a cycle
28
- self.assertFalse(self.graph.acyclic)
29
-
30
- @patch("lionagi.libs.SysUtil.check_import")
31
- def test_to_networkx_success(self, mock_check_import):
32
- mock_check_import.return_value = None
33
- with patch("networkx.DiGraph") as mock_digraph:
34
- mock_graph = MagicMock()
35
- mock_digraph.return_value = mock_graph
36
- result = self.graph.to_networkx()
37
- self.assertEqual(result, mock_graph)
38
-
39
- @patch("lionagi.libs.SysUtil.check_import")
40
- def test_to_networkx_empty_graph(self, mock_check_import):
41
- mock_check_import.return_value = None
42
- with patch("networkx.DiGraph") as mock_digraph:
43
- mock_graph = MagicMock()
44
- mock_digraph.return_value = mock_graph
45
-
46
- self.graph.internal_nodes = {}
47
- result = self.graph.to_networkx()
48
-
49
- self.assertEqual(result, mock_graph)
50
- mock_check_import.assert_called_once_with("networkx")
51
- mock_digraph.assert_called_once()
52
- mock_graph.add_node.assert_not_called()
53
- mock_graph.add_edge.assert_not_called()
54
-
55
- def test_add_node(self):
56
- new_node = Node(id_="node4", content="Node 4 content")
57
- self.graph.add_node(new_node)
58
- self.assertIn("node4", self.graph.internal_nodes)
59
-
60
- def test_remove_node(self):
61
- self.graph.remove_node(self.node1)
62
- self.assertNotIn("node1", self.graph.internal_nodes)
63
-
64
- def test_clear(self):
65
- self.graph.clear()
66
- self.assertEqual(len(self.graph.internal_nodes), 0)
67
- self.assertTrue(self.graph.is_empty)
68
-
69
- if __name__ == "__main__":
70
- unittest.main()
1
+ #TODO
2
+ # import unittest
3
+ # from unittest.mock import MagicMock, patch
4
+ # from lionagi.core.graph.graph import Graph
5
+ # from lionagi.core.generic.node import Node
6
+ # from lionagi.core.generic.edge import Edge
7
+ #
8
+ # class TestGraph(unittest.TestCase):
9
+ #
10
+ # def setUp(self):
11
+ # self.graph = Graph()
12
+ # self.node1 = Node(id_="node1", content="Node 1 content")
13
+ # self.node2 = Node(id_="node2", content="Node 2 content")
14
+ # self.node3 = Node(id_="node3", content="Node 3 content")
15
+ # self.graph.add_node(self.node1)
16
+ # self.graph.add_node(self.node2)
17
+ # self.graph.add_node(self.node3)
18
+ #
19
+ # def test_graph_heads(self):
20
+ # self.graph.relate_nodes(self.node1, self.node2)
21
+ # self.assertEqual(["node1"], self.graph.graph_heads)
22
+ #
23
+ #
24
+ # def test_acyclic(self):
25
+ # self.graph.relate_nodes(self.node1, self.node2)
26
+ # self.assertTrue(self.graph.acyclic)
27
+ #
28
+ # self.graph.relate_nodes(self.node2, self.node1) # Creating a cycle
29
+ # self.assertFalse(self.graph.acyclic)
30
+ #
31
+ # @patch("lionagi.libs.SysUtil.check_import")
32
+ # def test_to_networkx_success(self, mock_check_import):
33
+ # mock_check_import.return_value = None
34
+ # with patch("networkx.DiGraph") as mock_digraph:
35
+ # mock_graph = MagicMock()
36
+ # mock_digraph.return_value = mock_graph
37
+ # result = self.graph.to_networkx()
38
+ # self.assertEqual(result, mock_graph)
39
+ #
40
+ # @patch("lionagi.libs.SysUtil.check_import")
41
+ # def test_to_networkx_empty_graph(self, mock_check_import):
42
+ # mock_check_import.return_value = None
43
+ # with patch("networkx.DiGraph") as mock_digraph:
44
+ # mock_graph = MagicMock()
45
+ # mock_digraph.return_value = mock_graph
46
+ #
47
+ # self.graph.internal_nodes = {}
48
+ # result = self.graph.to_networkx()
49
+ #
50
+ # self.assertEqual(result, mock_graph)
51
+ # mock_check_import.assert_called_once_with("networkx")
52
+ # mock_digraph.assert_called_once()
53
+ # mock_graph.add_node.assert_not_called()
54
+ # mock_graph.add_edge.assert_not_called()
55
+ #
56
+ # def test_add_node(self):
57
+ # new_node = Node(id_="node4", content="Node 4 content")
58
+ # self.graph.add_node(new_node)
59
+ # self.assertIn("node4", self.graph.internal_nodes)
60
+ #
61
+ # def test_remove_node(self):
62
+ # self.graph.remove_node(self.node1)
63
+ # self.assertNotIn("node1", self.graph.internal_nodes)
64
+ #
65
+ # def test_clear(self):
66
+ # self.graph.clear()
67
+ # self.assertEqual(len(self.graph.internal_nodes), 0)
68
+ # self.assertTrue(self.graph.is_empty)
69
+ #
70
+ # if __name__ == "__main__":
71
+ # unittest.main()