-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_project.py
More file actions
112 lines (93 loc) · 3.16 KB
/
test_project.py
File metadata and controls
112 lines (93 loc) · 3.16 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from project import get_level, get_word, guessing, graphics
import pytest
def test_get_level(monkeypatch):
# the monkey patch overrides the builtin input function which allows to test it.
monkeypatch.setattr("builtins.input", lambda _: "1")
result = get_level()
assert result == "1"
monkeypatch.setattr("builtins.input", lambda _: "2")
result = get_level()
assert result == "2"
monkeypatch.setattr("builtins.input", lambda _: "3")
result = get_level()
assert result == "3"
# inputs is a list of wrong inputs where the function should repromt the user ending in a right input, only if
# after each wrong input the function reprompts the last(right) input is reached and the test evaluates to True
inputs = iter(
["a", "one", "yes", "?", ",.", "Michelle", "[]", "()", 4, 126384, "1"]
)
monkeypatch.setattr("builtins.input", lambda _: next(inputs))
result = get_level()
assert result == "1"
def test_get_word():
# results saves the random word and the number of tries and is idexable
# since the word is random i only check if it's a str of the wanted lenght
result = get_word("1")
assert isinstance(result[0], str)
assert len(result[0]) > 3 and len(result[0]) < 6
assert result[1] == 10
result = get_word("2")
assert isinstance(result[0], str)
assert len(result[0]) > 5 and len(result[0]) < 9
assert result[1] == 12
result = get_word("3")
assert isinstance(result[0], str)
assert len(result[0]) > 8 and len(result[0]) < 13
assert result[1] == 15
with pytest.raises(UnboundLocalError):
get_word(2)
with pytest.raises(UnboundLocalError):
get_word(24554)
with pytest.raises(UnboundLocalError):
get_word("lala")
def test_guessing(monkeypatch):
monkeypatch.setattr("builtins.input", lambda _: "banana")
with pytest.raises(SystemExit) as text:
guessing("banana", 1, 10)
assert text.value.code == "banana is right!!\n🎉🎉🎉 !!You Won!! 🥳 🎉🎉🎉"
inputs = iter(["b", "n", "a"])
monkeypatch.setattr("builtins.input", lambda _: next(inputs))
with pytest.raises(SystemExit) as text:
guessing("banana", 1, 10)
assert text.value.code == "banana is right!!\n🎉🎉🎉 !!You Won!! 🥳 🎉🎉🎉"
def test_graphics():
assert (
graphics(1, "1")
== """
____|_____"""
)
assert (
graphics(1, "2")
== """
____|_____"""
)
assert (
graphics(1, "3")
== """
____|_____"""
)
assert (
graphics(10, "1")
and graphics(12, "2")
and graphics(15, "3")
== """
________
| |
| 0
| /|\\
| |
| / \\
____|_____ """
)
assert graphics(12, "1") == None
assert graphics(14, "2") == None
assert graphics(16, "3") == None
assert graphics(16, 3) == None
assert graphics("Lala", "LULU") == None
assert graphics(16, "5") == None
with pytest.raises(TypeError):
graphics(12)
with pytest.raises(TypeError):
graphics()
with pytest.raises(TypeError):
graphics(12, 5, 13)