- Notifications
You must be signed in to change notification settings - Fork 422
/
Copy pathtest.py
33 lines (28 loc) · 1.47 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
32
33
importio, sys, os, re, pytest
sys.stdout=buffer=io.StringIO()
importapp
@pytest.mark.it("Create a variable named html_document")
deftest_html_document_exists():
try:
fromappimporthtml_document
exceptImportError:
raiseImportError("The variable 'html_document' should exist on app.py")
@pytest.mark.it("The value of html_document should be the expected")
deftest_html_document_exists():
try:
fromappimporthtml_document
asserthtml_document=='<html><head><title></title></head><body></body></html>'
exceptImportError:
raiseImportError("The variable 'html_document' should exist on app.py")
@pytest.mark.it('Concatenate all the variables together (in the right order) to set the value of html_document')
deftest_for_concat():
path=os.path.dirname(os.path.abspath(__file__))+'/app.py'
withopen(path, 'r') ascontent_file:
content=content_file.read()
_regex=r"html_document(\s*)=(\s*)e(\s*)\+(\s*)c(\s*)\+(\s*)g(\s*)\+(\s*)a(\s*)\+(\s*)f(\s*)\+(\s*)h(\s*)\+(\s*)d(\s*)\+(\s*)b"
regex=re.compile(_regex)
assertbool(regex.search(content)) ==True
@pytest.mark.it('Print a basic html layout on the console like this: <html><head><title></title></head><body></body></html>')
deftest_for_file_output():
captured=buffer.getvalue()
assert"<html><head><title></title></head><body></body></html>\n"incaptured#add \n because the console jumps the line on every print