Esempio n. 1
0
def test_game_path_not_replay(mock_getctime, mock_glob):
    """ Ensure that a Question's game_path method while not in replay mode
    returns the most recently created file """
    mock_getctime.return_value = 1
    mock_glob.return_value = ['games/json/mock_game_file.json']
    test_q = generate_question(is_replay=False)
    assert test_q.game_path == 'games/json/mock_game_file.json'
Esempio n. 2
0
def test_ans_correct_no_ans():
    """ Ensure that if the Question instance has no correct answer value
    the correct property method returns False
    """
    test_q = generate_question()
    test_q.correct = None
    assert test_q.answered_correctly is False
Esempio n. 3
0
def test_add_correct_is_replay_true(mock_save):
    """
    Ensure a Question that is in replay mode will not update its correct answer
    or call save
    """
    test_q = generate_question(is_replay=True)
    test_q.add_correct('B')
    assert mock_save.called is False
Esempio n. 4
0
def test_add_correct_not_replay(mock_save):
    """
    Ensure a Question that is not in replay mode will update its correct answer
    and call its save method
    """
    test_q = generate_question(is_replay=False)
    test_q.add_correct('B')
    assert mock_save.called
Esempio n. 5
0
def test_add_prediction():
    """ Ensure Question has its prediction dictionary updated and save is called """
    prediction = "B"
    confidence = {
        "A": "0%",
        "B": "100%",
        "C": "0%"
    }
    expected = {
        "answer": prediction,
        "confidence": confidence
    }
    test_q = generate_question(correct=True)
    test_q.prediction = None
    assert test_q.prediction is None
    test_q.add_prediction(prediction, confidence)
    assert test_q.prediction == expected
Esempio n. 6
0
def test_game_path_is_replay():
    """ Ensure that a Question's game_path method while in replay mode
    will return replay_results.json
    """
    test_q = generate_question(is_replay=True)
    assert test_q.game_path == 'replay_results.json'
Esempio n. 7
0
def test_ans_correct_wrong_ans():
    """ Ensure a Questions answered_correctly property returns False if
    the Questions prediction values doesn't match the correct answer value
    """
    test_q = generate_question(correct=False)
    assert test_q.answered_correctly is False
Esempio n. 8
0
def test_ans_correct_has_ans():
    """ Ensure a Question's answered_correctly property method returns True
     if the Question's prediction matches its correct answer value
    """
    test_q = generate_question(correct=True)
    assert test_q.answered_correctly is True
Esempio n. 9
0
    questions = replay.Replayer.load_questions()
    # make sure correct number of q's loaded
    assert len(questions) == len(globbed_paths) * 12
    # ensure q's ordered by numbers 1-12
    for idx, question in enumerate(questions):
        if idx == 0:
            assert question.number == 1
        else:
            assert question.number >= questions[idx - 1].number


@pytest.mark.parametrize(
    "loaded_questions",
    [
        [],  # no questions loaded
        [generate_question(is_replay=True)
         for _ in range(1)],  # single question
        [generate_question(is_replay=True)
         for _ in range(24)]  # two games worth
    ])
@patch('replay.Replayer.load_questions')
@patch('replay.HqTriviaBot.prediction_time')
@patch('replay.Replayer.setup_output_file')
def test_play(mock_setup_file, mock_prediction_time, mock_load_question,
              loaded_questions):
    """ Ensure running play on Replayer will call its own setup_output_file methos,
    call HqTriviaBot.prediction_time
    """
    mock_load_question.return_value = loaded_questions
    replayer = replay.Replayer()
    replayer.play()