def test_question_pre(self): question = Question("What?") Quiz(questions=[question]) self.assertEqual( "* Question 1/1. [No answer]\n", question.get_question_pre() ) question.answer = "Good answer" self.assertEqual( "* Question 1/1. [Good answer]\n", question.get_question_pre() ) question.answer = Option(value="A", expression="Best answer.") self.assertEqual( "* Question 1/1. [A) Best answer.]\n", question.get_question_pre() )
def test_skip(self, mock_stdout, *_): question = Question("Hello?", commands=[Skip], required=False) question.answer = "World" question.ask() mock_stdout.assert_called_with("You decided to skip this question.") self.assertIsNone(question.answer) self.assertEqual(1, question.attempt)
def test_answer_persists_on_empty_input(self, *_): question = Question("What?", required=False) question.answer = "Previous Answer" question.ask() self.assertEqual("Previous Answer", question.answer)