-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_menu.py
53 lines (45 loc) · 1.64 KB
/
test_menu.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
import unittest
from unittest.mock import patch
from menu import Menu
import sys
class Test(unittest.TestCase):
# @patch('builtins.input', lambda *args: '1')
# def test_start(self):
# self.assertEqual(Menu.start(), True)
# ------ Tests for option 1 -------
# Test if game Starts if input is equal to "1"
@patch('game.Game.start')
@patch('builtins.input', lambda *args: '1')
def test_game_called(self, mock):
Menu.start()
self.assertTrue(mock.called)
# ------ Tests for option 2 -------
# Test if Bingo Card is generated if input is equal to "2"
@patch('menu.Menu.new_card')
@patch('builtins.input', lambda *args: '2')
def test_card_called(self, mock):
Menu.start()
self.assertTrue(mock.called)
# ------ Tests for option 3 -------
# Test if game is closed if input is equal to "3"
@patch('builtins.input', lambda *args: '3')
def test_sys_exit(self):
with self.assertRaises(SystemExit) as cm:
Menu.start()
self.assertEqual(cm.exception.code, 0)
# ------ Tests for invalid Input -------
# Test if menu restarts if the input is invalid
@patch('menu.Menu.start')
@patch('builtins.input', lambda *args: 'g')
def test_game_invalid(self, mock):
Menu.start()
self.assertTrue(mock.called)
# ------ Tests for Generate Bingo Card -------
# Test if the changes to Main Menu if input is equal to 'N'
@patch('menu.Menu.start')
@patch('builtins.input', lambda *args: 'N')
def test_new_card_deny(self, mock):
Menu.new_card()
self.assertTrue(mock.called)
if __name__ == "__main__":
unittest.main()