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_multichoiceanswer_init0(): """test default arguments """ a = exam.MultiChoiceAnswer() assert a.text == "" assert a.image == Path()
def test_multichoiceanswer_init2(): """Test wrong arguments """ image = Path() with pytest.raises(TypeError): exam.MultiChoiceAnswer(image)
def test_multichoiceanswer_load(): a = exam.MultiChoiceAnswer() tupl = ("text", ) with pytest.raises(StopIteration): a.load_sequentially(iter(tupl)) assert a.text == tupl[0] assert a.image == Path()
def test_multichoiceanswer_set(attribute, expected): a = exam.MultiChoiceAnswer() try: setattr(a, attribute, expected) except TypeError: assert False assert getattr(a, attribute) == expected
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_multichoiceanswer_print(): a = exam.MultiChoiceAnswer() text = "Answer text" image = "home/mydir/image.jpg" i = iter((text, image)) a.load_sequentially(i) assert f"text: {text}" in a.__str__() assert f"image: {image}" in a.__str__()
def test_multichoiceanswer_attribute(): """Test attribute """ a = exam.MultiChoiceAnswer() expected_attr_load_sequence = ("text", "image") expected_type_caster_sequence = (str, Path) assert a.attr_load_sequence == expected_attr_load_sequence assert a.type_caster_sequence == expected_type_caster_sequence
def test_multichoiceanswer_init1(): """Test init assignment """ text = "text" image = Path("my_pic.jpg") a = exam.MultiChoiceAnswer(text, image) assert a.text == text assert a.image == image
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"
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_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_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_multichoiceanswer_init3(): """Test wrong arguments """ text = "text" with pytest.raises(TypeError): exam.MultiChoiceAnswer(image=text)