Skip to content

Commit b7e0b37

Browse files
committed
problem in 05-User-Inputed-Values
1 parent 84a6340 commit b7e0b37

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

exercises/01-Console/test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import re
66
import os
77
import pytest
8+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
89

910
@pytest.mark.it('Use the function print()')
1011
def test_for_file_output(capsys):
11-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
12+
1213
with open(path, 'r') as content_file:
1314
content = content_file.read()
1415
pattern = r"print\s*\("

exercises/02-Declare-Variables/test.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
import pytest
77
import os
88
import re
9+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
910

1011
@pytest.mark.it('Use the function print()')
1112
def test_for_print():
12-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
13+
1314
with open(path, 'r') as content_file:
1415
content = content_file.read()
1516
regex = re.compile(r"print\s*\(['\"]?.+['\"]?\)")
1617
assert bool(regex.search(content)) == True
1718

1819
@pytest.mark.it('Declare a variable and assign it the value "Yellow"')
1920
def test_for_variable():
20-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
21+
2122
with open(path, 'r') as content_file:
2223
content = content_file.read()
2324
regex = re.compile(r"\w*(\s*)=(\s*)\"Yellow\"")
2425
assert bool(regex.search(content)) == True
2526

26-
@pytest.mark.it('Print "Yellow" on the console')
27+
@pytest.mark.it('Print the variable on the console')
2728
def test_for_file_output(capsys):
2829
captured = buffer.getvalue()
2930
assert captured == "Yellow\n" #add \n because the console jumps the line on every print

exercises/03-Print-Variables-In-The-Console/test.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import io
22
import sys
33
sys.stdout = buffer = io.StringIO()
4-
54
# from app import my_function
65
import pytest
76
import app
87
import os
98
import re
9+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1010

1111
@pytest.mark.it("Create a variable named 'color' with the string value red")
1212
def test_declare_variable():
13-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
14-
with open(path, 'r') as content_file:
15-
content = content_file.read()
16-
regex = re.compile(r"color(\s*)=(\s*)[\"']red[\"']")
17-
assert bool(regex.search(content)) == True
13+
result = app.color == "red"
14+
assert result == True
15+
16+
# with open(path, 'r') as content_file:
17+
# content = content_file.read()
18+
# regex = re.compile(r"color(\s*)=(\s*)[\"']red[\"']")
19+
# assert bool(regex.search(content)) == True
1820

1921
@pytest.mark.it('Print on the console the value of the variable ')
2022
def test_for_printing_variable():
21-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
23+
2224
with open(path, 'r') as content_file:
2325
content = content_file.read()
24-
regex = re.compile(r"print(\s*)\(color\)")
26+
regex = re.compile(r"print(\s*)\(\s*color\s*\)")
2527
assert bool(regex.search(content)) == True
2628

2729
@pytest.mark.it('The printed value on the console should be "red"')
+10-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import io
22
import sys
33
sys.stdout = buffer = io.StringIO()
4-
54
# from app import my_function
65
import pytest
76
import os
87
import app
98
import re
9+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1010

1111
@pytest.mark.it('You should create a variable named variables_are_cool')
1212
def test_variable_exists():
@@ -17,15 +17,16 @@ def test_variable_exists():
1717

1818
@pytest.mark.it('Variables_are_cool value should be like 2345 * 7323 ')
1919
def test_use_variable_name():
20-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
21-
with open(path, 'r') as content_file:
22-
content = content_file.read()
23-
regex = re.compile(r"variables_are_cool(\s*)=(\s*)2345(\s*)\*(\s*)7323")
24-
assert bool(regex.search(content)) == True
20+
result = app.variables_are_cool == 17172435
21+
assert result == True
22+
# with open(path, 'r') as content_file:
23+
# content = content_file.read()
24+
# regex = re.compile(r"variables_are_cool(\s*)=(\s*)2345(\s*)\*(\s*)7323")
25+
# assert bool(regex.search(content)) == True
2526

2627
@pytest.mark.it('Print on the console the variables_are_cool value ')
2728
def test_for_file_output(capsys):
28-
29-
from app import variables_are_cool
29+
# from app import variables_are_cool
3030
captured = buffer.getvalue()
31-
assert captured == str(variables_are_cool)+'\n'
31+
# assert captured == str(variables_are_cool)+'\n' # 17172435 -> output
32+
assert captured == '17172435\n'
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
age = int(input('What is your age?\n'))
1+
ages = int(input('What is your age?\n'))
22
# CHANGE THE CODE BELOW TO ADD 10 TO AGE
3-
print("Your age is: "+str(age))
3+
ages = ages + 10
4+
print("Your age is: "+str(ages))

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import pytest,os,re,io,sys, mock, json
1+
import pytest,os,re,io,sys,mock,json
2+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
3+
4+
5+
@pytest.mark.it('Variable "age" should exist')
6+
def test_for_file_output(capsys, app):
7+
result = app.age
8+
assert result == True
9+
210

311
@pytest.mark.it('Use the function print()')
412
def test_for_file_output(capsys):
5-
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
13+
614
with open(path, 'r') as content_file:
715
content = content_file.read()
816
pattern = r"print\s*\("

0 commit comments

Comments
 (0)