-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
50 lines (44 loc) · 1.77 KB
/
Copy pathtest.py
File metadata and controls
50 lines (44 loc) · 1.77 KB
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
import io
import sys
sys.stdout = buffer = io.StringIO()
# from app import my_function
import pytest
import os
import re
import app
@pytest.mark.it("You should be printing the get_randomInt function")
def test_only_change_line_5():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
content = content_file.read()
line = r"print\s*\(\s*get_randomInt\s*\(\s*\)\s*\)"
regex = re.compile(line)
assert bool(regex.search(content)) == True
@pytest.mark.it("get_randomInt function should exist")
def test_function_exists():
try:
assert app.get_randomInt()
except AttributeError:
raise AttributeError('The function "get_randomInt" should exist')
@pytest.mark.it("get_randomInt function should return a random integer between 1 and 10")
def test_function_returns_random_integer():
try:
for i in range(10):
# only asserting if value is outside the range, else it will pass
result = app.get_randomInt()
assert result >= 1 and result <= 10
except AttributeError:
raise AttributeError('The function "get_randomInt" is returning values outside the specified range')
@pytest.mark.it("get_randomInt function should NOT be returning a static integer value")
# in case user returns single value between [1 and 10]
def test_function_return_no_static():
try:
tries = 0
output = app.get_randomInt()
for i in range(10):
if output == app.get_randomInt():
tries+=1
# only asserting if value is outside the range, else it will pass
assert tries < 10
except AttributeError:
raise AttributeError('The function "get_randomInt" is returning a static value, not a random one')