- Notifications
You must be signed in to change notification settings - Fork 422
/
Copy pathtest.py
31 lines (27 loc) · 1.13 KB
/
test.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
importio
importsys
sys.stdout=buffer=io.StringIO()
# from app import my_function
importpytest
importapp
importre
importos
@pytest.mark.it("You should declare a function named sing()")
deftest_function_sing_exists(app):
try:
assertapp.sing
exceptAttributeError:
raiseAttributeError("The function 'sing' should exist on app.py")
@pytest.mark.it("You should not be hard coding the output")
deftest_function_hardcode_output():
path=os.path.dirname(os.path.abspath(__file__))+'/app.py'
withopen(path, 'r') ascontent_file:
content=content_file.read()
regex=re.compile(r"\breturn\s*[^\"][a-zA-Z0-9]*\b\s*")
assertbool(regex.search(content)) ==True
@pytest.mark.it("The function sing() should return a string with the song lyrics")
deftest_function_sing_exists(app):
try:
assertapp.sing() =="let it be,\nlet it be,\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"
exceptAttributeError:
raiseAttributeError("The function 'sing' should exist on app.py")