def test_truefalse_question_wrong_correct_answer_set(): true_answer = exam2pdf.TrueFalseAnswer(True) false_answer = exam2pdf.TrueFalseAnswer(False) quest = exam2pdf.TrueFalseQuest("question") quest._answers = (true_answer, ) with pytest.raises(ValueError): quest.correct_answer = false_answer
def test_truefalse_question_correct_answer_set(): true_answer = exam2pdf.TrueFalseAnswer(True) false_answer = exam2pdf.TrueFalseAnswer(False) quest = exam2pdf.TrueFalseQuest("question") quest._answers = (true_answer, false_answer) quest.correct_answer = false_answer assert quest.correct_answer == false_answer
def test_truefalse_question_add_answers_correct_set(): """test add 2 answer """ true_answer = exam2pdf.TrueFalseAnswer(True) false_answer = exam2pdf.TrueFalseAnswer(False) quest = exam2pdf.TrueFalseQuest() quest.add_answer(true_answer) quest.add_answer(false_answer, is_correct=True) assert quest.correct_answer == false_answer
def test_truefalse_question_add_two_true(): """test add true answers """ true_answer_1 = exam2pdf.TrueFalseAnswer(True) true_answer_2 = exam2pdf.TrueFalseAnswer(True) quest = exam2pdf.TrueFalseQuest() quest.add_answer(true_answer_1) with pytest.raises(ValueError): quest.add_answer(true_answer_2)
def test_truefalse_question_add_three_answers(): """test add 3 answer ... maybe redundant """ true_answer_1 = exam2pdf.TrueFalseAnswer(True) false_answer = exam2pdf.TrueFalseAnswer(False) true_answer_2 = exam2pdf.TrueFalseAnswer(True) quest = exam2pdf.TrueFalseQuest() quest.add_answer(true_answer_1) with pytest.raises(ValueError): quest.answers = (true_answer_1, false_answer, true_answer_2)
def test_truefalse_quest_add_two_answers(): """test add 2 answers """ true_answer = exam2pdf.TrueFalseAnswer(True) false_answer = exam2pdf.TrueFalseAnswer(False) quest = exam2pdf.TrueFalseQuest() quest.answers = (true_answer, false_answer) assert quest.answers == (true_answer, false_answer) assert quest.correct_answer == true_answer assert quest.correct_index == 0 assert quest.correct_option == "Vero"
def test_truefalse_question_shuffle(): """test shuffle for true false question """ false_answer = exam2pdf.TrueFalseAnswer(False) true_answer = exam2pdf.TrueFalseAnswer(True) quest = exam2pdf.TrueFalseQuest() quest.add_answer(false_answer) quest.add_answer(true_answer) assert quest.answers[1].boolean is True quest.shuffle() assert quest.answers[0] == true_answer
def test_truefalse_answer_attribute(): a = exam2pdf.TrueFalseAnswer(True) expected_attr_load_sequence = ("boolean", "image") expected_type_caster_sequence = (bool, Path) assert a.attr_load_sequence == expected_attr_load_sequence assert a.type_caster_sequence == expected_type_caster_sequence
def test_exam_truefalse_question(): question1 = exam2pdf.TrueFalseQuest("mc quest1 text", "subject") question1.answers = ( exam2pdf.TrueFalseAnswer(True), exam2pdf.TrueFalseAnswer(False), ) question2 = exam2pdf.Question("mc quest2 text", "subject") question2.answers = ( exam2pdf.TrueFalseAnswer(False), exam2pdf.TrueFalseAnswer(True), ) ex = exam2pdf.Exam(question1, question2) assert ex.questions[0].answers[1].image == Path() assert ex.questions[0].correct_answer.boolean is True assert ex.questions[1].text == "mc quest2 text" assert ex.questions[1].correct_answer.text == "Falso"
def mix_dummy_exam(): q1 = exam2pdf.Question( "question 1: correct is n. two", "subject 1", Path("a.png") ) a1 = exam2pdf.Answer("answer 1", Path("b.png")) a2 = exam2pdf.Answer("answer 2", Path("c.png")) a3 = exam2pdf.Answer("answer 3", Path("a.png")) q1.answers = (a1, a2, a3) q1.correct_option = "B" q2 = exam2pdf.Question( "question 2: correct is n. one", "subject 1", Path("a.png") ) a1 = exam2pdf.Answer("answer 1") a2 = exam2pdf.Answer("answer 2") a3 = exam2pdf.Answer("answer 3") q2.answers = (a1, a2, a3) q3 = exam2pdf.TrueFalseQuest("question 3: correct is True (first)") a1 = exam2pdf.TrueFalseAnswer(True) a2 = exam2pdf.TrueFalseAnswer(False) q3.answers = (a1, a2) q4 = exam2pdf.Question("question 4: no answer", "subject 2", Path("b.png")) q5 = exam2pdf.TrueFalseQuest("question 5: correct is False (first))") a1 = exam2pdf.TrueFalseAnswer(False) a2 = exam2pdf.TrueFalseAnswer(True) q5.answers = (a1, a2) q6 = exam2pdf.Question( "question 6: correct is n. three", "subject 4", Path("c.png") ) a1 = exam2pdf.Answer("answer 1") a2 = exam2pdf.Answer("answer 2") a3 = exam2pdf.Answer("answer 3") a4 = exam2pdf.Answer("answer 4") q6.add_answer(a1) q6.add_answer(a2) q6.add_answer(a3, is_correct=True) q6.add_answer(a4) dummy_ex = exam2pdf.Exam(q1, q2, q3, q4, q5, q6) return dummy_ex
def test_exam_mix_question(): question = exam2pdf.Question("mc quest1 text", "subject") question.answers = ( exam2pdf.Answer("Q1 A1"), exam2pdf.Answer("Q1 A2"), exam2pdf.Answer("Q1 A3"), ) truefalse_quest = exam2pdf.TrueFalseQuest("mc quest2 text", "subject") truefalse_quest.answers = ( exam2pdf.TrueFalseAnswer(False), exam2pdf.TrueFalseAnswer(True), ) ex = exam2pdf.Exam(question, truefalse_quest) assert ex.questions[0].answers[1].image == Path() assert ex.questions[0].correct_option == "A" assert ex.questions[1].text == "mc quest2 text" assert ex.questions[1].correct_answer.text == "Falso"
def test_truefalse_quest_add_one_answer(): """test add an answer """ answer = exam2pdf.TrueFalseAnswer(True) quest = exam2pdf.TrueFalseQuest() quest.add_answer(answer) assert quest.answers == (answer, ) assert quest.correct_answer == answer assert quest.correct_index == 0 assert quest.correct_option == "Vero"
def test_truefalse_answer_init_two_args(): a = exam2pdf.TrueFalseAnswer(True, Path()) assert a.boolean is True assert a.text == "Vero" assert a.image == Path()
def test_truefalse_answer_init_one_arg(): a = exam2pdf.TrueFalseAnswer(True) a.boolean = False assert a.boolean is False assert a.text == "Falso"
def test_truefalse_answer_init_num_arg(): a = exam2pdf.TrueFalseAnswer(1) assert a.boolean is True assert a.text == "Vero"
def test_truefalse_answer_init_num_arg0(): a = exam2pdf.TrueFalseAnswer(0) assert a.boolean is False assert a.text == "Falso"
def test_truefalse_answer_empty(): a = exam2pdf.TrueFalseAnswer() assert a.boolean is False assert a.text == "Falso"