lionagi 0.2.10__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.
- lionagi/core/action/function_calling.py +13 -6
- lionagi/core/action/tool.py +10 -9
- lionagi/core/action/tool_manager.py +18 -9
- lionagi/core/agent/README.md +1 -1
- lionagi/core/agent/base_agent.py +5 -2
- lionagi/core/agent/eval/README.md +1 -1
- lionagi/core/collections/README.md +1 -1
- lionagi/core/collections/_logger.py +16 -6
- lionagi/core/collections/abc/README.md +1 -1
- lionagi/core/collections/abc/component.py +35 -11
- lionagi/core/collections/abc/concepts.py +5 -3
- lionagi/core/collections/abc/exceptions.py +3 -1
- lionagi/core/collections/flow.py +16 -5
- lionagi/core/collections/model.py +34 -8
- lionagi/core/collections/pile.py +65 -28
- lionagi/core/collections/progression.py +1 -2
- lionagi/core/collections/util.py +11 -2
- lionagi/core/director/README.md +1 -1
- lionagi/core/engine/branch_engine.py +35 -10
- lionagi/core/engine/instruction_map_engine.py +14 -5
- lionagi/core/engine/sandbox_.py +3 -1
- lionagi/core/engine/script_engine.py +6 -2
- lionagi/core/executor/base_executor.py +10 -3
- lionagi/core/executor/graph_executor.py +12 -4
- lionagi/core/executor/neo4j_executor.py +18 -6
- lionagi/core/generic/edge.py +7 -2
- lionagi/core/generic/graph.py +23 -7
- lionagi/core/generic/node.py +14 -5
- lionagi/core/generic/tree_node.py +5 -1
- lionagi/core/mail/mail_manager.py +3 -1
- lionagi/core/mail/package.py +3 -1
- lionagi/core/message/action_request.py +9 -2
- lionagi/core/message/action_response.py +9 -3
- lionagi/core/message/instruction.py +8 -2
- lionagi/core/message/util.py +15 -5
- lionagi/core/report/base.py +12 -7
- lionagi/core/report/form.py +7 -4
- lionagi/core/report/report.py +10 -3
- lionagi/core/report/util.py +3 -1
- lionagi/core/rule/action.py +4 -1
- lionagi/core/rule/base.py +17 -6
- lionagi/core/rule/rulebook.py +8 -4
- lionagi/core/rule/string.py +3 -1
- lionagi/core/session/branch.py +15 -4
- lionagi/core/session/session.py +6 -2
- lionagi/core/unit/parallel_unit.py +9 -3
- lionagi/core/unit/template/action.py +1 -1
- lionagi/core/unit/template/predict.py +3 -1
- lionagi/core/unit/template/select.py +5 -3
- lionagi/core/unit/unit.py +50 -2
- lionagi/core/unit/unit_form.py +13 -15
- lionagi/core/unit/unit_mixin.py +45 -27
- lionagi/core/unit/util.py +7 -3
- lionagi/core/validator/validator.py +28 -15
- lionagi/core/work/work_edge.py +7 -3
- lionagi/core/work/work_task.py +11 -5
- lionagi/core/work/worker.py +20 -5
- lionagi/core/work/worker_engine.py +6 -2
- lionagi/core/work/worklog.py +3 -1
- lionagi/experimental/compressor/llm_compressor.py +20 -5
- lionagi/experimental/directive/README.md +1 -1
- lionagi/experimental/directive/parser/base_parser.py +41 -14
- lionagi/experimental/directive/parser/base_syntax.txt +23 -23
- lionagi/experimental/directive/template/base_template.py +14 -6
- lionagi/experimental/directive/tokenizer.py +3 -1
- lionagi/experimental/evaluator/README.md +1 -1
- lionagi/experimental/evaluator/ast_evaluator.py +6 -2
- lionagi/experimental/evaluator/base_evaluator.py +27 -16
- lionagi/integrations/bridge/autogen_/autogen_.py +7 -3
- lionagi/integrations/bridge/langchain_/documents.py +13 -10
- lionagi/integrations/bridge/llamaindex_/llama_pack.py +36 -12
- lionagi/integrations/bridge/llamaindex_/node_parser.py +8 -3
- lionagi/integrations/bridge/llamaindex_/reader.py +3 -1
- lionagi/integrations/bridge/llamaindex_/textnode.py +9 -3
- lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +7 -1
- lionagi/integrations/bridge/transformers_/install_.py +3 -1
- lionagi/integrations/chunker/chunk.py +5 -2
- lionagi/integrations/loader/load.py +7 -3
- lionagi/integrations/loader/load_util.py +35 -16
- lionagi/integrations/provider/oai.py +13 -4
- lionagi/integrations/provider/openrouter.py +13 -4
- lionagi/integrations/provider/services.py +3 -1
- lionagi/integrations/provider/transformers.py +5 -3
- lionagi/integrations/storage/neo4j.py +23 -7
- lionagi/integrations/storage/storage_util.py +23 -7
- lionagi/integrations/storage/structure_excel.py +7 -2
- lionagi/integrations/storage/to_csv.py +8 -2
- lionagi/integrations/storage/to_excel.py +11 -3
- lionagi/libs/ln_api.py +41 -19
- lionagi/libs/ln_context.py +4 -4
- lionagi/libs/ln_convert.py +35 -14
- lionagi/libs/ln_dataframe.py +9 -3
- lionagi/libs/ln_func_call.py +53 -18
- lionagi/libs/ln_image.py +9 -5
- lionagi/libs/ln_knowledge_graph.py +21 -7
- lionagi/libs/ln_nested.py +57 -16
- lionagi/libs/ln_parse.py +45 -15
- lionagi/libs/ln_queue.py +8 -3
- lionagi/libs/ln_tokenize.py +19 -6
- lionagi/libs/ln_validate.py +14 -3
- lionagi/libs/sys_util.py +44 -12
- lionagi/lions/coder/coder.py +24 -8
- lionagi/lions/coder/util.py +6 -2
- lionagi/lions/researcher/data_source/google_.py +12 -4
- lionagi/lions/researcher/data_source/wiki_.py +3 -1
- lionagi/version.py +1 -1
- {lionagi-0.2.10.dist-info → lionagi-0.3.0.dist-info}/METADATA +6 -7
- lionagi-0.3.0.dist-info/RECORD +226 -0
- lionagi/tests/__init__.py +0 -0
- lionagi/tests/api/__init__.py +0 -0
- lionagi/tests/api/aws/__init__.py +0 -0
- lionagi/tests/api/aws/conftest.py +0 -25
- lionagi/tests/api/aws/test_aws_s3.py +0 -6
- lionagi/tests/integrations/__init__.py +0 -0
- lionagi/tests/libs/__init__.py +0 -0
- lionagi/tests/libs/test_api.py +0 -48
- lionagi/tests/libs/test_convert.py +0 -89
- lionagi/tests/libs/test_field_validators.py +0 -354
- lionagi/tests/libs/test_func_call.py +0 -701
- lionagi/tests/libs/test_nested.py +0 -382
- lionagi/tests/libs/test_parse.py +0 -171
- lionagi/tests/libs/test_queue.py +0 -68
- lionagi/tests/libs/test_sys_util.py +0 -222
- lionagi/tests/test_core/__init__.py +0 -0
- lionagi/tests/test_core/collections/__init__.py +0 -0
- lionagi/tests/test_core/collections/test_component.py +0 -208
- lionagi/tests/test_core/collections/test_exchange.py +0 -139
- lionagi/tests/test_core/collections/test_flow.py +0 -146
- lionagi/tests/test_core/collections/test_pile.py +0 -172
- lionagi/tests/test_core/collections/test_progression.py +0 -130
- lionagi/tests/test_core/generic/__init__.py +0 -0
- lionagi/tests/test_core/generic/test_edge.py +0 -69
- lionagi/tests/test_core/generic/test_graph.py +0 -97
- lionagi/tests/test_core/generic/test_node.py +0 -107
- lionagi/tests/test_core/generic/test_structure.py +0 -194
- lionagi/tests/test_core/generic/test_tree_node.py +0 -74
- lionagi/tests/test_core/graph/__init__.py +0 -0
- lionagi/tests/test_core/graph/test_graph.py +0 -71
- lionagi/tests/test_core/graph/test_tree.py +0 -76
- lionagi/tests/test_core/mail/__init__.py +0 -0
- lionagi/tests/test_core/mail/test_mail.py +0 -98
- lionagi/tests/test_core/test_branch.py +0 -116
- lionagi/tests/test_core/test_form.py +0 -47
- lionagi/tests/test_core/test_report.py +0 -106
- lionagi/tests/test_core/test_structure/__init__.py +0 -0
- lionagi/tests/test_core/test_structure/test_base_structure.py +0 -198
- lionagi/tests/test_core/test_structure/test_graph.py +0 -55
- lionagi/tests/test_core/test_structure/test_tree.py +0 -49
- lionagi/tests/test_core/test_validator.py +0 -112
- lionagi-0.2.10.dist-info/RECORD +0 -267
- {lionagi-0.2.10.dist-info → lionagi-0.3.0.dist-info}/LICENSE +0 -0
- {lionagi-0.2.10.dist-info → lionagi-0.3.0.dist-info}/WHEEL +0 -0
@@ -1,107 +0,0 @@
|
|
1
|
-
import unittest
|
2
|
-
|
3
|
-
from lionagi.core.collections.abc import Condition, RelationError
|
4
|
-
from lionagi.core.generic import Node
|
5
|
-
from lionagi.core.generic.edge import Edge
|
6
|
-
|
7
|
-
|
8
|
-
class TestNode(unittest.TestCase):
|
9
|
-
|
10
|
-
def setUp(self):
|
11
|
-
"""Setup nodes for testing."""
|
12
|
-
self.node_a = Node()
|
13
|
-
self.node_b = Node()
|
14
|
-
self.node_c = Node()
|
15
|
-
|
16
|
-
def test_initialization(self):
|
17
|
-
"""Test that a Node initializes with empty relations."""
|
18
|
-
self.assertEqual(len(self.node_a.relations["in"]), 0)
|
19
|
-
self.assertEqual(len(self.node_a.relations["out"]), 0)
|
20
|
-
|
21
|
-
def test_relate_outgoing(self):
|
22
|
-
"""Test relating nodes with an outgoing edge."""
|
23
|
-
self.node_a.relate(self.node_b, "out")
|
24
|
-
self.assertIn(self.node_b.ln_id, self.node_a.related_nodes)
|
25
|
-
self.assertIn(self.node_a.ln_id, self.node_b.related_nodes)
|
26
|
-
self.assertIn(self.node_b.ln_id, self.node_a.successors)
|
27
|
-
self.assertIn(self.node_a.ln_id, self.node_b.predecessors)
|
28
|
-
|
29
|
-
def test_relate_incoming(self):
|
30
|
-
"""Test relating nodes with an incoming edge."""
|
31
|
-
self.node_a.relate(self.node_c, "in")
|
32
|
-
self.assertIn(self.node_c.ln_id, self.node_a.related_nodes)
|
33
|
-
self.assertIn(self.node_a.ln_id, self.node_c.related_nodes)
|
34
|
-
self.assertIn(self.node_a.ln_id, self.node_c.successors)
|
35
|
-
self.assertIn(self.node_c.ln_id, self.node_a.predecessors)
|
36
|
-
|
37
|
-
def test_invalid_relate(self):
|
38
|
-
"""Test that relating nodes with an invalid direction raises ValueError."""
|
39
|
-
with self.assertRaises(ValueError):
|
40
|
-
self.node_a.relate(self.node_b, "invalid_direction")
|
41
|
-
|
42
|
-
def test_remove_edge(self):
|
43
|
-
"""Test removing a specific edge between nodes."""
|
44
|
-
self.node_a.relate(self.node_b, "out")
|
45
|
-
edge = next(iter(self.node_a.relations["out"]))
|
46
|
-
self.assertTrue(self.node_a.remove_edge(self.node_b, edge))
|
47
|
-
|
48
|
-
def test_unrelate_all_edges(self):
|
49
|
-
"""Test unrelating all edges between nodes."""
|
50
|
-
self.node_a.relate(self.node_b, "out")
|
51
|
-
self.assertTrue(self.node_a.unrelate(self.node_b))
|
52
|
-
self.assertNotIn(self.node_b.ln_id, self.node_a.related_nodes)
|
53
|
-
self.assertNotIn(self.node_a.ln_id, self.node_b.related_nodes)
|
54
|
-
|
55
|
-
def test_unrelate_specific_edge(self):
|
56
|
-
"""Test unrelating a specific edge between nodes."""
|
57
|
-
self.node_a.relate(self.node_b, "out")
|
58
|
-
edge = next(iter(self.node_a.relations["out"]))
|
59
|
-
self.assertTrue(self.node_a.unrelate(self.node_b, edge))
|
60
|
-
self.assertNotIn(self.node_b.ln_id, self.node_a.related_nodes)
|
61
|
-
self.assertNotIn(self.node_a.ln_id, self.node_b.related_nodes)
|
62
|
-
|
63
|
-
def test_node_relations(self):
|
64
|
-
"""Test that node relations are correctly categorized."""
|
65
|
-
self.node_a.relate(self.node_b, "out")
|
66
|
-
self.node_a.relate(self.node_c, "in")
|
67
|
-
relations = self.node_a.node_relations
|
68
|
-
self.assertIn(self.node_b.ln_id, relations["out"])
|
69
|
-
self.assertIn(self.node_c.ln_id, relations["in"])
|
70
|
-
|
71
|
-
def test_related_nodes(self):
|
72
|
-
"""Test that related nodes list is correct."""
|
73
|
-
self.node_a.relate(self.node_b, "out")
|
74
|
-
self.node_a.relate(self.node_c, "in")
|
75
|
-
related_nodes = self.node_a.related_nodes
|
76
|
-
self.assertIn(self.node_b.ln_id, related_nodes)
|
77
|
-
self.assertIn(self.node_c.ln_id, related_nodes)
|
78
|
-
|
79
|
-
def test_predecessors(self):
|
80
|
-
"""Test that predecessors list is correct."""
|
81
|
-
self.node_a.relate(self.node_c, "in")
|
82
|
-
self.assertIn(self.node_c.ln_id, self.node_a.predecessors)
|
83
|
-
|
84
|
-
def test_successors(self):
|
85
|
-
"""Test that successors list is correct."""
|
86
|
-
self.node_a.relate(self.node_b, "out")
|
87
|
-
self.assertIn(self.node_b.ln_id, self.node_a.successors)
|
88
|
-
|
89
|
-
def test_str(self):
|
90
|
-
"""Test the string representation of a node."""
|
91
|
-
self.node_a.relate(self.node_b, "out")
|
92
|
-
node_str = str(self.node_a)
|
93
|
-
self.assertIn(self.node_a.ln_id, node_str)
|
94
|
-
self.assertIn("relations", node_str)
|
95
|
-
self.assertIn("1", node_str) # 1 relation
|
96
|
-
|
97
|
-
def test_repr(self):
|
98
|
-
"""Test the repr representation of a node."""
|
99
|
-
self.node_a.relate(self.node_b, "out")
|
100
|
-
node_repr = repr(self.node_a)
|
101
|
-
self.assertIn(self.node_a.ln_id, node_repr)
|
102
|
-
self.assertIn("relations", node_repr)
|
103
|
-
self.assertIn("1", node_repr) # 1 relation
|
104
|
-
|
105
|
-
|
106
|
-
if __name__ == "__main__":
|
107
|
-
unittest.main()
|
@@ -1,194 +0,0 @@
|
|
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,74 +0,0 @@
|
|
1
|
-
import unittest
|
2
|
-
|
3
|
-
from lionagi.core.generic.tree import Tree
|
4
|
-
from lionagi.core.generic.tree_node import TreeNode
|
5
|
-
|
6
|
-
|
7
|
-
class TestTreeNode(unittest.TestCase):
|
8
|
-
|
9
|
-
def setUp(self):
|
10
|
-
self.tree_node1 = TreeNode()
|
11
|
-
self.tree_node2 = TreeNode()
|
12
|
-
self.tree_node3 = TreeNode()
|
13
|
-
self.tree_node4 = TreeNode()
|
14
|
-
self.tree = Tree()
|
15
|
-
|
16
|
-
def test_initialization(self):
|
17
|
-
self.assertIsNone(self.tree_node1.parent)
|
18
|
-
self.assertEqual(self.tree_node1.children, [])
|
19
|
-
self.assertIsInstance(self.tree_node1, TreeNode)
|
20
|
-
self.assertIsInstance(self.tree_node1.ln_id, str)
|
21
|
-
|
22
|
-
def test_relate_child(self):
|
23
|
-
self.tree_node1.relate_child([self.tree_node2, self.tree_node3])
|
24
|
-
self.assertIn(self.tree_node2.ln_id, self.tree_node1.children)
|
25
|
-
self.assertIn(self.tree_node3.ln_id, self.tree_node1.children)
|
26
|
-
self.assertEqual(self.tree_node2.parent, self.tree_node1)
|
27
|
-
self.assertEqual(self.tree_node3.parent, self.tree_node1)
|
28
|
-
|
29
|
-
def test_relate_parent(self):
|
30
|
-
self.tree_node1.relate_parent(self.tree_node4)
|
31
|
-
self.assertEqual(self.tree_node1.parent, self.tree_node4)
|
32
|
-
self.assertIn(self.tree_node1.ln_id, self.tree_node4.children)
|
33
|
-
|
34
|
-
def test_unrelate_parent(self):
|
35
|
-
self.tree_node1.relate_parent(self.tree_node4)
|
36
|
-
self.tree_node1.unrelate_parent()
|
37
|
-
self.assertIsNone(self.tree_node1.parent)
|
38
|
-
|
39
|
-
def test_unrelate_child(self):
|
40
|
-
self.tree_node1.relate_child([self.tree_node2, self.tree_node3])
|
41
|
-
self.tree_node1.unrelate_child([self.tree_node2, self.tree_node3])
|
42
|
-
self.assertNotIn(self.tree_node2.ln_id, self.tree_node1.children)
|
43
|
-
self.assertNotIn(self.tree_node3.ln_id, self.tree_node1.children)
|
44
|
-
self.assertIsNone(self.tree_node2.parent)
|
45
|
-
self.assertIsNone(self.tree_node3.parent)
|
46
|
-
|
47
|
-
def test_tree_integration(self):
|
48
|
-
self.tree.relate_parent_child(
|
49
|
-
self.tree_node1, [self.tree_node2, self.tree_node3, self.tree_node4]
|
50
|
-
)
|
51
|
-
self.assertEqual(len(self.tree.internal_nodes), 4)
|
52
|
-
self.assertEqual(len(self.tree_node1.children), 3)
|
53
|
-
self.assertEqual(self.tree.root, self.tree_node1)
|
54
|
-
|
55
|
-
def test_tree_node_edges(self):
|
56
|
-
self.tree_node1.relate_child([self.tree_node2, self.tree_node3])
|
57
|
-
df = self.tree_node1.edges.to_df()
|
58
|
-
self.assertEqual(len(df), 2)
|
59
|
-
self.assertIn(self.tree_node2.ln_id, df["tail"].values)
|
60
|
-
self.assertIn(self.tree_node3.ln_id, df["tail"].values)
|
61
|
-
|
62
|
-
def test_tree_display(self):
|
63
|
-
# This test is mainly to check if the display function runs without errors
|
64
|
-
self.tree.relate_parent_child(
|
65
|
-
self.tree_node1, [self.tree_node2, self.tree_node3, self.tree_node4]
|
66
|
-
)
|
67
|
-
try:
|
68
|
-
self.tree.display()
|
69
|
-
except Exception as e:
|
70
|
-
self.fail(f"Tree display method raised an exception: {e}")
|
71
|
-
|
72
|
-
|
73
|
-
if __name__ == "__main__":
|
74
|
-
unittest.main()
|
File without changes
|
@@ -1,71 +0,0 @@
|
|
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()
|
@@ -1,76 +0,0 @@
|
|
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
|
@@ -1,98 +0,0 @@
|
|
1
|
-
from datetime import datetime
|
2
|
-
|
3
|
-
import pytest
|
4
|
-
|
5
|
-
from lionagi.core.mail import Mail
|
6
|
-
from lionagi.core.mail.package import Package
|
7
|
-
|
8
|
-
"""
|
9
|
-
More to be added
|
10
|
-
"""
|
11
|
-
|
12
|
-
|
13
|
-
def trim_timestamp_to_day(timestamp_str):
|
14
|
-
dt = datetime.fromisoformat(timestamp_str)
|
15
|
-
return dt.strftime("%Y-%m-%d")
|
16
|
-
|
17
|
-
|
18
|
-
class MockPackage(Package):
|
19
|
-
"""A mock package class for testing purposes."""
|
20
|
-
|
21
|
-
|
22
|
-
@pytest.fixture
|
23
|
-
def mail():
|
24
|
-
"""Fixture to create a Mail instance with a MockPackage."""
|
25
|
-
package = MockPackage()
|
26
|
-
mail_instance = Mail(
|
27
|
-
timestamp=datetime.today().strftime("%Y-%m-%d"), package=package
|
28
|
-
)
|
29
|
-
return mail_instance
|
30
|
-
|
31
|
-
|
32
|
-
def test_mail_category(mail):
|
33
|
-
"""Test the category property of Mail."""
|
34
|
-
assert mail.category is None
|
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()
|