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

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,75 +1,76 @@
1
- import unittest
2
- from lionagi.core.graph.tree import TreeNode, Tree
3
-
4
- class TestTreeNode(unittest.TestCase):
5
- def setUp(self):
6
- self.parent_node = TreeNode(id_="parent", content="Parent Node")
7
- self.child_node1 = TreeNode(id_="child1", content="Child Node 1")
8
- self.child_node2 = TreeNode(id_="child2", content="Child Node 2")
9
-
10
- def test_relate_child(self):
11
- self.parent_node.relate_child(self.child_node1)
12
- self.assertIn("child1", self.parent_node.children)
13
- self.assertEqual(self.child_node1.parent, self.parent_node)
14
-
15
- def test_relate_children(self):
16
- self.parent_node.relate_child([self.child_node1, self.child_node2])
17
- self.assertIn("child1", self.parent_node.children)
18
- self.assertIn("child2", self.parent_node.children)
19
- self.assertEqual(self.child_node1.parent, self.parent_node)
20
- self.assertEqual(self.child_node2.parent, self.parent_node)
21
-
22
- def test_relate_parent(self):
23
- self.child_node1.relate_parent(self.parent_node)
24
- self.assertIn("child1", self.parent_node.children)
25
- self.assertEqual(self.child_node1.parent, self.parent_node)
26
-
27
- def test_unrelate_child(self):
28
- self.parent_node.relate_child(self.child_node1)
29
- self.parent_node.unrelate_child(self.child_node1)
30
- self.assertNotIn("child1", self.parent_node.children)
31
- self.assertIsNone(self.child_node1.parent)
32
-
33
- def test_unrelate_parent(self):
34
- self.child_node1.relate_parent(self.parent_node)
35
- self.child_node1.unrelate_parent()
36
- self.assertNotIn("child1", self.parent_node.children)
37
- self.assertIsNone(self.child_node1.parent)
38
-
39
- class TestTree(unittest.TestCase):
40
- def setUp(self):
41
- self.tree = Tree()
42
- self.root = TreeNode(id_="root", content="Root Node")
43
- self.child_node1 = TreeNode(id_="child1", content="Child Node 1")
44
- self.child_node2 = TreeNode(id_="child2", content="Child Node 2")
45
- self.grandchild_node = TreeNode(id_="grandchild", content="Grandchild Node")
46
-
47
- def test_add_node(self):
48
- self.tree.add_node(self.root)
49
- self.assertIn("root", self.tree.internal_nodes)
50
-
51
- def test_relate_parent_child(self):
52
- self.tree.relate_parent_child(self.root, [self.child_node1, self.child_node2])
53
- self.assertIn("child1", self.root.children)
54
- self.assertIn("child2", self.root.children)
55
- self.assertEqual(self.tree.root, self.root)
56
-
57
- def test_tree_structure(self):
58
- # Build the tree
59
- self.tree.relate_parent_child(self.root, [self.child_node1, self.child_node2])
60
- self.tree.relate_parent_child(self.child_node1, self.grandchild_node)
61
-
62
- # Check the tree structure
63
- self.assertIn("grandchild", self.child_node1.children)
64
- self.assertEqual(self.grandchild_node.parent, self.child_node1)
65
- self.assertEqual(self.child_node1.parent, self.root)
66
-
67
- def test_acyclic(self):
68
- # Build the tree
69
- self.tree.relate_parent_child(self.root, self.child_node1)
70
- self.tree.relate_parent_child(self.child_node1, self.child_node2)
71
- # Trees should always be acyclic
72
- self.assertTrue(self.tree.acyclic)
73
-
74
- if __name__ == "__main__":
75
- unittest.main()
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()
@@ -1,62 +1,98 @@
1
- from lionagi.core.generic.mail import *
2
-
3
- import unittest
4
-
5
-
6
- class TestMail(unittest.TestCase):
7
- def setUp(self):
8
- self.mail = Mail(
9
- sender="node1",
10
- recipient="node2",
11
- category=MailPackageCategory.MESSAGES,
12
- package="Hello, World!"
13
- )
14
-
15
- def test_mail_initialization(self):
16
- """Test initialization of Mail objects."""
17
- self.assertIsInstance(self.mail, BaseComponent)
18
- self.assertEqual(self.mail.sender, "node1")
19
- self.assertEqual(self.mail.recipient, "node2")
20
- self.assertEqual(self.mail.category, MailPackageCategory.MESSAGES)
21
- self.assertEqual(self.mail.package, "Hello, World!")
22
-
23
- def test_mail_str(self):
24
- """Test the string representation of Mail."""
25
- expected_str = "Mail from node1 to node2 with category messages and package Hello, World!"
26
- self.assertEqual(str(self.mail), expected_str)
27
-
28
- class TestMailBox(unittest.TestCase):
29
- def setUp(self):
30
- self.mailbox = MailBox()
31
- self.mail1 = Mail(
32
- sender="node1",
33
- recipient="node3",
34
- category="model",
35
- package={"model": "Random Forest"}
36
- )
37
- self.mail2 = Mail(
38
- sender="node2",
39
- recipient="node3",
40
- category=MailPackageCategory.SERVICE,
41
- package={"service": "Prediction"}
42
- )
43
-
44
- def test_adding_mails(self):
45
- """Test adding mails to MailBox."""
46
- self.mailbox.pending_ins["node1"] = self.mail1
47
- self.mailbox.pending_outs["node3"] = self.mail2
48
-
49
- self.assertIn("node1", self.mailbox.pending_ins)
50
- self.assertIn("node3", self.mailbox.pending_outs)
51
- self.assertEqual(self.mailbox.pending_ins["node1"], self.mail1)
52
- self.assertEqual(self.mailbox.pending_outs["node3"], self.mail2)
53
-
54
- def test_mailbox_str(self):
55
- """Test the string representation of MailBox."""
56
- self.mailbox.pending_ins["node1"] = self.mail1
57
- self.mailbox.pending_outs["node3"] = self.mail2
58
- expected_str = "MailBox with 1 pending incoming mails and 1 pending outgoing mails."
59
- self.assertEqual(str(self.mailbox), expected_str)
60
-
61
- if __name__ == "__main__":
62
- unittest.main()
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()