-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_game.py
56 lines (47 loc) · 1.7 KB
/
test_game.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
import unittest
from unittest.mock import patch
from game import Game
import threading
class Test(unittest.TestCase):
# Test if number is drawed when the user presses a key.
# Test if number is inside the numbers list
def test_number_in_range(self):
a = 4
b = Game.numbers_list
self.assertIn(a, b)
# Test if number is outside of the numbers range (1 - 75)
def test_number_not_in_range(self):
a = 76
b = Game.numbers_list
self.assertNotIn(a, b)
# Test if numbers list range is a string
def test_number_not_string(self):
a = '1'
b = Game.numbers_list[0]
self.assertIsNot(a, b)
# Test if numbers list range is a string
def test_number_is_int(self):
a = 1
b = Game.numbers_list[0]
self.assertIs(a, b)
# Test if game Function is called if input is equal to "B"
@patch('builtins.input')
def test_bingo_call(self, input_mock):
input_mock.side_effect=['B','S']
with patch.object(Game, "bingo_call") as mock:
game_thread = threading.Thread(target=self._game_thread)
game_thread.start()
mock.assert_called_once()
# Test if game is closed when the input is equal to "S"
@patch('builtins.input')
def test_exit(self, input_mock):
input_mock.side_effect=['S']
with patch.object(Game, "bingo_call") as mock:
game_thread = threading.Thread(target=self._game_thread)
game_thread.start()
mock.assert_not_called()
# Creates thread as workaround the While(True) loop
def _game_thread(self):
Game.start()
if __name__ == "__main__":
unittest.main()