lionagi 0.2.11__py3-none-any.whl → 0.3.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. lionagi/core/action/function_calling.py +13 -6
  2. lionagi/core/action/tool.py +10 -9
  3. lionagi/core/action/tool_manager.py +18 -9
  4. lionagi/core/agent/README.md +1 -1
  5. lionagi/core/agent/base_agent.py +5 -2
  6. lionagi/core/agent/eval/README.md +1 -1
  7. lionagi/core/collections/README.md +1 -1
  8. lionagi/core/collections/_logger.py +16 -6
  9. lionagi/core/collections/abc/README.md +1 -1
  10. lionagi/core/collections/abc/component.py +35 -11
  11. lionagi/core/collections/abc/concepts.py +5 -3
  12. lionagi/core/collections/abc/exceptions.py +3 -1
  13. lionagi/core/collections/flow.py +16 -5
  14. lionagi/core/collections/model.py +34 -8
  15. lionagi/core/collections/pile.py +65 -28
  16. lionagi/core/collections/progression.py +1 -2
  17. lionagi/core/collections/util.py +11 -2
  18. lionagi/core/director/README.md +1 -1
  19. lionagi/core/engine/branch_engine.py +35 -10
  20. lionagi/core/engine/instruction_map_engine.py +14 -5
  21. lionagi/core/engine/sandbox_.py +3 -1
  22. lionagi/core/engine/script_engine.py +6 -2
  23. lionagi/core/executor/base_executor.py +10 -3
  24. lionagi/core/executor/graph_executor.py +12 -4
  25. lionagi/core/executor/neo4j_executor.py +18 -6
  26. lionagi/core/generic/edge.py +7 -2
  27. lionagi/core/generic/graph.py +23 -7
  28. lionagi/core/generic/node.py +14 -5
  29. lionagi/core/generic/tree_node.py +5 -1
  30. lionagi/core/mail/mail_manager.py +3 -1
  31. lionagi/core/mail/package.py +3 -1
  32. lionagi/core/message/action_request.py +9 -2
  33. lionagi/core/message/action_response.py +9 -3
  34. lionagi/core/message/instruction.py +8 -2
  35. lionagi/core/message/util.py +15 -5
  36. lionagi/core/report/base.py +12 -7
  37. lionagi/core/report/form.py +7 -4
  38. lionagi/core/report/report.py +10 -3
  39. lionagi/core/report/util.py +3 -1
  40. lionagi/core/rule/action.py +4 -1
  41. lionagi/core/rule/base.py +17 -6
  42. lionagi/core/rule/rulebook.py +8 -4
  43. lionagi/core/rule/string.py +3 -1
  44. lionagi/core/session/branch.py +15 -4
  45. lionagi/core/session/session.py +6 -2
  46. lionagi/core/unit/parallel_unit.py +9 -3
  47. lionagi/core/unit/template/action.py +1 -1
  48. lionagi/core/unit/template/predict.py +3 -1
  49. lionagi/core/unit/template/select.py +5 -3
  50. lionagi/core/unit/unit.py +4 -2
  51. lionagi/core/unit/unit_form.py +13 -15
  52. lionagi/core/unit/unit_mixin.py +45 -27
  53. lionagi/core/unit/util.py +7 -3
  54. lionagi/core/validator/validator.py +28 -15
  55. lionagi/core/work/work_edge.py +7 -3
  56. lionagi/core/work/work_task.py +11 -5
  57. lionagi/core/work/worker.py +20 -5
  58. lionagi/core/work/worker_engine.py +6 -2
  59. lionagi/core/work/worklog.py +3 -1
  60. lionagi/experimental/compressor/llm_compressor.py +20 -5
  61. lionagi/experimental/directive/README.md +1 -1
  62. lionagi/experimental/directive/parser/base_parser.py +41 -14
  63. lionagi/experimental/directive/parser/base_syntax.txt +23 -23
  64. lionagi/experimental/directive/template/base_template.py +14 -6
  65. lionagi/experimental/directive/tokenizer.py +3 -1
  66. lionagi/experimental/evaluator/README.md +1 -1
  67. lionagi/experimental/evaluator/ast_evaluator.py +6 -2
  68. lionagi/experimental/evaluator/base_evaluator.py +27 -16
  69. lionagi/integrations/bridge/autogen_/autogen_.py +7 -3
  70. lionagi/integrations/bridge/langchain_/documents.py +13 -10
  71. lionagi/integrations/bridge/llamaindex_/llama_pack.py +36 -12
  72. lionagi/integrations/bridge/llamaindex_/node_parser.py +8 -3
  73. lionagi/integrations/bridge/llamaindex_/reader.py +3 -1
  74. lionagi/integrations/bridge/llamaindex_/textnode.py +9 -3
  75. lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +7 -1
  76. lionagi/integrations/bridge/transformers_/install_.py +3 -1
  77. lionagi/integrations/chunker/chunk.py +5 -2
  78. lionagi/integrations/loader/load.py +7 -3
  79. lionagi/integrations/loader/load_util.py +35 -16
  80. lionagi/integrations/provider/oai.py +13 -4
  81. lionagi/integrations/provider/openrouter.py +13 -4
  82. lionagi/integrations/provider/services.py +3 -1
  83. lionagi/integrations/provider/transformers.py +5 -3
  84. lionagi/integrations/storage/neo4j.py +23 -7
  85. lionagi/integrations/storage/storage_util.py +23 -7
  86. lionagi/integrations/storage/structure_excel.py +7 -2
  87. lionagi/integrations/storage/to_csv.py +8 -2
  88. lionagi/integrations/storage/to_excel.py +11 -3
  89. lionagi/libs/ln_api.py +41 -19
  90. lionagi/libs/ln_context.py +4 -4
  91. lionagi/libs/ln_convert.py +35 -14
  92. lionagi/libs/ln_dataframe.py +9 -3
  93. lionagi/libs/ln_func_call.py +53 -18
  94. lionagi/libs/ln_image.py +9 -5
  95. lionagi/libs/ln_knowledge_graph.py +21 -7
  96. lionagi/libs/ln_nested.py +57 -16
  97. lionagi/libs/ln_parse.py +45 -15
  98. lionagi/libs/ln_queue.py +8 -3
  99. lionagi/libs/ln_tokenize.py +19 -6
  100. lionagi/libs/ln_validate.py +14 -3
  101. lionagi/libs/sys_util.py +44 -12
  102. lionagi/lions/coder/coder.py +24 -8
  103. lionagi/lions/coder/util.py +6 -2
  104. lionagi/lions/researcher/data_source/google_.py +12 -4
  105. lionagi/lions/researcher/data_source/wiki_.py +3 -1
  106. lionagi/version.py +1 -1
  107. {lionagi-0.2.11.dist-info → lionagi-0.3.0.dist-info}/METADATA +6 -7
  108. lionagi-0.3.0.dist-info/RECORD +226 -0
  109. lionagi/tests/__init__.py +0 -0
  110. lionagi/tests/api/__init__.py +0 -0
  111. lionagi/tests/api/aws/__init__.py +0 -0
  112. lionagi/tests/api/aws/conftest.py +0 -25
  113. lionagi/tests/api/aws/test_aws_s3.py +0 -6
  114. lionagi/tests/integrations/__init__.py +0 -0
  115. lionagi/tests/libs/__init__.py +0 -0
  116. lionagi/tests/libs/test_api.py +0 -48
  117. lionagi/tests/libs/test_convert.py +0 -89
  118. lionagi/tests/libs/test_field_validators.py +0 -354
  119. lionagi/tests/libs/test_func_call.py +0 -701
  120. lionagi/tests/libs/test_nested.py +0 -382
  121. lionagi/tests/libs/test_parse.py +0 -171
  122. lionagi/tests/libs/test_queue.py +0 -68
  123. lionagi/tests/libs/test_sys_util.py +0 -222
  124. lionagi/tests/test_core/__init__.py +0 -0
  125. lionagi/tests/test_core/collections/__init__.py +0 -0
  126. lionagi/tests/test_core/collections/test_component.py +0 -208
  127. lionagi/tests/test_core/collections/test_exchange.py +0 -139
  128. lionagi/tests/test_core/collections/test_flow.py +0 -146
  129. lionagi/tests/test_core/collections/test_pile.py +0 -172
  130. lionagi/tests/test_core/collections/test_progression.py +0 -130
  131. lionagi/tests/test_core/generic/__init__.py +0 -0
  132. lionagi/tests/test_core/generic/test_edge.py +0 -69
  133. lionagi/tests/test_core/generic/test_graph.py +0 -97
  134. lionagi/tests/test_core/generic/test_node.py +0 -107
  135. lionagi/tests/test_core/generic/test_structure.py +0 -194
  136. lionagi/tests/test_core/generic/test_tree_node.py +0 -74
  137. lionagi/tests/test_core/graph/__init__.py +0 -0
  138. lionagi/tests/test_core/graph/test_graph.py +0 -71
  139. lionagi/tests/test_core/graph/test_tree.py +0 -76
  140. lionagi/tests/test_core/mail/__init__.py +0 -0
  141. lionagi/tests/test_core/mail/test_mail.py +0 -98
  142. lionagi/tests/test_core/test_branch.py +0 -116
  143. lionagi/tests/test_core/test_form.py +0 -47
  144. lionagi/tests/test_core/test_report.py +0 -106
  145. lionagi/tests/test_core/test_structure/__init__.py +0 -0
  146. lionagi/tests/test_core/test_structure/test_base_structure.py +0 -198
  147. lionagi/tests/test_core/test_structure/test_graph.py +0 -55
  148. lionagi/tests/test_core/test_structure/test_tree.py +0 -49
  149. lionagi/tests/test_core/test_validator.py +0 -112
  150. lionagi-0.2.11.dist-info/RECORD +0 -267
  151. {lionagi-0.2.11.dist-info → lionagi-0.3.0.dist-info}/LICENSE +0 -0
  152. {lionagi-0.2.11.dist-info → lionagi-0.3.0.dist-info}/WHEEL +0 -0
