|
1 |
| -import pytest, io, sys, json |
2 |
| - |
| 1 | +import pytest, io, sys, json, mock, re, os |
| 2 | +path = os.path.dirname(os.path.abspath(__file__))+'/app.py' |
3 | 3 |
|
| 4 | +@pytest.mark.it("You need to use the print() method") |
| 5 | +def test_use_print(): |
| 6 | +with open(path, 'r') as content_file: |
| 7 | +content = content_file.read() |
| 8 | +regex = re.compile(r"print(\s)*\(") |
| 9 | +assert bool(regex.search(content)) == True |
4 | 10 |
|
5 | 11 | @pytest.mark.it('Sum all three input numbers and print on the console the result')
|
6 |
| -def test_add_variables(mocker, stdin): |
7 |
| - |
8 |
| -_stdin = json.loads(stdin) |
9 |
| -mocker.('builtins.input', lambda x: _stdin.pop(0)) |
| 12 | +def test_add_variables(capsys, app): |
10 | 13 |
|
11 |
| -sys.stdout = buffer = io.StringIO() |
12 |
| -import app |
| 14 | +fake_input = [2,3,4] #fake input |
| 15 | +with mock.('builtins.input', lambda x: fake_input.pop()): |
| 16 | +app() |
| 17 | +captured = capsys.readouterr() |
| 18 | +assert captured.out == "9\n" |
13 | 19 |
|
14 |
| -_stdin = json.loads(stdin) |
15 |
| -sumatory = int(_stdin[0]) + int(_stdin[1]) + int(_stdin[2]) |
16 | 20 |
|
17 |
| -assert buffer.getvalue() == str(sumatory)+"\n" |
18 | 21 |
|
19 | 22 |
|
0 commit comments