-
Notifications
You must be signed in to change notification settings - Fork 509
Expand file tree
/
Copy pathtest.py
More file actions
41 lines (36 loc) · 1.6 KB
/
test.py
File metadata and controls
41 lines (36 loc) · 1.6 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
import io
import sys
sys.stdout = buffer = io.StringIO()
# from app import my_function
import pytest
import os
import app
import re
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
@pytest.mark.it('You should create a variable named variables_are_cool')
def test_variable_exists():
try:
from app import variables_are_cool
except ImportError:
raise ImportError("The variable 'variables_are_cool' should exist on app.py")
@pytest.mark.it('The value of variables_are_cool should be 2345 * 7323')
def test_use_variable_name():
result = app.variables_are_cool == 17172435
assert result == True
@pytest.mark.it('Print on the console the value of variables_are_cool')
def test_for_file_output(capsys):
captured = buffer.getvalue()
assert '17172435\n' in captured
@pytest.mark.it('Print on the console the variables_are_cool variable')
def test_prints_variable():
with open(path, 'r') as content_file:
content = content_file.read()
# makes sure we are calling print function with a variable and not the hard coded value
regex = re.compile(r"print\s*\(\s*variables_are_cool\s*\)")
assert bool(regex.search(content)) == True, "Expected print statement to use the variable 'variables_are_cool'"
@pytest.mark.it('You should not hardcode the result')
def test_does_not_hardcode_result():
with open(path, 'r') as content_file:
content = content_file.read()
# makes sure we are calling print function with a variable and not the hard coded value
assert str(17172435) not in content, "Do not hardcode the result directly in print()"