@@ -1,116 +0,0 @@
1
- import unittest
2
- from unittest.mock import MagicMock, patch
3
-
4
- import lionagi as li
5
- from lionagi.core.action.tool_manager import ToolManager
6
- from lionagi.core.collections import Exchange, Pile, Progression
7
- from lionagi.core.message import ActionResponse, AssistantResponse, Instruction, System
8
-
9
-
10
- class TestBranch(unittest.TestCase):
11
-
12
- def setUp(self):
13
- self.branch = li.Branch()
14
-
15
- def test_initialize_branch(self):
16
- self.assertIsInstance(self.branch, li.Branch)
17
- self.assertIsInstance(self.branch.messages, Pile)
18
- self.assertIsInstance(self.branch.progress, Progression)
19
- self.assertIsInstance(self.branch.tool_manager, ToolManager)
20
- self.assertIsInstance(self.branch.mailbox, Exchange)
21
- self.assertIsInstance(self.branch.imodel, li.iModel)
22
-
23
- def test_add_message_system(self):
24
- self.branch.add_message(
25
- system="You are a helpful assistant, let's think step by step"
26
- )
27
- self.assertEqual(len(self.branch.messages), 1)
28
- self.assertEqual(
29
- self.branch.messages[0].content,
30
- {"system_info": "You are a helpful assistant, let's think step by step"},
31
- )
32
-
33
- def test_to_df(self):
34
- self.branch.add_message(
35
- system="You are a helpful assistant, let's think step by step"
36
- )
37
- df = self.branch.to_df()
38
- self.assertEqual(df.iloc[0]["message_type"], "System")
39
- self.assertEqual(df.iloc[0]["role"], "system")
40
-
41
- def test_to_chat_messages(self):
42
- self.branch.add_message(
43
- system="You are a helpful assistant, let's think step by step"
44
- )
45
- chat_msgs = self.branch.to_chat_messages()
46
- self.assertEqual(chat_msgs[0]["role"], "system")
47
- self.assertEqual(
48
- chat_msgs[0]["content"],
49
- "You are a helpful assistant, let's think step by step",
50
- )
51
-
52
- @patch("lionagi.Branch.chat")
53
- async def test_chat(self, mock_chat):
54
- mock_chat.return_value = (
55
- "Rain poured, but their love shone brighter than any storm."
56
- )
57
- response = await self.branch.chat("tell me a 10 word story", logprobs=True)
58
- self.assertEqual(
59
- response, "Rain poured, but their love shone brighter than any storm."
60
- )
61
- mock_chat.assert_called_once_with("tell me a 10 word story", logprobs=True)
62
-
63
- def test_metadata(self):
64
- self.branch.add_message(
65
- system="You are a helpful assistant, let's think step by step"
66
- )
67
- self.assertIn("last_updated", self.branch.messages[0].metadata)
68
-
69
- # def test_register_tools(self):
70
- # tool = MagicMock()
71
- # self.branch.register_tools([tool])
72
- # self.assertIn(tool, self.branch.tool_manager.registry.values())
73
-
74
- # def test_delete_tools(self):
75
- # tool = MagicMock()
76
- # tool.schema_ = {"function": {"name": "test_tool"}}
77
- # self.branch.register_tools([tool])
78
- # self.branch.delete_tools([tool])
79
- # self.assertNotIn("test_tool", self.branch.tool_manager.registry)
80
-
81
- def test_send_receive_mail(self):
82
- self.branch.send = MagicMock()
83
- self.branch.receive = MagicMock()
84
- package = MagicMock()
85
- self.branch.send(recipient="recipient_id", category="message", package=package)
86
- self.branch.receive(sender="recipient_id")
87
- self.branch.send.assert_called_once_with(
88
- recipient="recipient_id", category="message", package=package
89
- )
90
- self.branch.receive.assert_called_once_with(sender="recipient_id")
91
-
92
- async def test_chat_with_tool(self):
93
- async def mock_multiply(number1, number2, number3=1):
94
- return number1 * number2 * number3
95
-
96
- instruction = """
97
- solve the following problem
98
- """
99
- context = """
100
- I have 730_000 trees, with average 123 apples per tree, each weigh 0.4 lbs.
101
- 20 percent are bad and sold for 0.1 dollar per lbs, 30 percent are sold to
102
- brewery for 0.3 dollar per apple, what is my revenue?
103
- """
104
-
105
- self.branch = li.Branch(
106
- "act like a calculator, invoke tool uses", tools=[mock_multiply]
107
- )
108
- response = await self.branch.chat(
109
- instruction=instruction, context=context, tools=True
110
- )
111
- self.assertIsNotNone(response)
112
- self.assertIn("revenue", response.lower())
113
-
114
-
115
- if __name__ == "__main__":
116
- unittest.main()
@@ -1,47 +0,0 @@
1
- import unittest
2
-
3
- from lionagi import Form
4
-
5
-
6
- class TestForm(unittest.TestCase):
7
-
8
- def setUp(self):
9
- self.form = Form(assignment="input1, input2 -> output")
10
-
11
- def test_initial_state(self):
12
- self.assertEqual(self.form.input_fields, ["input1", "input2"])
13
- self.assertEqual(self.form.requested_fields, ["output"])
14
- self.assertFalse(self.form.workable)
15
- self.assertFalse(self.form.filled)
16
- self.assertEqual(
17
- self.form.work_fields, {"input1": None, "input2": None, "output": None}
18
- )
19
-
20
- def test_fill_input_fields(self):
21
- self.form.fill(input1=1, input2=2)
22
- self.assertTrue(self.form.workable)
23
- self.assertFalse(self.form.filled)
24
- self.assertEqual(
25
- self.form.work_fields, {"input1": 1, "input2": 2, "output": None}
26
- )
27
-
28
- def test_fill_all_fields(self):
29
- self.form.fill(input1=1, input2=2)
30
- self.form.fill(output=3)
31
- self.assertTrue(self.form.filled)
32
- self.assertFalse(self.form.workable)
33
- self.assertEqual(self.form.work_fields, {"input1": 1, "input2": 2, "output": 3})
34
-
35
- def test_fill_once(self):
36
- self.form.fill(input1=1, input2=2)
37
- self.form.fill(output=3)
38
- with self.assertRaises(ValueError) as context:
39
- self.form.fill(input1=2, input2=3)
40
- self.assertTrue(
41
- "Form is filled, cannot be worked on again" in str(context.exception)
42
- )
43
- self.assertEqual(self.form.work_fields, {"input1": 1, "input2": 2, "output": 3})
44
-
45
-
46
- if __name__ == "__main__":
47
- unittest.main()
@@ -1,106 +0,0 @@
1
- import unittest
2
-
3
- from lionagi.core.report.form import Form
4
- from lionagi.core.report.report import Report
5
-
6
-
7
- class TestForm(unittest.TestCase):
8
-
9
- def setUp(self):
10
- self.form = Form(assignment="input1, input2 -> output")
11
-
12
- def test_initial_fields(self):
13
- self.assertEqual(self.form.input_fields, ["input1", "input2"])
14
- self.assertEqual(self.form.requested_fields, ["output"])
15
- self.assertFalse(self.form.workable)
16
- self.assertFalse(self.form.filled)
17
- self.assertEqual(
18
- self.form.work_fields, {"input1": None, "input2": None, "output": None}
19
- )
20
-
21
- def test_fill_input_fields(self):
22
- self.form.fill(input1=1, input2=2)
23
- self.assertTrue(self.form.workable)
24
- self.assertFalse(self.form.filled)
25
- self.assertEqual(
26
- self.form.work_fields, {"input1": 1, "input2": 2, "output": None}
27
- )
28
-
29
- def test_fill_output_field(self):
30
- self.form.fill(input1=1, input2=2)
31
- self.form.fill(output=3)
32
- self.assertTrue(self.form.filled)
33
- self.assertEqual(self.form.work_fields, {"input1": 1, "input2": 2, "output": 3})
34
- self.assertFalse(self.form.workable)
35
-
36
- def test_fill_again_raises_error(self):
37
- self.form.fill(input1=1, input2=2, output=3)
38
- with self.assertRaises(ValueError):
39
- self.form.fill(input1=2, input2=3)
40
-
41
-
42
- class TestReport(unittest.TestCase):
43
-
44
- def setUp(self):
45
- self.report = Report(assignment="a, b -> c")
46
-
47
- def test_initial_fields(self):
48
- self.assertEqual(self.report.input_fields, ["a", "b"])
49
- self.assertEqual(self.report.requested_fields, ["c"])
50
- self.assertEqual(self.report.work_fields, {"a": None, "b": None, "c": None})
51
- self.assertFalse(self.report.filled)
52
- self.assertFalse(self.report.workable)
53
-
54
- def test_fill_input_fields(self):
55
- self.report.fill(a=3, b=4)
56
- self.assertEqual(self.report.work_fields, {"a": 3, "b": 4, "c": None})
57
- self.assertTrue(self.report.workable)
58
-
59
- def test_fill_output_field(self):
60
- self.report.fill(a=3, b=4)
61
- self.report.fill(c=4)
62
- self.assertEqual(self.report.work_fields, {"a": 3, "b": 4, "c": 4})
63
- self.assertTrue(self.report.filled)
64
- self.assertFalse(self.report.workable)
65
-
66
- def test_next_forms_none(self):
67
- self.assertIsNone(self.report.next_forms())
68
-
69
- def test_complex_assignment(self):
70
- self.report = Report(
71
- assignment="a, b -> h",
72
- form_assignments=[
73
- "a, b -> c",
74
- "a -> e",
75
- "b -> f",
76
- "c -> g",
77
- "e, f, g -> h",
78
- ],
79
- a=3,
80
- b=4,
81
- )
82
- self.assertEqual(
83
- self.report.work_fields,
84
- {
85
- "a": None,
86
- "b": None,
87
- "c": None,
88
- "e": None,
89
- "f": None,
90
- "g": None,
91
- "h": None,
92
- },
93
- )
94
- self.report.fill(c=5, e=6, f=7, g=8, h=10)
95
- self.assertEqual(
96
- self.report.work_fields,
97
- {"a": None, "b": None, "c": 5, "e": 6, "f": 7, "g": 8, "h": 10},
98
- )
99
- self.assertFalse(self.report.filled)
100
- self.assertFalse(self.report.workable)
101
- with self.assertRaises(ValueError):
102
- self.report.fill(c="xx", e="yy")
103
-
104
-
105
- if __name__ == "__main__":
106
- unittest.main()
File without changes
@@ -1,198 +0,0 @@
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()
@@ -1,55 +0,0 @@
1
- # TODO
2
- # import unittest
3
- # from unittest.mock import MagicMock, patch
4
- # from lionagi.core.generic import BaseNode, Edge
5
- # from lionagi.new.schema.todo.graph import Graph
6
- #
7
- #
8
- # class TestGraph(unittest.TestCase):
9
- # def setUp(self):
10
- # self.graph = Graph()
11
- # self.node1 = BaseNode(id_="node1", content="Node 1")
12
- # self.node2 = BaseNode(id_="node2", content="Node 2")
13
- # self.edge1 = Edge(
14
- # id_="edge1", source_node_id="node1", target_node_id="node2", label="Edge 1"
15
- # )
16
- # self.graph.structure_nodes = {"node1": self.node1, "node2": self.node2}
17
- # self.graph.structure_edges = {"edge1": self.edge1}
18
- #
19
- # @patch("lionagi.libs.SysUtil.check_import")
20
- # def test_to_networkx_success(self, mock_check_import):
21
- # mock_check_import.return_value = None
22
- # with patch("networkx.DiGraph") as mock_digraph:
23
- # mock_graph = MagicMock()
24
- # mock_digraph.return_value = mock_graph
25
- #
26
- # result = self.graph.to_networkx()
27
- #
28
- # self.assertEqual(result, mock_graph)
29
- #
30
- # @patch("lionagi.libs.SysUtil.check_import")
31
- # def test_to_networkx_empty_graph(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
- #
37
- # self.graph.structure_nodes = {}
38
- # self.graph.structure_edges = {}
39
- # result = self.graph.to_networkx()
40
- #
41
- # self.assertEqual(result, mock_graph)
42
- # mock_check_import.assert_called_once_with("networkx")
43
- # mock_digraph.assert_called_once()
44
- # mock_graph.add_node.assert_not_called()
45
- # mock_graph.add_edge.assert_not_called()
46
- #
47
- # @patch("lionagi.libs.SysUtil.check_import", side_effect=ImportError)
48
- # def test_to_networkx_import_error(self, mock_check_import):
49
- # with self.assertRaises(ImportError):
50
- # self.graph.to_networkx()
51
- # mock_check_import.assert_called_once_with("networkx")
52
- #
53
- #
54
- # if __name__ == "__main__":
55
- # unittest.main()
@@ -1,49 +0,0 @@
1
- # TODO
2
- # import unittest
3
- # from lionagi.new.schema.todo.tree import Tree
4
- # from lionagi.core.generic import TreeNode
5
- #
6
- #
7
- # class TestTree(unittest.TestCase):
8
- # def setUp(self):
9
- # self.tree = Tree()
10
- # self.node1 = TreeNode(id_="node1", content="Node 1")
11
- # self.node2 = TreeNode(id_="node2", content="Node 2")
12
- # self.node3 = TreeNode(id_="node3", content="Node 3")
13
- # self.tree.add_structure_node(self.node1)
14
- # self.tree.add_structure_node(self.node2)
15
- # self.tree.add_structure_node(self.node3)
16
- #
17
- # def test_add_parent_to_child(self):
18
- # self.tree.add_parent_to_child(self.node1, self.node2)
19
- # self.assertEqual(self.node2, self.node1.parent)
20
- # self.assertIn(self.node1, self.node2.children)
21
- #
22
- # def test_add_child_to_parent(self):
23
- # self.tree.add_child_to_parent(self.node3, self.node2)
24
- # self.assertEqual(self.node2, self.node3.parent)
25
- # self.assertIn(self.node3, self.node2.children)
26
- #
27
- # def test_find_parent(self):
28
- # self.tree.add_parent_to_child(self.node1, self.node2)
29
- # parent = self.tree.find_parent(self.node1)
30
- # self.assertEqual(self.node2, parent)
31
- #
32
- # def test_find_child(self):
33
- # self.tree.add_parent_to_child(self.node1, self.node2)
34
- # children = self.tree.find_child(self.node2)
35
- # self.assertIn(self.node1, children)
36
- #
37
- # def test_parent_child_relationship(self):
38
- # self.tree.add_parent_to_child(self.node1, self.node2)
39
- # self.tree.add_child_to_parent(self.node3, self.node2)
40
- # self.assertIn(self.node1, self.node2.children)
41
- # self.assertIn(self.node3, self.node2.children)
42
- # self.assertEqual(self.node2, self.node1.parent)
43
- # self.assertEqual(self.node2, self.node3.parent)
44
- #
45
- # # Add more tests as necessary to cover edge cases and other functionalities
46
- #
47
- #
48
- # if __name__ == "__main__":
49
- # unittest.main()