예제 #1
0
def test_validate_guess(capfd):
    game = Game()
    game._answer = 2

    # use capfd to look at and test the stdout
    assert not game._validate_guess(1)
    out, error = capfd.readouterr()
    assert out.rstrip() == '1 is too low'

    assert not game._validate_guess(3)
    assert game._validate_guess(2)
예제 #2
0
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!'
예제 #3
0
def test_validate_guess(capfd):  # captures std output of program in execution
    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_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!'
예제 #5
0
def test_validate_guess(capfd):
    game = Game()
    game._answer = 2

    assert not game._validate_guess(1)
    out, _ = capfd.readouterr()
    # print(out)  # run with pytest -s test_guess.py --> its not capturing the output but it prints it to the console // this can be run only once per assertion if run on multiple assertions it will fail the test
    assert out.rstrip(
    ) == '1 is too low'  # run without -s to just check the percentage for passing

    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!'
예제 #6
0
def test_validate_guess(capfd):
    """pytest capture stdout:
       https://docs.pytest.org/en/2.9.1/capture.html"""
    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!'
예제 #7
0
def test_validate_guess(capfd):
    #capfd captures the standard output to test what is being printed
    game = Game()
    game._answer = 2

    # If we guess a 1 when the answer is 2, make sure that validate_guess
    # is returning False
    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!'
예제 #8
0
def test_validate_guess(capfd):
    game = Game()
    game._answer = 2

    # Test incorrect values
    # Too low
    assert not game._validate_guess(1)
    out, _ = capfd.readouterr()
    assert out.strip() == '1 is too low'
    # Too low
    assert not game._validate_guess(3)
    out, _ = capfd.readouterr()
    assert out.strip() == '3 is too high'

    # Test correct values
    assert game._validate_guess(2)
    out, _ = capfd.readouterr()
    assert out.strip() == '2 is correct!'