lionagi 0.2.1__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.
Files changed (33) hide show
  1. lionagi/__init__.py +2 -1
  2. lionagi/core/engine/branch_engine.py +4 -4
  3. lionagi/core/generic/graph.py +10 -3
  4. lionagi/core/generic/node.py +5 -1
  5. lionagi/core/report/base.py +1 -0
  6. lionagi/core/work/work_edge.py +96 -0
  7. lionagi/core/work/work_function.py +29 -6
  8. lionagi/core/work/work_function_node.py +44 -0
  9. lionagi/core/work/work_queue.py +20 -18
  10. lionagi/core/work/work_task.py +155 -0
  11. lionagi/core/work/worker.py +164 -39
  12. lionagi/core/work/worker_engine.py +179 -0
  13. lionagi/core/work/worklog.py +5 -3
  14. lionagi/tests/api/__init__.py +0 -0
  15. lionagi/tests/api/aws/__init__.py +0 -0
  16. lionagi/tests/api/aws/conftest.py +28 -0
  17. lionagi/tests/api/aws/test_aws_s3.py +7 -0
  18. lionagi/tests/test_core/generic/test_structure.py +194 -0
  19. lionagi/tests/test_core/graph/__init__.py +0 -0
  20. lionagi/tests/test_core/graph/test_graph.py +71 -0
  21. lionagi/tests/test_core/graph/test_tree.py +76 -0
  22. lionagi/tests/test_core/mail/__init__.py +0 -0
  23. lionagi/tests/test_core/mail/test_mail.py +98 -0
  24. lionagi/tests/test_core/test_structure/__init__.py +0 -0
  25. lionagi/tests/test_core/test_structure/test_base_structure.py +198 -0
  26. lionagi/tests/test_core/test_structure/test_graph.py +55 -0
  27. lionagi/tests/test_core/test_structure/test_tree.py +49 -0
  28. lionagi/version.py +1 -1
  29. {lionagi-0.2.1.dist-info → lionagi-0.2.3.dist-info}/METADATA +9 -4
  30. {lionagi-0.2.1.dist-info → lionagi-0.2.3.dist-info}/RECORD +33 -15
  31. {lionagi-0.2.1.dist-info → lionagi-0.2.3.dist-info}/WHEEL +1 -1
  32. {lionagi-0.2.1.dist-info → lionagi-0.2.3.dist-info}/LICENSE +0 -0
  33. {lionagi-0.2.1.dist-info → lionagi-0.2.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,194 @@
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()
File without changes
@@ -0,0 +1,71 @@
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()
@@ -0,0 +1,76 @@
1
+ #TODO
2
+ # import unittest
3
+ # from lionagi.core.graph.tree import TreeNode, Tree
4
+ #
5
+ # class TestTreeNode(unittest.TestCase):
6
+ # def setUp(self):
7
+ # self.parent_node = TreeNode(id_="parent", content="Parent Node")
8
+ # self.child_node1 = TreeNode(id_="child1", content="Child Node 1")
9
+ # self.child_node2 = TreeNode(id_="child2", content="Child Node 2")
10
+ #
11
+ # def test_relate_child(self):
12
+ # self.parent_node.relate_child(self.child_node1)
13
+ # self.assertIn("child1", self.parent_node.children)
14
+ # self.assertEqual(self.child_node1.parent, self.parent_node)
15
+ #
16
+ # def test_relate_children(self):
17
+ # self.parent_node.relate_child([self.child_node1, self.child_node2])
18
+ # self.assertIn("child1", self.parent_node.children)
19
+ # self.assertIn("child2", self.parent_node.children)
20
+ # self.assertEqual(self.child_node1.parent, self.parent_node)
21
+ # self.assertEqual(self.child_node2.parent, self.parent_node)
22
+ #
23
+ # def test_relate_parent(self):
24
+ # self.child_node1.relate_parent(self.parent_node)
25
+ # self.assertIn("child1", self.parent_node.children)
26
+ # self.assertEqual(self.child_node1.parent, self.parent_node)
27
+ #
28
+ # def test_unrelate_child(self):
29
+ # self.parent_node.relate_child(self.child_node1)
30
+ # self.parent_node.unrelate_child(self.child_node1)
31
+ # self.assertNotIn("child1", self.parent_node.children)
32
+ # self.assertIsNone(self.child_node1.parent)
33
+ #
34
+ # def test_unrelate_parent(self):
35
+ # self.child_node1.relate_parent(self.parent_node)
36
+ # self.child_node1.unrelate_parent()
37
+ # self.assertNotIn("child1", self.parent_node.children)
38
+ # self.assertIsNone(self.child_node1.parent)
39
+ #
40
+ # class TestTree(unittest.TestCase):
41
+ # def setUp(self):
42
+ # self.tree = Tree()
43
+ # self.root = TreeNode(id_="root", content="Root Node")
44
+ # self.child_node1 = TreeNode(id_="child1", content="Child Node 1")
45
+ # self.child_node2 = TreeNode(id_="child2", content="Child Node 2")
46
+ # self.grandchild_node = TreeNode(id_="grandchild", content="Grandchild Node")
47
+ #
48
+ # def test_add_node(self):
49
+ # self.tree.add_node(self.root)
50
+ # self.assertIn("root", self.tree.internal_nodes)
51
+ #
52
+ # def test_relate_parent_child(self):
53
+ # self.tree.relate_parent_child(self.root, [self.child_node1, self.child_node2])
54
+ # self.assertIn("child1", self.root.children)
55
+ # self.assertIn("child2", self.root.children)
56
+ # self.assertEqual(self.tree.root, self.root)
57
+ #
58
+ # def test_tree_structure(self):
59
+ # # Build the tree
60
+ # self.tree.relate_parent_child(self.root, [self.child_node1, self.child_node2])
61
+ # self.tree.relate_parent_child(self.child_node1, self.grandchild_node)
62
+ #
63
+ # # Check the tree structure
64
+ # self.assertIn("grandchild", self.child_node1.children)
65
+ # self.assertEqual(self.grandchild_node.parent, self.child_node1)
66
+ # self.assertEqual(self.child_node1.parent, self.root)
67
+ #
68
+ # def test_acyclic(self):
69
+ # # Build the tree
70
+ # self.tree.relate_parent_child(self.root, self.child_node1)
71
+ # self.tree.relate_parent_child(self.child_node1, self.child_node2)
72
+ # # Trees should always be acyclic
73
+ # self.assertTrue(self.tree.acyclic)
74
+ #
75
+ # if __name__ == "__main__":
76
+ # unittest.main()
File without changes
@@ -0,0 +1,98 @@
1
+ import pytest
2
+
3
+ from lionagi.core.mail import Mail
4
+ from lionagi.core.mail.package import Package
5
+ from datetime import datetime
6
+
7
+ """
8
+ More to be added
9
+ """
10
+
11
+
12
+ def trim_timestamp_to_day(timestamp_str):
13
+ dt = datetime.fromisoformat(timestamp_str)
14
+ return dt.strftime('%Y-%m-%d')
15
+
16
+
17
+ class MockPackage(Package):
18
+ """A mock package class for testing purposes."""
19
+
20
+
21
+ @pytest.fixture
22
+ def mail():
23
+ """Fixture to create a Mail instance with a MockPackage."""
24
+ package = MockPackage()
25
+ mail_instance = Mail(timestamp=datetime.today().strftime('%Y-%m-%d'), package=package)
26
+ return mail_instance
27
+
28
+
29
+ def test_mail_category(mail):
30
+ """Test the category property of Mail."""
31
+ assert mail.category is None
32
+
33
+
34
+
35
+
36
+
37
+ # from lionagi.core.generic.mail import *
38
+ #
39
+ # import unittest
40
+ #
41
+ #
42
+ # class TestMail(unittest.TestCase):
43
+ # def setUp(self):
44
+ # self.mail = Mail(
45
+ # sender="node1",
46
+ # recipient="node2",
47
+ # category=MailPackageCategory.MESSAGES,
48
+ # package="Hello, World!"
49
+ # )
50
+ #
51
+ # def test_mail_initialization(self):
52
+ # """Test initialization of Mail objects."""
53
+ # self.assertIsInstance(self.mail, BaseComponent)
54
+ # self.assertEqual(self.mail.sender, "node1")
55
+ # self.assertEqual(self.mail.recipient, "node2")
56
+ # self.assertEqual(self.mail.category, MailPackageCategory.MESSAGES)
57
+ # self.assertEqual(self.mail.package, "Hello, World!")
58
+ #
59
+ # def test_mail_str(self):
60
+ # """Test the string representation of Mail."""
61
+ # expected_str = "Mail from node1 to node2 with category messages and package Hello, World!"
62
+ # self.assertEqual(str(self.mail), expected_str)
63
+ #
64
+ # class TestMailBox(unittest.TestCase):
65
+ # def setUp(self):
66
+ # self.mailbox = MailBox()
67
+ # self.mail1 = Mail(
68
+ # sender="node1",
69
+ # recipient="node3",
70
+ # category="model",
71
+ # package={"model": "Random Forest"}
72
+ # )
73
+ # self.mail2 = Mail(
74
+ # sender="node2",
75
+ # recipient="node3",
76
+ # category=MailPackageCategory.SERVICE,
77
+ # package={"service": "Prediction"}
78
+ # )
79
+ #
80
+ # def test_adding_mails(self):
81
+ # """Test adding mails to MailBox."""
82
+ # self.mailbox.pending_ins["node1"] = self.mail1
83
+ # self.mailbox.pending_outs["node3"] = self.mail2
84
+ #
85
+ # self.assertIn("node1", self.mailbox.pending_ins)
86
+ # self.assertIn("node3", self.mailbox.pending_outs)
87
+ # self.assertEqual(self.mailbox.pending_ins["node1"], self.mail1)
88
+ # self.assertEqual(self.mailbox.pending_outs["node3"], self.mail2)
89
+ #
90
+ # def test_mailbox_str(self):
91
+ # """Test the string representation of MailBox."""
92
+ # self.mailbox.pending_ins["node1"] = self.mail1
93
+ # self.mailbox.pending_outs["node3"] = self.mail2
94
+ # expected_str = "MailBox with 1 pending incoming mails and 1 pending outgoing mails."
95
+ # self.assertEqual(str(self.mailbox), expected_str)
96
+ #
97
+ # if __name__ == "__main__":
98
+ # unittest.main()
File without changes
@@ -0,0 +1,198 @@
1
+ #TODO
2
+
3
+ # import unittest
4
+ # from unittest.mock import MagicMock, patch
5
+ # from lionagi.core.tool.structure import *
6
+ #
7
+ #
8
+ # class TestBaseStructure(unittest.TestCase):
9
+ # def setUp(self):
10
+ # self.structure = BaseStructure()
11
+ # self.node1 = BaseNode(id_="node1")
12
+ # self.node2 = BaseNode(id_="node2")
13
+ # self.node3 = BaseNode(id_="node3")
14
+ # self.edge1 = Edge(id_="edge1", source_node_id="node1", target_node_id="node2")
15
+ # self.edge2 = Edge(id_="edge2", source_node_id="node2", target_node_id="node3")
16
+ #
17
+ # def test_node_edges_property(self):
18
+ # self.node1.in_relations = {"edge1": self.edge1}
19
+ # self.node1.out_relations = {"edge2": self.edge2}
20
+ # self.structure.structure_nodes = {"node1": self.node1}
21
+ # expected_result = {
22
+ # "node1": {"in": {"edge1": self.edge1}, "out": {"edge2": self.edge2}}
23
+ # }
24
+ # self.assertEqual(self.structure.node_edges, expected_result)
25
+ #
26
+ # def test_get_node_edges_with_node(self):
27
+ # self.node1.out_relations = {"edge1": self.edge1}
28
+ # self.node1.in_relations = {"edge2": self.edge2}
29
+ # self.structure.structure_nodes = {"node1": self.node1}
30
+ # self.assertEqual(
31
+ # self.structure.get_node_edges(self.node1, direction="out"), [self.edge1]
32
+ # )
33
+ # self.assertEqual(
34
+ # self.structure.get_node_edges(self.node1, direction="in"), [self.edge2]
35
+ # )
36
+ # self.assertEqual(
37
+ # self.structure.get_node_edges(self.node1, direction="all"),
38
+ # [self.edge2, self.edge1],
39
+ # )
40
+ #
41
+ # def test_get_node_edges_without_node(self):
42
+ # self.structure.structure_edges = {"edge1": self.edge1, "edge2": self.edge2}
43
+ # self.assertEqual(self.structure.get_node_edges(), [self.edge1, self.edge2])
44
+ #
45
+ # def test_get_node_edges_node_not_found(self):
46
+ # invalid_node = BaseNode(id_="invalid_node")
47
+ # try:
48
+ # self.structure.get_node_edges(invalid_node)
49
+ # except KeyError as e:
50
+ # self.assertEqual(str(e), f"node {invalid_node.id_} is not found")
51
+ #
52
+ # def test_has_structure_edge_with_edge_object(self):
53
+ # self.structure.structure_edges = {"edge1": self.edge1}
54
+ # self.assertTrue(self.structure.has_structure_edge(self.edge1))
55
+ #
56
+ # def test_has_structure_edge_with_edge_id(self):
57
+ # self.structure.structure_edges = {"edge1": self.edge1}
58
+ # self.assertTrue(self.structure.has_structure_edge("edge1"))
59
+ #
60
+ # def test_get_structure_edge_with_edge_object(self):
61
+ # self.structure.structure_edges = {"edge1": self.edge1}
62
+ # self.assertEqual(self.structure.get_structure_edge(self.edge1), self.edge1)
63
+ #
64
+ # def test_get_structure_edge_with_edge_id(self):
65
+ # self.structure.structure_edges = {"edge1": self.edge1}
66
+ # self.assertEqual(self.structure.get_structure_edge("edge1"), self.edge1)
67
+ #
68
+ # def test_add_structure_edge_success(self):
69
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
70
+ # self.structure.add_structure_edge(self.edge1)
71
+ # self.assertEqual(self.structure.structure_edges, {"edge1": self.edge1})
72
+ # self.assertEqual(self.node1.out_relations, {"node2": self.edge1})
73
+ # self.assertEqual(self.node2.in_relations, {"node1": self.edge1})
74
+ #
75
+ # def test_add_structure_edge_failure(self):
76
+ # with self.assertRaises(ValueError):
77
+ # self.structure.add_structure_edge(self.edge1)
78
+ #
79
+ # def test_remove_structure_edge_with_edge_object(self):
80
+ # self.structure.structure_edges = {"edge1": self.edge1}
81
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
82
+ # self.node1.out_relations = {"node2": self.edge1}
83
+ # self.node2.in_relations = {"node1": self.edge1}
84
+ # self.structure.remove_structure_edge(self.edge1)
85
+ # self.assertEqual(self.structure.structure_edges, {})
86
+ # self.assertEqual(self.node1.out_relations, {})
87
+ # self.assertEqual(self.node2.in_relations, {})
88
+ #
89
+ # def test_remove_structure_edge_with_edge_id(self):
90
+ # self.structure.structure_edges = {"edge1": self.edge1}
91
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
92
+ # self.node1.out_relations = {"node2": self.edge1}
93
+ # self.node2.in_relations = {"node1": self.edge1}
94
+ # self.structure.remove_structure_edge("edge1")
95
+ # self.assertEqual(self.structure.structure_edges, {})
96
+ # self.assertEqual(self.node1.out_relations, {})
97
+ # self.assertEqual(self.node2.in_relations, {})
98
+ #
99
+ # def test_remove_structure_node_success(self):
100
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
101
+ # self.structure.structure_edges = {"edge1": self.edge1}
102
+ # self.node1.out_relations = {"node2": self.edge1}
103
+ # self.node2.in_relations = {"node1": self.edge1}
104
+ # self.structure.remove_structure_node(self.node1)
105
+ # self.assertEqual(self.structure.structure_nodes, {"node2": self.node2})
106
+ # self.assertEqual(self.structure.structure_edges, {})
107
+ #
108
+ # def test_remove_structure_node_failure(self):
109
+ # with self.assertRaises(ValueError):
110
+ # self.structure.remove_structure_node(self.node1)
111
+ #
112
+ # def test_add_structure_node_with_base_node(self):
113
+ # self.structure.add_structure_node(self.node1)
114
+ # self.assertEqual(self.structure.structure_nodes, {"node1": self.node1})
115
+ #
116
+ # def test_add_structure_node_with_list(self):
117
+ # self.structure.add_structure_node([self.node1, self.node2])
118
+ # self.assertEqual(
119
+ # self.structure.structure_nodes, {"node1": self.node1, "node2": self.node2}
120
+ # )
121
+ #
122
+ # def test_add_structure_node_with_dict(self):
123
+ # self.structure.add_structure_node({"node1": self.node1, "node2": self.node2})
124
+ # self.assertEqual(
125
+ # self.structure.structure_nodes, {"node1": self.node1, "node2": self.node2}
126
+ # )
127
+ #
128
+ # def test_add_structure_node_unsupported_type(self):
129
+ # with self.assertRaises(NotImplementedError):
130
+ # self.structure.add_structure_node(1)
131
+ #
132
+ # def test_get_structure_node_with_node_id(self):
133
+ # self.structure.structure_nodes = {"node1": self.node1}
134
+ # self.assertEqual(self.structure.get_structure_node("node1"), self.node1)
135
+ #
136
+ # def test_get_structure_node_with_base_node(self):
137
+ # self.structure.structure_nodes = {"node1": self.node1}
138
+ # self.assertEqual(self.structure.get_structure_node(self.node1), self.node1)
139
+ #
140
+ # def test_get_structure_node_with_list(self):
141
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
142
+ # self.assertEqual(
143
+ # self.structure.get_structure_node(["node1", "node2"]),
144
+ # [self.node1, self.node2],
145
+ # )
146
+ #
147
+ # def test_pop_structure_node_with_node_id(self):
148
+ # self.structure.structure_nodes = {"node1": self.node1}
149
+ # self.assertEqual(self.structure.pop_structure_node("node1"), self.node1)
150
+ # self.assertEqual(self.structure.structure_nodes, {})
151
+ #
152
+ # def test_pop_structure_node_with_base_node(self):
153
+ # self.structure.structure_nodes = {"node1": self.node1}
154
+ # self.assertEqual(self.structure.pop_structure_node(self.node1), self.node1)
155
+ # self.assertEqual(self.structure.structure_nodes, {})
156
+ #
157
+ # def test_pop_structure_node_with_list(self):
158
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
159
+ # self.assertEqual(
160
+ # self.structure.pop_structure_node(["node1", "node2"]),
161
+ # [self.node1, self.node2],
162
+ # )
163
+ # self.assertEqual(self.structure.structure_nodes, {})
164
+ #
165
+ # def test_pop_structure_node_unsupported_type(self):
166
+ # with self.assertRaises(NotImplementedError):
167
+ # self.structure.pop_structure_node(1)
168
+ #
169
+ # def test_has_structure_node_with_node_id(self):
170
+ # self.structure.structure_nodes = {"node1": self.node1}
171
+ # self.assertTrue(self.structure.has_structure_node("node1"))
172
+ # self.assertFalse(self.structure.has_structure_node("node2"))
173
+ #
174
+ # def test_has_structure_node_with_base_node(self):
175
+ # self.structure.structure_nodes = {"node1": self.node1}
176
+ # self.assertTrue(self.structure.has_structure_node(self.node1))
177
+ # self.assertFalse(self.structure.has_structure_node(self.node2))
178
+ #
179
+ # def test_has_structure_node_with_list(self):
180
+ # self.structure.structure_nodes = {"node1": self.node1, "node2": self.node2}
181
+ # self.assertTrue(self.structure.has_structure_node(["node1", "node2"]))
182
+ # self.assertFalse(self.structure.has_structure_node(["node1", "node3"]))
183
+ #
184
+ # def test_is_empty_property(self):
185
+ # self.assertTrue(self.structure.is_empty)
186
+ # self.structure.structure_nodes = {"node1": self.node1}
187
+ # self.assertFalse(self.structure.is_empty)
188
+ #
189
+ # def test_clear_method(self):
190
+ # self.structure.structure_nodes = {"node1": self.node1}
191
+ # self.structure.structure_edges = {"edge1": self.edge1}
192
+ # self.structure.clear()
193
+ # self.assertEqual(self.structure.structure_nodes, {})
194
+ # self.assertEqual(self.structure.structure_edges, {})
195
+ #
196
+ #
197
+ # if __name__ == "__main__":
198
+ # unittest.main()