-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
38 lines (31 loc) · 1.3 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
34
35
36
37
38
import io, sys, os, pytest, re, app
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
@pytest.mark.it("The variable 'new_list' should exist")
def test_variable_exists():
assert app.new_list != None
@pytest.mark.it("The variable 'new_list' value should contain data-types of 'dict' and 'list'")
def test_variable_value():
assert app.new_list == [[2, 1], {'name': 'juan'}]
@pytest.mark.it("You have to use a for loop")
def test_for_loop():
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"for(\s)")
assert bool(regex.search(content)) == True
@pytest.mark.it("You have to use an if statement")
def test_if():
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"if(\s)")
assert bool(regex.search(content)) == True
@pytest.mark.it("you should use print()")
def test_print():
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"print\(new_list\)")
assert bool(regex.search(content)) == True
@pytest.mark.it("You have to print the value of the variable 'new_list' in the console")
def test_all_data_type(capsys, app):
app()
captured = capsys.readouterr()
assert "[[2, 1], {'name': 'juan'}]\n" in captured.out