-
Notifications
You must be signed in to change notification settings - Fork 509
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (27 loc) · 1.11 KB
/
test.py
File metadata and controls
31 lines (27 loc) · 1.11 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
import io
import sys
sys.stdout = buffer = io.StringIO()
# from app import my_function
import pytest
import app
import re
import os
@pytest.mark.it("You should declare a function named sing()")
def test_function_sing_exists(app):
try:
assert app.sing
except AttributeError:
raise AttributeError("The function 'sing' should exist on app.py")
@pytest.mark.it("You should not be hard coding the output")
def test_function_hardcode_output():
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"\breturn\s*[^\"][a-zA-Z0-9]*\b\s*")
assert bool(regex.search(content)) == True
@pytest.mark.it("The function sing() should return a string with the song lyrics")
def test_function_sing_exists(app):
try:
assert app.sing() == " nlet it be,\nlet it be,\nthere will be an answer,\nlet it be,\nlet it be,\nlet it be,\nlet it be,\nlet it be,\nwhisper words of wisdom, let it be"
except AttributeError:
raise AttributeError("The function 'sing' should exist on app.py")