-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·52 lines (43 loc) · 2.08 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import io, sys, pytest, os, re, mock
@pytest.mark.it("Create the function 'calculate_area'")
def test_declare_variable():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"def(\s*)calculate_area\(")
assert bool(regex.search(content)) == True
@pytest.mark.it('The function calculate_area must exist')
def test_for_callable(capsys, app):
assert callable(app.calculate_area)
@pytest.mark.it('The function calculate_area must return an integer')
def test_for_integer(capsys, app):
assert isinstance(app.calculate_area(3,4), int)
@pytest.mark.it('We tried the function sum with length=3 and width=4 and it did not return 12')
def test_for_return(capsys, app):
assert app.calculate_area(3,4) == 12
assert app.calculate_area(5,4) == 20
@pytest.mark.it('The variable square_area1 needs to be declared')
def test_for_existence1(capsys, app):
app.square_area1
@pytest.mark.it('The variable square_area2 needs to be declared')
def test_for_existence2(capsys, app):
app.square_area2
@pytest.mark.it('The variable square_area3 needs to be declared')
def test_for_existence3(capsys, app):
app.square_area3
@pytest.mark.it('square_area1 needs to have as value the area of the first square')
def test_for_square_area_value1(capsys, app):
assert app.square_area1 == 16
@pytest.mark.it('square_area2 needs to have as value the area of the second square')
def test_for_square_area_value2(capsys, app):
assert app.square_area2 == 4
@pytest.mark.it('square_area3 needs to have as value the area of the third square')
def test_for_square_area_value3(capsys, app):
assert app.square_area3 == 25
@pytest.mark.it("The function calculate_area must be called 3 times, one for each square")
def test_call_calculate_area():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"=(\s*)calculate_area\s*\(")
assert bool(regex.search(content)) == True