-
Notifications
You must be signed in to change notification settings - Fork 421
/
Copy pathtest.py
67 lines (58 loc) · 2.66 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# from app import my_function
import pytest,os,re,io,sys, mock, json
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
@pytest.mark.it('Use the if statement')
def test_for_print(capsys):
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('Use the elif statement')
def test_for_print(capsys):
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"if\s*")
regex2 = re.compile(r"elif\s*")
assert ((bool(regex.search(content)) == True) and (bool(regex2.search(content))==True))
@pytest.mark.it('Use the function print()')
def test_for_print(capsys):
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"print\s*\(")
assert bool(regex.search(content)) == True
@pytest.mark.it("When input for more than 100 it should print: Give me your money!")
def test_for_output_when_101(stdin, capsys, app):
with mock.patch('builtins.input', lambda x: 101):
app()
captured = capsys.readouterr()
assert "Give me your money!\n" in captured.out
@pytest.mark.it("When input exactly 100 should print: Buy me some coffee, you cheap!")
def test_for_output_when_100(capsys, app):
with mock.patch('builtins.input', lambda x: 100):
app()
captured = capsys.readouterr()
assert "Buy me some coffee, you cheap!\n" in captured.out
@pytest.mark.it("When input is 99 should print: Buy me some coffee, you cheap!")
def test_for_output_when_99(capsys, app):
with mock.patch('builtins.input', lambda x: 99):
app()
captured = capsys.readouterr()
assert "Buy me some coffee, you cheap!\n" in captured.out
@pytest.mark.it("When input is 51 should print: Buy me some coffee, you cheap!")
def test_for_output_when_51(capsys, app):
with mock.patch('builtins.input', lambda x: 51):
app()
captured = capsys.readouterr()
assert "Buy me some coffee, you cheap!\n" in captured.out
@pytest.mark.it("When input exactly 50 should print: You are a poor guy, go away!")
def test_for_output_when_50(capsys, app):
with mock.patch('builtins.input', lambda x: 50):
app()
captured = capsys.readouterr()
assert "You are a poor guy, go away!\n" in captured.out
@pytest.mark.it("When input less than 50 should print: You are a poor guy, go away!")
def test_for_output_when_49(capsys, app):
with mock.patch('builtins.input', lambda x: 49):
app()
captured = capsys.readouterr()
assert "You are a poor guy, go away!\n" in captured.out