Skip to content

Commit dbc1db9

Browse files
committed
16-Random-Colors-Loop
1 parent 291bf7f commit dbc1db9

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def start_counting():
2+
for i in range(12):
3+
print(i)
4+
return i
5+
6+
start_counting()

exercises/14-Your-First-Loop/test.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,29 @@
77
import os
88
import app
99
import re
10+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1011

12+
@pytest.mark.it('The function start_counting should exist')
13+
def test_for_function_existence():
14+
try:
15+
app.start_counting
16+
except AttributeError:
17+
raise AttributeError('The function start_counting should exist')
1118

12-
@pytest.mark.it("1. You should return a list of number between 0 and 100")
19+
@pytest.mark.it('The function start_counting should return the expected output')
20+
def test_for_function_output(capsys):
21+
app.start_counting()
22+
captured = capsys.readouterr()
23+
assert "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n" == captured.out
24+
25+
@pytest.mark.it('Use for loop')
26+
def test_for_loop():
27+
with open(path, 'r') as content_file:
28+
content = content_file.read()
29+
regex = re.compile(r"for\s*")
30+
assert bool(regex.search(content)) == True
31+
32+
@pytest.mark.it("1. You should return a list of number between 0 and 11")
1333
def test_for_file_output(capsys):
1434
captured = buffer.getvalue()
1535
assert captured == "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n" #add \n because the console jumps the line on every print

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import app
88
import os
99
import re
10+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
11+
1012

1113
@pytest.mark.it("1. Don't change or remove the existing code")
1214
def test_forExistingCode(capsys):
@@ -19,9 +21,22 @@ def test_forExistingCode(capsys):
1921
my_codeCall = [s for s in content[3:] if "fizz_buzz()" in s]
2022
my_codeCallVar = content.index(my_codeCall[0])
2123
regexCall = r"fizz_buzz\(\)"
22-
2324
assert re.match(regex, content[my_codeVar])
2425
assert re.match(regexCall, content[my_codeCallVar])
26+
27+
@pytest.mark.it('The function fizz_buzz should exist')
28+
def test_function_existence():
29+
try:
30+
app.fizz_buzz
31+
except AttributeError:
32+
raise AttributeError('The function fizz_buzz should exist')
33+
34+
@pytest.mark.it('Use for loop')
35+
def test_for_loop():
36+
with open(path, 'r') as content_file:
37+
content = content_file.read()
38+
regex = re.compile(r"for\s*")
39+
assert bool(regex.search(content)) == True
2540

2641
@pytest.mark.it('2. Your function needs to print the correct output')
2742
def test_for_function_output(capsys):

0 commit comments

Comments
 (0)