message / chat: output improvements
This commit is contained in:
+12
-4
@@ -66,16 +66,20 @@ class TestChat(CmmTestCase):
|
||||
def test_print(self, mock_stdout: StringIO) -> None:
|
||||
self.chat.add_messages([self.message1, self.message2])
|
||||
self.chat.print(paged=False)
|
||||
expected_output = f"""{'-'*terminal_width()}
|
||||
{Question.txt_header}
|
||||
expected_output = f"""{Question.txt_header}
|
||||
Question 1
|
||||
{Answer.txt_header}
|
||||
Answer 1
|
||||
|
||||
{'-'*terminal_width()}
|
||||
|
||||
{Question.txt_header}
|
||||
Question 2
|
||||
{Answer.txt_header}
|
||||
Answer 2
|
||||
|
||||
{'-'*terminal_width()}
|
||||
|
||||
"""
|
||||
self.assertEqual(mock_stdout.getvalue(), expected_output)
|
||||
|
||||
@@ -83,20 +87,24 @@ Answer 2
|
||||
def test_print_with_tags_and_file(self, mock_stdout: StringIO) -> None:
|
||||
self.chat.add_messages([self.message1, self.message2])
|
||||
self.chat.print(paged=False, with_tags=True, with_files=True)
|
||||
expected_output = f"""{'-'*terminal_width()}
|
||||
{TagLine.prefix} atag1 btag2
|
||||
expected_output = f"""{TagLine.prefix} atag1 btag2
|
||||
FILE: 0001.txt
|
||||
{Question.txt_header}
|
||||
Question 1
|
||||
{Answer.txt_header}
|
||||
Answer 1
|
||||
|
||||
{'-'*terminal_width()}
|
||||
|
||||
{TagLine.prefix} btag2
|
||||
FILE: 0002.txt
|
||||
{Question.txt_header}
|
||||
Question 2
|
||||
{Answer.txt_header}
|
||||
Answer 2
|
||||
|
||||
{'-'*terminal_width()}
|
||||
|
||||
"""
|
||||
self.assertEqual(mock_stdout.getvalue(), expected_output)
|
||||
|
||||
|
||||
@@ -804,3 +804,27 @@ class MessageRenameTagsTestCase(CmmTestCase):
|
||||
self.message.rename_tags({(Tag('atag1'), Tag('atag2')), (Tag('btag2'), Tag('btag3'))})
|
||||
self.assertIsNotNone(self.message.tags)
|
||||
self.assertSetEqual(self.message.tags, {Tag('atag2'), Tag('btag3')}) # type: ignore [arg-type]
|
||||
|
||||
|
||||
class MessageToStrTestCase(CmmTestCase):
|
||||
def setUp(self) -> None:
|
||||
self.message = Message(Question('This is a question.'),
|
||||
Answer('This is an answer.'),
|
||||
tags={Tag('atag1'), Tag('btag2')},
|
||||
file_path=pathlib.Path('/tmp/foo/bla'))
|
||||
|
||||
def test_to_str(self) -> None:
|
||||
expected_output = f"""{Question.txt_header}
|
||||
This is a question.
|
||||
{Answer.txt_header}
|
||||
This is an answer."""
|
||||
self.assertEqual(self.message.to_str(), expected_output)
|
||||
|
||||
def test_to_str_with_tags_and_file(self) -> None:
|
||||
expected_output = f"""{TagLine.prefix} atag1 btag2
|
||||
FILE: /tmp/foo/bla
|
||||
{Question.txt_header}
|
||||
This is a question.
|
||||
{Answer.txt_header}
|
||||
This is an answer."""
|
||||
self.assertEqual(self.message.to_str(with_tags=True, with_file=True), expected_output)
|
||||
|
||||
Reference in New Issue
Block a user