question_cmd: now also accepts Messages as source files
This commit was merged in pull request #11.
This commit is contained in:
@@ -5,7 +5,7 @@ import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
from chatmastermind.commands.question import create_message
|
||||
from chatmastermind.message import Message, Question
|
||||
from chatmastermind.message import Message, Question, Answer
|
||||
from chatmastermind.chat import ChatDB
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ class TestMessageCreate(unittest.TestCase):
|
||||
self.cache_path = tempfile.TemporaryDirectory()
|
||||
self.chat = ChatDB.from_dir(cache_path=Path(self.cache_path.name),
|
||||
db_path=Path(self.db_path.name))
|
||||
# create some messages
|
||||
self.message_text = Message(Question("What is this?"),
|
||||
Answer("It is pure text"))
|
||||
self.message_code = Message(Question("What is this?"),
|
||||
Answer("Text\n```\nIt is embedded code\n```\ntext"))
|
||||
self.chat.add_to_db([self.message_text, self.message_code])
|
||||
# create arguments mock
|
||||
self.args = MagicMock(spec=argparse.Namespace)
|
||||
self.args.source_text = None
|
||||
@@ -159,4 +165,31 @@ This is embedded source code.
|
||||
```
|
||||
This is embedded source code.
|
||||
```
|
||||
"""))
|
||||
|
||||
def test_single_question_with_text_only_message(self) -> None:
|
||||
self.args.ask = ["What is this?"]
|
||||
self.args.source_text = [f"{self.chat.messages[0].file_path}"]
|
||||
message = create_message(self.chat, self.args)
|
||||
self.assertIsInstance(message, Message)
|
||||
# file contains no source code (only text)
|
||||
# -> don't expect any in the question
|
||||
self.assertEqual(len(message.question.source_code()), 0)
|
||||
self.assertEqual(message.question, Question(f"""What is this?
|
||||
|
||||
{self.message_text.answer}"""))
|
||||
|
||||
def test_single_question_with_message_and_embedded_code(self) -> None:
|
||||
self.args.ask = ["What is this?"]
|
||||
self.args.source_code = [f"{self.chat.messages[1].file_path}"]
|
||||
message = create_message(self.chat, self.args)
|
||||
self.assertIsInstance(message, Message)
|
||||
# answer contains 1 source code block
|
||||
# -> expect it in the question
|
||||
self.assertEqual(len(message.question.source_code()), 1)
|
||||
self.assertEqual(message.question, Question("""What is this?
|
||||
|
||||
```
|
||||
It is embedded code
|
||||
```
|
||||
"""))
|
||||
|
||||
Reference in New Issue
Block a user