-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_blackjack.py
More file actions
44 lines (35 loc) · 1.67 KB
/
test_blackjack.py
File metadata and controls
44 lines (35 loc) · 1.67 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
import io
from unittest import TestCase, mock
import blackjack
class TestBlackjack(TestCase):
def setUp(self):
self.player = blackjack.Player()
@mock.patch('builtins.input', return_value='x')
def test_player_bet_quit(self, mock_input):
actual = blackjack.player_bet(self.player)
self.assertEqual(-1, actual)
@mock.patch('builtins.input', return_value='50')
def test_player_bet_valid(self, mock_input):
actual = blackjack.player_bet(self.player)
self.assertEqual(50, actual)
@mock.patch('sys.stdout', new_callable=io.StringIO)
@mock.patch('builtins.input', create=True)
def test_player_invalid_entry(self, mock_input, mock_stdout):
mock_input.side_effect = ['c', 'x']
actual = blackjack.player_bet(self.player)
self.assertEqual('c is not a valid entry\n', mock_stdout.getvalue())
self.assertEqual(-1, actual)
@mock.patch('sys.stdout', new_callable=io.StringIO)
@mock.patch('builtins.input', create=True)
def test_player_zero_entry(self, mock_input, mock_stdout):
mock_input.side_effect = ['0', 'x']
actual = blackjack.player_bet(self.player)
self.assertEqual('Bets must be greater than 0\n', mock_stdout.getvalue())
self.assertEqual(-1, actual)
@mock.patch('sys.stdout', new_callable=io.StringIO)
@mock.patch('builtins.input', create=True)
def test_player_over_limit_entry(self, mock_input, mock_stdout):
mock_input.side_effect = ['100000', 'x']
actual = blackjack.player_bet(self.player)
self.assertEqual('You do not have enough to cover that bet\n', mock_stdout.getvalue())
self.assertEqual(-1, actual)