From 374f543bea153cd7bf6fa510500347407e62470f Mon Sep 17 00:00:00 2001 From: Media <12145726+rihp@users.noreply.github.com> Date: Sun, 23 Apr 2023 23:50:15 +0200 Subject: [PATCH] Perm memory test cases (#2996) * Update Python version and benchmark file in benchmark.yml * Refactor main function and imports in cli.py * Update import statement in ai_config.py * Add set_temperature and set_memory_backend methods in config.py * Remove unused import in prompt.py * Add goal oriented tasks workflow * Added agent_utils to create agent * added pytest and vcrpy * added write file cassette * created goal oriented task write file with cassettes to not pay openai tokens * solve conflicts * add ability set azure because github workflow needs it off * solve conflicts in cli.py * black because linter fails * solve conflict * setup github action to v3 Signed-off-by: Merwane Hamadi * fix conflicts Signed-off-by: Merwane Hamadi * Plugins: debug line always printed in plugin load * add decorator to tests Signed-off-by: Merwane Hamadi * move decorator higher up Signed-off-by: Merwane Hamadi * init * more tests * passing tests * skip gitbranch decorator on ci * decorator skiponci * black * Update tests/utils.py decorator of skipping ci Co-authored-by: Nicholas Tindle * black * I oopsed the name * black * finally * perm memory tests * perm memory tests --------- Signed-off-by: Merwane Hamadi Co-authored-by: Merwane Hamadi Co-authored-by: Merwane Hamadi Co-authored-by: Richard Beales Co-authored-by: Nicholas Tindle Co-authored-by: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Co-authored-by: Nicholas Tindle --- tests/test_permanent_memory.py | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/test_permanent_memory.py diff --git a/tests/test_permanent_memory.py b/tests/test_permanent_memory.py new file mode 100644 index 00000000..943c61fe --- /dev/null +++ b/tests/test_permanent_memory.py @@ -0,0 +1,59 @@ +import os +import unittest + +from autogpt.permanent_memory.sqlite3_store import MemoryDB + + +class TestMemoryDB(unittest.TestCase): + def setUp(self): + self.db_filename = "test_db.sqlite3" + self.db = MemoryDB(self.db_filename) + + def tearDown(self): + self.db.quit() + os.remove(self.db_filename) + + def test_overwrite_and_get_session(self): + self.db.insert("The quick brown fox jumps over the lazy dog") + self.db.insert("The five boxing wizards jump quickly") + + # Overwrite the second text + self.db.overwrite(1, "The slow elephant walks carefully") + + # Get the session and verify the texts + session = self.db.get_session() + self.assertEqual(len(session), 2) + self.assertIn("The quick brown fox jumps over the lazy dog", session) + self.assertIn("The slow elephant walks carefully", session) + + # Overwrite the first text + self.db.overwrite(0, "The lazy dog jumps over the quick brown fox") + + # Get the session and verify the texts + session = self.db.get_session() + self.assertEqual(len(session), 2) + self.assertIn("The lazy dog jumps over the quick brown fox", session) + self.assertIn("The slow elephant walks carefully", session) + + def test_delete_memory(self): + self.db.insert("The quick brown fox jumps over the lazy dog") + self.db.insert("The five boxing wizards jump quickly") + + # Delete the first text + self.db.delete_memory(0) + + # Get the session and verify the remaining text + session = self.db.get_session() + self.assertEqual(len(session), 1) + self.assertIn("The five boxing wizards jump quickly", session) + + # Delete the remaining text + self.db.delete_memory(1) + + # Get the session and verify that it's empty + session = self.db.get_session() + self.assertEqual(len(session), 0) + + +if __name__ == "__main__": + unittest.main()