Exemplo n.º 1
0
def test_question_correct_index_set_invalid():
    """Test set invalid correct answer index
    """
    q = exam.Question("Who are you?")
    a1 = exam.Answer()
    a2 = exam.Answer()
    q.add_answer(a1)
    q.add_answer(a2)
    with pytest.raises(ValueError):
        q.correct_index = 2
Exemplo n.º 2
0
def test_question_correct_answer_set1():
    """Test set correct answer index
    """
    q = exam.Question("Who are you?")
    a1 = exam.Answer()
    a2 = exam.Answer()
    q.add_answer(a1)
    q.add_answer(a2)
    q.correct_index = 1

    assert q.correct_answer == a2
    assert q.correct_index == 1
Exemplo n.º 3
0
def test_question_answer_correct0():
    """Test correctness of the last
    answer added when is set to correct
    """
    q = exam.Question("Who are you?")
    a1 = exam.Answer()
    a2 = exam.Answer()
    q.add_answer(a2)
    q.add_answer(a1, True)

    assert q.correct_answer == a1
    assert q.correct_index == 1
Exemplo n.º 4
0
def test_question_answer_add1():
    """Test two answers addition
    and correctness
    """
    q = exam.Question("Who are you?")
    a1 = exam.Answer()
    a2 = exam.Answer()
    q.add_answer(a1)
    q.add_answer(a2)

    assert q.answers == (a1, a2)
    assert q.correct_answer == a1
    assert q.correct_index == 0
Exemplo n.º 5
0
def test_question_add_path_parent0():
    """Test whether path is added to Answer.image
    """
    path = Path("home/my_home/file.txt")
    quest = exam.Question("question text", image=Path())
    image_path = Path("image1.png")
    answer_1 = exam.Answer()
    answer_1.image = image_path
    answer_2 = exam.Answer()
    answer_2.image = Path()
    quest.answers = (answer_1, answer_2)
    quest.add_parent_path(path)

    assert quest.image == Path()
    assert quest.answers[0].image == path.parent / image_path
    assert quest.answers[1].image == Path()
Exemplo n.º 6
0
def test_answer_load0():
    """test empty iterator without attribute:
    StopIteration must not be raised
    """
    a = exam.Answer()
    a.load_sequentially(iter(tuple()))

    assert True
Exemplo n.º 7
0
def test_question_answer_setter0():
    """Test tuple addition, overwriting
    previous addition and
    correctness
    """
    q = exam.Question("Who are you?")
    a = exam.Answer()
    q.add_answer(a)
    b = exam.Answer()
    c = exam.Answer()
    q.answers = (b, c)

    assert a not in q.answers
    assert b in q.answers
    assert c in q.answers
    assert q.correct_answer == b
    assert q.correct_index == 0
Exemplo n.º 8
0
def test_question_answer_correct1():
    """Test ineffectiveness of correct setting
    for the first answer added
    """
    q = exam.Question("Who are you?")
    a1 = exam.Answer()
    q.add_answer(a1, False)

    assert q.correct_answer == a1
Exemplo n.º 9
0
def test_answer_load5():
    """test iterator with wrong type
    """
    a = exam.Answer()
    a._attr_load_sequence = ("A", )
    a._type_caster_sequence = (int, )
    iterator = iter("a")

    with pytest.raises(ValueError):
        a.load_sequentially(iterator)
Exemplo n.º 10
0
def test_question_answer_add0():
    """Test one answer addition
    and correctness
    """
    q = exam.Question("Who are you?")
    a = exam.Answer()
    q.add_answer(a)

    assert a in q.answers
    assert q.correct_answer == a
    assert q.correct_index == 0
Exemplo n.º 11
0
def test_answer_load1():
    """test empty iterator;
    one attribute is expected
    """
    a = exam.Answer()
    a._attr_load_sequence = ("A", )
    a._type_caster_sequence = (str, )
    try:
        a.load_sequentially(iter(tuple()))
    except StopIteration:
        pass
Exemplo n.º 12
0
def test_answer_load3():
    """test iterator with one item and two
    attribute is expected
    """
    a = exam.Answer()
    a._attr_load_sequence = ("A", "B")
    a._type_caster_sequence = (int, str)
    test_tuple = ("2", )
    iterator = iter(test_tuple)

    with pytest.raises(StopIteration):
        a.load_sequentially(iterator)

    assert a.A == int(test_tuple[0])
Exemplo n.º 13
0
def test_answer_load4():
    """test iterator with two items and one
    attribute is expected;
    test last item left in the iterator
    """
    a = exam.Answer()
    a._attr_load_sequence = ("A", )
    a._type_caster_sequence = (int, )
    test_tuple = ("2", "abc")
    iterator = iter(test_tuple)

    a.load_sequentially(iterator)

    assert a.A == int(test_tuple[0])
    assert next(iterator) == test_tuple[1]
Exemplo n.º 14
0
        q.correct_answer = a3


def test_question_correct_index_set_invalid():
    """Test set invalid correct answer index
    """
    q = exam.Question("Who are you?")
    a1 = exam.Answer()
    a2 = exam.Answer()
    q.add_answer(a1)
    q.add_answer(a2)
    with pytest.raises(ValueError):
        q.correct_index = 2


A1 = exam.Answer()
A2 = exam.Answer()
A3 = exam.Answer()
A4 = exam.Answer()


@pytest.mark.parametrize(
    "attribute_set, expected, attribute1_get, expected1",
    [
        ("correct_answer", A2, "correct_index", 1),
        ("correct_index", 0, "correct_answer", A1),
        ("correct_index", 2, "correct_answer", A3),
    ],
)
def test_question_set_correct(attribute_set, expected, attribute1_get,
                              expected1):