Skip to content

Commit 1e6d548

Browse files
committed
doing 08-Your-First-If
1 parent b7e0b37 commit 1e6d548

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ages = int(input('What is your age?\n'))
1+
age = int(input('What is your age?\n'))
22
# CHANGE THE CODE BELOW TO ADD 10 TO AGE
3-
ages = ages + 10
4-
print("Your age is: "+str(ages))
3+
4+
print("Your age is: "+str(age))

exercises/05-User-Inputed-Values/test.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

44

5-
@pytest.mark.it('Variable "age" should exist')
6-
def test_for_file_output(capsys, app):
7-
result = app.age
8-
assert result == True
5+
@pytest.mark.it('The variable age should exist')
6+
def test_variable_exists(capsys):
7+
import app
8+
try:
9+
app.age
10+
except AttributeError:
11+
raise AttributeError("The variable age should exist")
12+
913

1014

1115
@pytest.mark.it('Use the function print()')
1216
def test_for_file_output(capsys):
13-
1417
with open(path, 'r') as content_file:
1518
content = content_file.read()
16-
pattern = r"print\s*\("
19+
pattern = (r"print\s*\(")
1720
regex = re.compile(pattern)
1821
assert bool(regex.search(content)) == True
1922

23+
2024
@pytest.mark.it("We tried with age 50 and it was supposed to return 60")
2125
@mock.patch('builtins.input', lambda x: 50)
2226
def test_plus_ten(stdin):
23-
# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
24-
sys.stdout = buffer = io.StringIO()
25-
import app
26-
captured = buffer.getvalue()
27-
assert captured == "Your age is: 60\n"
27+
# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
28+
sys.stdout = buffer = io.StringIO()
29+
import app
30+
captured = buffer.getvalue()
31+
assert captured == "Your age is: 60\n"

0 commit comments

Comments
 (0)