def test_validate_guess(capfd): game = Game() game._answer = 2 assert not game._validate_guess(1) out, _ = capfd.readouterr() assert out.rstrip() == '1 is too low' assert not game._validate_guess(3) out, _ = capfd.readouterr() assert out.rstrip() == '3 is too high' assert game._validate_guess(2) out, _ = capfd.readouterr() assert out.rstrip() == '2 is correct!'
def test_game_win(inp, capfd): game = Game() game._answer = 6 game() assert game._win is True out = capfd.readouterr()[0] expected = [ '4 is too low', 'Number not in range', '9 is too high', 'Already guessed', '6 is correct!', 'It took you 3 guesses' ] output = [line.strip() for line in out.split('\n') if line.strip()] for line, exp in zip(output, expected): assert line == exp
def test_game_lose(inp, capfd): game = Game() game._answer = 13 game() assert game._win is False