forked from UWPCE-PythonCert/ProgrammingInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mock_input.py
More file actions
37 lines (26 loc) · 829 Bytes
/
Copy pathtest_mock_input.py
File metadata and controls
37 lines (26 loc) · 829 Bytes
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
import pytest
from unittest import mock
def get_color():
color = input("what is your favorite color?")
if color == "red":
return "that's a stupid color"
if color == "blue":
return "Hey! that's mine too!"
else:
raise ValueError("nothing to say about that color")
return color
@mock.patch('builtins.input')
def test_get_color_red(mocked_input):
mocked_input.return_value = "red"
result = get_color()
assert "stupid" in result
@mock.patch('builtins.input')
def test_get_color_blue(mocked_input):
mocked_input.return_value = "blue"
result = get_color()
assert "Hey!" in result
@mock.patch('builtins.input')
def test_get_color_purple(mocked_input):
mocked_input.return_value = "purple"
with pytest.raises(ValueError):
result = get_color()