Example #1
0
def test_truefalse_question_init_emtpy():
    quest = exam2pdf.TrueFalseQuest()

    assert quest.text == ""
    assert quest.subject == ""
    assert quest.image == Path()
    assert quest.level == 0
Example #2
0
def test_truefalse_question_shuffle_empty():
    """test shuffle without answer
    """
    quest = exam2pdf.TrueFalseQuest()

    quest.shuffle()

    assert True
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
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)
Example #8
0
def test_truefalse_question_init_full():
    """test init with no answer
    """
    text, subject, image, level = ("q text", "q subject", Path("image.png"), 2)
    quest = exam2pdf.TrueFalseQuest(text, subject, image, level)

    assert quest.text == text
    assert quest.subject == subject
    assert quest.image == image
    assert quest.level == level
Example #9
0
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)
Example #10
0
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"
Example #11
0
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"
Example #12
0
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
Example #13
0
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"
Example #14
0
def test_truefalse_question_load0():
    """load question and two answers.
    """
    tupl = ("t", "s", "i", 1, "1", "image", "", "")
    quest = exam2pdf.TrueFalseQuest()
    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].boolean == bool(tupl[4])
    assert quest.answers[0].image == Path(tupl[5])
    assert quest.answers[1].boolean == bool(tupl[6])
    assert quest.answers[1].image == Path(tupl[7])
    with pytest.raises(IndexError):
        _ = quest.answers[2]
Example #15
0
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"