message: improved robustness of Question and Answer content checks and tests

This commit is contained in:
2023-09-01 16:00:24 +02:00
parent f9d749cdd8
commit fa292fb73a
2 changed files with 49 additions and 28 deletions
+23 -6
View File
@@ -61,22 +61,39 @@ class SourceCodeTestCase(CmmTestCase):
class QuestionTestCase(CmmTestCase):
def test_question_with_prefix(self) -> None:
def test_question_with_header(self) -> None:
with self.assertRaises(MessageError):
Question("=== QUESTION === What is your name?")
Question(f"{Question.txt_header}\nWhat is your name?")
def test_question_without_prefix(self) -> None:
def test_question_with_answer_header(self) -> None:
with self.assertRaises(MessageError):
Question(f"{Answer.txt_header}\nBob")
def test_question_with_legal_header(self) -> None:
"""
If the header is just a part of a line, it's fine.
"""
question = Question(f"This is a line contaning '{Question.txt_header}'\nWhat does that mean?")
self.assertIsInstance(question, Question)
self.assertEqual(question, f"This is a line contaning '{Question.txt_header}'\nWhat does that mean?")
def test_question_without_header(self) -> None:
question = Question("What is your favorite color?")
self.assertIsInstance(question, Question)
self.assertEqual(question, "What is your favorite color?")
class AnswerTestCase(CmmTestCase):
def test_answer_with_prefix(self) -> None:
def test_answer_with_header(self) -> None:
with self.assertRaises(MessageError):
Answer("=== ANSWER === Yes")
Answer(f"{Answer.txt_header}\nno")
def test_answer_without_prefix(self) -> None:
def test_answer_with_legal_header(self) -> None:
answer = Answer(f"This is a line contaning '{Answer.txt_header}'\nIt is what it is.")
self.assertIsInstance(answer, Answer)
self.assertEqual(answer, f"This is a line contaning '{Answer.txt_header}'\nIt is what it is.")
def test_answer_without_header(self) -> None:
answer = Answer("No")
self.assertIsInstance(answer, Answer)
self.assertEqual(answer, "No")