def test_exam_tfquestion(): tfquestion1 = exam.MultiChoiceQuest("mc quest1 text", "subject") tfquestion1.answers = (exam.TrueFalseAnswer(True), exam.TrueFalseAnswer(False)) tfquestion2 = exam.MultiChoiceQuest("mc quest2 text", "subject") tfquestion2.answers = (exam.TrueFalseAnswer(False), exam.TrueFalseAnswer(True)) ex = exam.Exam(tfquestion1, tfquestion2) 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 == "False"
def dummy_exam(): q1 = exam.MultiChoiceQuest("question 1", "subject 1", pathlib.Path("home/img1.png")) a1 = exam.MultiChoiceAnswer("answer 1", pathlib.Path("home/img2.png")) a2 = exam.MultiChoiceAnswer("answer 2", pathlib.Path("home/img3.png")) q1.answers = (a1, a2) q1.correct_value = "B" q2 = exam.MultiChoiceQuest("question 2", "subject 3", pathlib.Path("home/img4.png")) q3 = exam.MultiChoiceQuest("question 3", "subject 3", pathlib.Path("home/img5.png")) a1 = exam.MultiChoiceAnswer("answer 3", pathlib.Path("home/img6.png")) q3.add_answer(a1) dummy_ex = exam.Exam(q1, q2, q3) return dummy_ex
def test_mcquestion_load2(): """load question and only some empty answers; check empty answers are not loaded. """ quest = exam.MultiChoiceQuest() sequence = ( "Text", "Subject", "dir/ec/tor/y", 1, "", "", "Answer", "", "", "", "", "image.png", ) iterator = iter(sequence) quest.load_sequentially(iterator) assert quest.text == sequence[0] assert quest.subject == sequence[1] assert quest.image == Path(sequence[2]) assert quest.level == sequence[3] assert quest.answers[0].text == sequence[6] assert quest.answers[0].image == Path(".") assert quest.answers[1].text == sequence[10] assert quest.answers[1].image == Path(sequence[11]) with pytest.raises(IndexError): _ = quest.answers[2]
def test_exam_mixquestion(): mcquestion = exam.MultiChoiceQuest("mc quest1 text", "subject") mcquestion.answers = ( exam.MultiChoiceAnswer("Q1 A1"), exam.MultiChoiceAnswer("Q1 A2"), exam.MultiChoiceAnswer("Q1 A3"), ) tfquestion = exam.MultiChoiceQuest("mc quest2 text", "subject") tfquestion.answers = (exam.TrueFalseAnswer(False), exam.TrueFalseAnswer(True)) ex = exam.Exam(mcquestion, tfquestion) 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 == "False"
def test_exam_add_path_parent(): image = Path("images/image.png") path = Path("/project/A/") q1 = exam.MultiChoiceQuest("q1 text", "") q1.answers = ( exam.MultiChoiceAnswer("a1 text", image), exam.MultiChoiceAnswer("a2 text", image), ) q2 = exam.MultiChoiceQuest("q2 text", "", image) q2.add_answer(exam.MultiChoiceAnswer("a3 text")) ex = exam.Exam(q1, q2) ex.add_path_parent(path) assert ex.questions[0].image == Path() assert ex.questions[0].answers[0].image == path.parent / image assert ex.questions[0].answers[1].image == path.parent / image assert ex.questions[1].image == path.parent / image assert ex.questions[1].answers[0].image == Path()
def test_mcquestion_init0(): """test init with no answer """ q = exam.MultiChoiceQuest() assert q.text == "" assert q.subject == "" assert q.image == Path() assert q.level == 0
def test_mcquestion_add(): """Test add answer """ q = exam.MultiChoiceQuest("Who are you?") a1 = exam.MultiChoiceAnswer("That's me.") q.add_answer(a1) assert q.correct_answer == a1 assert q.correct_index == 0 assert q.correct_option == "A"
def test_mcquestion_init1(): """test init with no answer """ text, subject, image, level = ("q text", "q subject", Path("image.png"), 2) q = exam.MultiChoiceQuest(text, subject, image, level) assert q.text == text assert q.subject == subject assert q.image == image assert q.level == level
def test_exam_mcquestion(): mcquestion1 = exam.MultiChoiceQuest("mc quest1 text", "subject") mcquestion1.answers = ( exam.MultiChoiceAnswer("Q1 A1"), exam.MultiChoiceAnswer("Q1 A2"), exam.MultiChoiceAnswer("Q1 A3"), ) mcquestion2 = exam.MultiChoiceQuest("mc quest2 text", "subject") mcquestion2.answers = ( exam.MultiChoiceAnswer("Q2 A1"), exam.MultiChoiceAnswer("Q2 A2"), exam.MultiChoiceAnswer("Q2 A3"), ) ex = exam.Exam(mcquestion1, mcquestion2) assert ex.questions[0].answers[1].image == Path() assert ex.questions[0].correct_answer.text == "Q1 A1" assert ex.questions[1].text == "mc quest2 text"
def test_mcquestion_shuffle1(): """Test shuffle with one question added """ q = exam.MultiChoiceQuest("Who are you?") a1 = exam.MultiChoiceAnswer("That's me.") q.add_answer(a1) random.seed(1) q.shuffle() assert q.correct_answer == a1 assert q.correct_index == 0 assert q.correct_option == "A"
def test_mcquestion_load1(): """load question and only answer text; answer image checked for default value. """ quest = exam.MultiChoiceQuest() sequence = ("Text", "Subject", "dir/ec/tor/y", 1, "Answer") iterator = iter(sequence) quest.load_sequentially(iterator) assert quest.text == sequence[0] assert quest.subject == sequence[1] assert quest.image == Path(sequence[2]) assert quest.level == sequence[3] assert quest.answers[0].text == sequence[4] assert quest.answers[0].image == Path(".") with pytest.raises(IndexError): _ = quest.answers[1]
def test_mcquestion_load0(): """load question and two answers. """ tupl = ("t", "s", "i", 1, "a1", "ai1", "a", "ai2") quest = exam.MultiChoiceQuest() quest.load_sequentially(iter(tupl)) assert quest.text == tupl[0] assert quest.subject == tupl[1] assert quest.image == Path(tupl[2]) assert quest.level == tupl[3] assert quest.answers != () assert quest.answers[0].text == tupl[4] assert quest.answers[0].image == Path(tupl[5]) assert quest.answers[1].text == tupl[6] assert quest.answers[1].image == Path(tupl[7]) with pytest.raises(IndexError): _ = quest.answers[2]
def test_mcquestion_shuffle2(): """Test shuffle with more question added """ q = exam.MultiChoiceQuest("Who are you?") a1 = exam.MultiChoiceAnswer("That's me.") a2 = exam.MultiChoiceAnswer("That's not me.") a3 = exam.MultiChoiceAnswer("That's him") a4 = exam.MultiChoiceAnswer("That's her.") q.add_answer(a1) q.add_answer(a2, True) q.add_answer(a3) q.add_answer(a4) random.seed(1) q.shuffle() assert q.answers == (a4, a1, a3, a2) assert q.correct_answer == a2 assert q.correct_index == 3 assert q.correct_option == "D"