コード例 #1
0
def test_exam_init():
    """test Exam with one and two arguments
    """
    q1, q2 = exam.Question("q1 text",
                           "q1 image"), exam.Question("q2 text", "q2 image")
    ex1 = exam.Exam(q1)
    ex2 = exam.Exam(q1, q2)

    assert ex1.questions == (q1, )
    assert ex2.questions == (q1, q2)
コード例 #2
0
def test_exam_load1():
    """test empty iterable
    """
    ex = exam.Exam()
    ex.load(iter(()))

    assert ex.questions == tuple()
コード例 #3
0
def test_exam_attribute_selector2():
    """test attribute_selector set and type conversion
    """
    ex = exam.Exam()
    expected = ("hello", "2", "times")
    ex.attribute_selector = (expected[0], int(expected[1]), expected[2])

    assert ex.attribute_selector == expected
コード例 #4
0
def test_exam_load3():
    """test without setting _attribute_selector
    and missing row
    """
    ex = exam.Exam()
    reader = (dict([]), dict([("A", "What?"), ("B", "topic")]))
    ex.load(reader)

    assert ex.questions[0].text == "What?"
    assert ex.questions[0].subject == "topic"
コード例 #5
0
def test_exam_questions_setter0():
    """test question set
    """
    q1, q2 = exam.Question("q1 text",
                           "q1 image"), exam.Question("q2 text", "q2 image")
    ex = exam.Exam()
    ex.add_question(q1)
    ex.add_question(q2)

    assert q1 in ex.questions
    assert q2 in ex.questions
コード例 #6
0
def test_exam_questions_setter1():
    """test question set; question added before overwritten
    """
    q1, q2 = exam.Question("q1 text",
                           "q1 image"), exam.Question("q2 text", "q2 image")
    ex = exam.Exam()
    ex.add_question(q1)
    ex.questions = (q2, )

    assert q1 not in ex.questions
    assert q2 in ex.questions
コード例 #7
0
def create_user_exam(name, matnr, semestercount, semester):
    ects = 6
    grade = 1
    year = user_start_year
    month = 1
    if semestercount % 2 == 1:
        semestercount -= 1
        month = 6
    date = datetime.date(year, month, 30)
    return exam.Exam(matnr, user_study, name, name, date, semester, ects,
                     grade)
コード例 #8
0
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"
コード例 #9
0
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
コード例 #10
0
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"
コード例 #11
0
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()
コード例 #12
0
def test_exam_load2():
    """test without setting _attribute_selector
    2 rows -> 2 questions with 2 answers each but second answer image is not provided
    """
    data = (
        dict([
            ("text", "ab"),
            ("subject", "ac"),
            ("image", "ad"),
            ("level", "1"),
            ("a0 text", "ae"),
            ("a0 image", "af"),
            ("a1 text", "ag"),
        ]),
        dict([
            ("text", "ba"),
            ("subject", "bc"),
            ("image", "bd"),
            ("level", "2"),
            ("a0 text", "be"),
            ("a0 image", "bf"),
            ("a1 text", "bg"),
        ]),
    )
    ex = exam.Exam()
    ex.load(data)

    for i in (0, 1):
        assert ex.questions[i].text == data[i]["text"]
        assert ex.questions[i].subject == data[i]["subject"]
        assert ex.questions[i].image == Path(data[i]["image"])
        assert ex.questions[i].level == int(data[i]["level"])
        assert ex.questions[i].answers[0].text == data[i]["a0 text"]
        assert ex.questions[i].answers[0].image == Path(data[i]["a0 image"])
        assert ex.questions[i].answers[1].text == data[i]["a1 text"]
        assert ex.questions[i].answers[1].image == Path()  # default value

    # third answer of second question is not provided
    with pytest.raises(IndexError):
        _ = ex.questions[1].answers[2]

    # third question is not provided
    with pytest.raises(IndexError):
        _ = ex.questions[2]
