Change type msg_location to an Enum instead of Literal to be able to get all values easy and improve type checks.
This commit is contained in:
+14
-14
@@ -9,7 +9,7 @@ from chatmastermind.configuration import Config
|
||||
from chatmastermind.commands.question import create_message, question_cmd
|
||||
from chatmastermind.tags import Tag
|
||||
from chatmastermind.message import Message, Question, Answer
|
||||
from chatmastermind.chat import Chat, ChatDB
|
||||
from chatmastermind.chat import Chat, ChatDB, msg_location
|
||||
from chatmastermind.ai import AIError
|
||||
from .test_common import TestWithFakeAI
|
||||
|
||||
@@ -279,7 +279,7 @@ class TestQuestionCmdAsk(TestQuestionCmd):
|
||||
# check for the expected message files
|
||||
chat = ChatDB.from_dir(Path(self.cache_dir.name),
|
||||
Path(self.db_dir.name))
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 1)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, expected_responses)
|
||||
|
||||
@@ -337,7 +337,7 @@ class TestQuestionCmdAsk(TestQuestionCmd):
|
||||
# check for the expected message files
|
||||
chat = ChatDB.from_dir(Path(self.cache_dir.name),
|
||||
Path(self.db_dir.name))
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 1)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, [expected_question])
|
||||
|
||||
@@ -375,7 +375,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
# we expect the original message + the one with the new response
|
||||
expected_responses = [message] + [expected_response]
|
||||
question_cmd(self.args, self.config)
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
print(self.message_list(self.cache_dir))
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 2)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, expected_responses)
|
||||
@@ -396,7 +396,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
model=self.args.model,
|
||||
file_path=Path(self.cache_dir.name) / f'0001{msg_suffix}')
|
||||
chat.msg_write([message])
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
assert cached_msg[0].file_path
|
||||
cached_msg_file_id = cached_msg[0].file_path.stem
|
||||
|
||||
@@ -412,7 +412,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
tags=message.tags,
|
||||
file_path=Path('<NOT COMPARED>'))
|
||||
question_cmd(self.args, self.config)
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 1)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, [expected_response])
|
||||
# also check that the file ID has not been changed
|
||||
@@ -435,7 +435,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
model=self.args.model,
|
||||
file_path=Path(self.cache_dir.name) / f'0001{msg_suffix}')
|
||||
chat.msg_write([message])
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
assert cached_msg[0].file_path
|
||||
cached_msg_file_id = cached_msg[0].file_path.stem
|
||||
|
||||
@@ -452,7 +452,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
tags=message.tags,
|
||||
file_path=Path('<NOT COMPARED>'))
|
||||
question_cmd(self.args, self.config)
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 1)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, [expected_response])
|
||||
# also check that the file ID has not been changed
|
||||
@@ -475,7 +475,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
model=self.args.model,
|
||||
file_path=Path(self.cache_dir.name) / f'0001{msg_suffix}')
|
||||
chat.msg_write([message])
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
assert cached_msg[0].file_path
|
||||
|
||||
# repeat the last question with new arguments (without overwriting)
|
||||
@@ -493,7 +493,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
tags={Tag('newtag')},
|
||||
file_path=Path('<NOT COMPARED>'))
|
||||
question_cmd(self.args, self.config)
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 2)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, [message] + [new_expected_response])
|
||||
|
||||
@@ -513,7 +513,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
model=self.args.model,
|
||||
file_path=Path(self.cache_dir.name) / f'0001{msg_suffix}')
|
||||
chat.msg_write([message])
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
assert cached_msg[0].file_path
|
||||
|
||||
# repeat the last question with new arguments
|
||||
@@ -530,7 +530,7 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
tags={Tag('newtag')},
|
||||
file_path=Path('<NOT COMPARED>'))
|
||||
question_cmd(self.args, self.config)
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 1)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, [new_expected_response])
|
||||
|
||||
@@ -586,8 +586,8 @@ class TestQuestionCmdRepeat(TestQuestionCmd):
|
||||
self.assertEqual(len(self.message_list(self.cache_dir)), 4)
|
||||
self.assertEqual(len(self.message_list(self.db_dir)), 1)
|
||||
expected_cache_messages = [expected_responses[0], message2, expected_responses[1], expected_responses[2]]
|
||||
cached_msg = chat.msg_gather(loc='cache')
|
||||
cached_msg = chat.msg_gather(loc=msg_location.CACHE)
|
||||
self.assert_msgs_equal_except_file_path(cached_msg, expected_cache_messages)
|
||||
# check that the DB message has not been modified at all
|
||||
db_msg = chat.msg_gather(loc='db')
|
||||
db_msg = chat.msg_gather(loc=msg_location.DB)
|
||||
self.assert_msgs_all_equal(db_msg, [message3])
|
||||
|
||||
Reference in New Issue
Block a user