File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
📝 Instructions:
44

55
**Statement**
6-
Write a program that takes three numbers and prints their sum. Every number is given on a separate line.
6+
Taking 3 numbers from the input, print their sum. Every number is given on a separate line.
77

88
**Example input**
99
- 2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
first_number = input("First input")
33
second_number = input("Second input")
44
third_number = input("Third input")
5-
6-
# Invoke the function with any three numbers
5+
# print here the sum of three inputs
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
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'
33

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
410

511
@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):
1013

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"
1319

14-
_stdin = json.loads(stdin)
15-
sumatory = int(_stdin[0]) + int(_stdin[1]) + int(_stdin[2])
1620

17-
assert buffer.getvalue() == str(sumatory)+"\n"
1821

1922

0 commit comments

Comments
 (0)