コード例 #13
0
def test_exam_load4():
    """test setting _attribute_selector
    """
    data = (dict([
        ("A text", "A"),
        ("B text", "B"),
        ("text", "T"),
        ("C text", "A3"),
        ("D text", "A4"),
        ("subject", "S"),
        ("level", 2),
        ("void", ""),
    ]), )
    ex = exam.Exam()
    ex.attribute_selector = (
        "text",
        "subject",
        "void",
        "level",
        "A text",
        "void",
        "B text",
        "void",
        "C text",
    )
    ex.load(data)

    assert ex.questions[0].text == data[0]["text"]
    assert ex.questions[0].subject == data[0]["subject"]
    assert ex.questions[0].image == Path()
    assert ex.questions[0].level == data[0]["level"]
    assert ex.questions[0].answers[0].text == data[0]["A text"]
    assert ex.questions[0].answers[0].image == Path()
    assert ex.questions[0].answers[1].text == data[0]["B text"]
    assert ex.questions[0].answers[1].image == Path()
    assert ex.questions[0].answers[2].text == data[0]["C text"]
    assert ex.questions[0].answers[2].image == Path()

    # no further elements loaded
    with pytest.raises(IndexError):
        _ = ex.questions[0].answers[3]
    with pytest.raises(IndexError):
        _ = ex.questions[1].answers[2]
コード例 #14
0
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"
コード例 #15
0
def test_shuffle():
    data = (
        dict([
            ("question", " Q1"),
            ("A", "A1"),
            ("B", "B1"),
            ("C", "C1"),
            ("D", "D1"),
            ("E", "E1"),
            ("void", ""),
        ]),
        dict([
            ("question", "Q2"),
            ("A", "A2"),
            ("B", "B2"),
            ("C", "C2"),
            ("D", "D2"),
            ("E", "E2"),
            ("void", ""),
        ]),
    )
    correct_values = ("D", "C")
    ex = exam.Exam()
    ex.attribute_selector = (
        "question",
        "void",
        "void",
        "void",
        "A",
        "void",
        "B",
        "void",
        "C",
        "void",
        "D",
        "void",
        "E",
    )
    ex.load(data)
    ex.shuffle()

    for question, value in zip(ex.questions, correct_values):
        assert question.correct_option == value
コード例 #16
0
def test_exam_print():
    data = (dict([
        ("field A", "A1"),
        ("field B", "A2"),
        ("field C", "T"),
        ("field D", "A3"),
        ("field E", "A4"),
        ("field F", "S"),
        ("field G", 2),
        ("void", ""),
    ]), )
    text, q_image, level, a_image = f"text: A1", f"image: .", f"level: 2", f"image: S"
    ex = exam.Exam()
    ex.attribute_selector = ("field A", "void", "void", "field G", "void",
                             "field F")
    ex.load(data)

    assert text in ex.__str__()
    assert q_image in ex.__str__()
    assert level in ex.__str__()
    assert a_image in ex.__str__()
コード例 #17
0
def test_assignment0():
    my_exam = exam.Exam()
    expected = SerializeExam(my_exam).assignment()

    with pytest.raises(StopIteration):
        next(expected)
コード例 #18
0
def test_correction0():
    my_exam = exam.Exam()
    expected = SerializeExam(my_exam).correction()

    with pytest.raises(StopIteration):
        next(expected)
コード例 #19
0
def test_exam_attribute_selector1():
    """test attribute_selector default value"""
    ex = exam.Exam()

    assert ex.attribute_selector == ()
コード例 #20
0
                course.semester = allsem[pos]
                courses.append(course)

        studies.append(
            study.Study(testystudy.studycode, testystudy.studentid,
                        testystudy.matnr, courses, testystudy.progress,
                        label + "-" + str(c)))
        #paths.append(path.Path(newsemester, label, testystudy.id, ipath.studentid, ipath.studycode, ipath.state))
    return studies


exams = []
with open('../data/allpruefungsleistungen.csv', newline='') as plcsv:
    plreader = csv.DictReader(plcsv, delimiter=';')
    for r in plreader:
        exams += [exam.Exam(r['matnr'], r['studyid'], r['courseid'], r['coursename'], \
            toDateTime(r['date']), r['semester'], r['ects'], r['grade'])]

progresses = []
with open('../data/allstudienstatus.csv', newline='') as svcsv:
    svreader = csv.DictReader(svcsv, delimiter=';')
    for i, r in enumerate(svreader):
        progresses += [progress.Progress(i, r['matnr'], r['studyid'], \
            toDateTime(r['start']), toDateTime(r['end']), \
            r['reason'], r['state'])]

matnrs = set(map(lambda x: x.matnr, progresses))
iter = []
for i, m in enumerate(matnrs):
    iter.append((m, i, exams, progresses))

if __name__ == '__main__':
コード例 #21
0
def test_exam():
    """test Exam with no args
    """
    ex = exam.Exam()

    assert ex.questions == tuple()
コード例 #22
0
ファイル: chat.py プロジェクト: artklyachin/mybot
 def exam(self, exam_name, words):
     self._status = "exam"
     self._current_exam = exam.Exam(words, exam_name, 3)