Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Add test case for perform quiz function
Browse files Browse the repository at this point in the history
  • Loading branch information
shorodilov committed Oct 15, 2023
1 parent a8ff38f commit 6f2fad8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 10 additions & 0 deletions tests/quiz/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ def questions():
"answer": "opt 3",
},
]


@pytest.fixture
def correct_answers():
return "1", "2", "4", "3", "3"


@pytest.fixture
def incorrect_answers():
return "2", "1", "2", "1", "2"
16 changes: 11 additions & 5 deletions tests/quiz/func_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ def test_load_questions_from_file(questions):
assert quiz.load_questions_from_file(fixture) == questions


def test_perform_quiz(questions):
... # TODO
def test_perform_quiz(questions, correct_answers, incorrect_answers):
with patch("builtins.input", side_effect=correct_answers):
assert quiz.perform_quiz(questions) == len(questions)

with patch("builtins.input", side_effect=incorrect_answers):
assert quiz.perform_quiz(questions) == 0


def test_display_question(question):
... # TODO:


def test_gather_answer(question):
with patch("builtins.input", return_value="1"):
answer = quiz.gather_answer(question)
assert answer == 0
with patch("builtins.input", side_effect=["1", "3", "4", "2"]):
assert quiz.gather_answer(question) == 1
assert quiz.gather_answer(question) == 3
assert quiz.gather_answer(question) == 4
assert quiz.gather_answer(question) == 2


def test_gather_answer_repeat():
Expand Down

0 comments on commit 6f2fad8

Please sign in to comment.