Skip to content

Commit f01d537

Browse files
committed
fixed some exercises
1 parent 3f7d51c commit f01d537

File tree

11 files changed

+41
-61
lines changed

11 files changed

+41
-61
lines changed

exercises/01-Console/test.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ def test_for_file_output(capsys):
1111
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1212
with open(path, 'r') as content_file:
1313
content = content_file.read()
14-
regex = r"print\("
15-
assert re.match(regex, content) != None
14+
pattern = r"print\("
15+
regex = re.compile(pattern)
16+
assert bool(regex.search(content)) == True
1617

1718
@pytest.mark.it('Print Hello World! on the console')
1819
def test_for_console_log(capsys):

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_declare_variable():
1313
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1414
with open(path, 'r') as content_file:
1515
content = content_file.read()
16-
regex = re.compile(r"color(\s*)=(\s*)\"red\"")
16+
regex = re.compile(r"color(\s*)=(\s*)[\"']red[\"']")
1717
assert bool(regex.search(content)) == True
1818

1919
@pytest.mark.it('Print on the console the value of the variable ')
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest,os,re,io,sys, mock, json
22

3-
@pytest.mark.it("Print on the console the input value + 10")
3+
@pytest.mark.it("We tried with age 50 and it was supposed to return 60")
44
def test_t(stdin):
5-
_input = [40,30,20]
6-
with mock.patch('builtins.input', lambda x: _input.pop()):
5+
with mock.patch('builtins.input', lambda x: 50):
76
# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
87
sys.stdout = buffer = io.StringIO()
98
import app
109
captured = buffer.getvalue()
11-
assert captured == "Your age is: 50\n"
10+
assert captured == "Your age is: 60\n"

exercises/09-Creating-Your-First-Function/test.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@ def test_call_sample2():
3333

3434
@pytest.mark.it("Add the return statement inside the existing function")
3535
def test_use_my_var1():
36-
37-
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
38-
content = f.readlines()
39-
content = [x.strip() for x in content]
40-
my_return = [s for s in content if "return" in s]
41-
my_returnIndex = content.index(my_return[0])
42-
# print(my_print_index)
43-
regex = r"return\s+.+"
44-
assert re.match(regex, content[my_returnIndex])
36+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
37+
with open(path, 'r') as content_file:
38+
content = content_file.read()
39+
pattern = r"return\s+.+"
40+
regex = re.compile(pattern)
41+
assert bool(regex.search(content)) == True
4542

4643
# assert re.match(regex, content)
4744
@pytest.mark.it('Console should output 7')

exercises/13-Random-Numbers/test.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
@pytest.mark.it("You should update only line 5 using randint()")
1111
def test_conditional():
12-
f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py')
13-
content = f.readlines()
14-
content = [x.strip() for x in content]
15-
my_print = [s for s in content if "random_number =" in s]
16-
my_printVar = content.index(my_print[0])
17-
regex = r"random_number(\s*)=(\s*)random\.rand\w+\(1,10\)"
18-
assert re.match(regex, content[my_printVar])
12+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
13+
with open(path, 'r') as content_file:
14+
content = content_file.read()
15+
pattern = r"random_number(\s*)=(\s*)random\.rand\w+\(1,10\)"
16+
regex = re.compile(pattern)
17+
assert bool(regex.search(content)) == True
1918

exercises/14-Rand-From-One-to-Six/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import random
22

33
def get_randomInt():
4-
random_number = random.randint(1,10)
4+
random_number = random.randrange(1,13)
55
return random_number
66

77

exercises/14-Rand-From-One-to-Six/test.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
@pytest.mark.it("You should return a random number between 1 and 12 included")
1212
def test_conditional():
13-
f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py')
14-
content = f.readlines()
15-
content = [x.strip() for x in content]
16-
my_print = [s for s in content if "random_number =" in s]
17-
my_printVar = content.index(my_print[0])
18-
regex = r"random_number(\s*)=(\s*)random\.randrange+\(1,13\)"
19-
assert re.match(regex, content[my_printVar])
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+
pattern = r"random_number(\s*)=(\s*)random\.randrange+\(1,13\)"
17+
regex = re.compile(pattern)
18+
assert bool(regex.search(content)) == True

exercises/16-Create-A-For-Loop/app.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
def standards_maker():
2-
for x in range(300):
3-
print("I will write questions if I am stuck")
4-
pass
2+
#your code here
53

6-
standards_maker()
4+
#remember to call the function outside (here)

exercises/16-Create-A-For-Loop/test.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ def test_for_print():
3131

3232
@pytest.mark.it("You should call the function standards_maker ")
3333
def test_callTheFunction():
34-
f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py')
35-
content = f.readlines()
36-
content = [x.strip() for x in content]
37-
my_call = [s for s in content[2:] if "standards_maker()" in s]
38-
my_callVar = content.index(my_call[0])
39-
print("###",my_callVar)
40-
regex_call = r"standards_maker\(\)"
41-
42-
43-
assert re.match(regex_call, content[my_callVar])
34+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
35+
with open(path, 'r') as content_file:
36+
content = content_file.read()
37+
pattern = r"standards_maker\(\)"
38+
regex = re.compile(pattern)
39+
assert bool(regex.search(content)) == True

exercises/18-Random-Colors-Loop/test.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,9 @@
1010

1111
@pytest.mark.it('Print the correct output on the console')
1212
def test_for_file_output(capsys):
13-
captured = buffer.getvalue()
14-
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
15-
content = f.readlines()
16-
content = [x.strip() for x in content]
17-
regex = r"print\(get_allStudentColors\(\)\)"
18-
assert re.match(regex, content[(len(content)-1)])
19-
20-
# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console')
21-
# def test_for_function_output(capsys):
22-
# my_function()
23-
# captured = capsys.readouterr()
24-
# assert captured.out == "Hello Inside Function\n"
25-
26-
# @pytest.mark.it('Your function needs to return True')
27-
# def test_for_function_return(capsys):
28-
# assert my_function() == True
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+
pattern = r"print\(get_allStudentColors\(\)\)"
17+
regex = re.compile(pattern)
18+
assert bool(regex.search(content)) == True

exercises/19-Looping-With-FizzBuzz/test.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_forExistingCode(capsys):
2222

2323
assert re.match(regex, content[my_codeVar])
2424
assert re.match(regexCall, content[my_codeCallVar])
25+
2526
@pytest.mark.it('2. Your function needs to print the correct output')
2627
def test_for_function_output(capsys):
2728
fizz_buzz()

0 commit comments

Comments
 (0)