File tree 3 files changed +43
-2
lines changed
3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change
1
+ def start_counting ():
2
+ for i in range (12 ):
3
+ print (i )
4
+ return i
5
+
6
+ start_counting ()
Original file line number Diff line number Diff line change 7
7
import os
8
8
import app
9
9
import re
10
+ path = os .path .dirname (os .path .abspath (__file__ ))+ '/app.py'
10
11
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' )
11
18
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\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10\n 11\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" )
13
33
def test_for_file_output (capsys ):
14
34
captured = buffer .getvalue ()
15
35
assert captured == "0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10\n 11\n " #add \n because the console jumps the line on every print
Original file line number Diff line number Diff line change 7
7
import app
8
8
import os
9
9
import re
10
+ path = os .path .dirname (os .path .abspath (__file__ ))+ '/app.py'
11
+
10
12
11
13
@pytest .mark .it ("1. Don't change or remove the existing code" )
12
14
def test_forExistingCode (capsys ):
@@ -19,9 +21,22 @@ def test_forExistingCode(capsys):
19
21
my_codeCall = [s for s in content [3 :] if "fizz_buzz()" in s ]
20
22
my_codeCallVar = content .index (my_codeCall [0 ])
21
23
regexCall = r"fizz_buzz\(\)"
22
-
23
24
assert re .match (regex , content [my_codeVar ])
24
25
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
25
40
26
41
@pytest .mark .it ('2. Your function needs to print the correct output' )
27
42
def test_for_function_output (capsys ):
You can’t perform that action at this time.
0 commit comments