|
1 | 1 | # coding=utf-8
|
2 | 2 |
|
3 |
| -from rummy.deck.card import Card |
4 |
| -from rummy.game.melds import Melds |
5 |
| -from rummy.player.hand import Hand |
6 |
| -from rummy.player.human import Human |
7 |
| -from rummy.ui.user_input import UserInput |
8 |
| - |
9 | 3 |
|
10 | 4 | class TestHuman:
|
11 |
| - |
12 |
| - def test_draw_from_deck_or_discard_pile(self, mocker): |
13 |
| - mocker.patch.object(Human, '_choose_pick_up') |
14 |
| - mocker.patch.object(Human, 'take_from_deck') |
15 |
| - human = Human(1) |
16 |
| - human.round = mocker.MagicMock() |
17 |
| - human.round.deck.has_discard.return_value = False |
18 |
| - human.draw_card() |
19 |
| - assert human._choose_pick_up.call_count == 0 |
20 |
| - assert human.take_from_deck.call_count == 1 |
21 |
| - human.round.deck.has_discard.return_value = True |
22 |
| - human.draw_card() |
23 |
| - assert human._choose_pick_up.call_count == 1 |
24 |
| - assert human.take_from_deck.call_count == 1 |
25 |
| - |
26 |
| - def test__choose_pick_up(self, mocker): |
27 |
| - # TODO: Rewrite this test for new action separation |
28 |
| - human = Human(1) |
29 |
| - mocker.patch.object(UserInput, 'create_input', side_effect=['p', 'd']) |
30 |
| - human.round = mocker.MagicMock() |
31 |
| - mocker.patch.object(human.round.deck, 'take_card', return_value=Card("A", "♥")) |
32 |
| - mocker.patch.object(human.round.deck, 'take_discard', return_value=Card("2", "♥")) |
33 |
| - mocker.spy(Hand, 'draw_card') |
34 |
| - # player_choice = 'p' |
35 |
| - human._choose_pick_up() |
36 |
| - # player_choice = 'd' |
37 |
| - human._choose_pick_up() |
38 |
| - assert Hand.draw_card.call_count == 2 |
39 |
| - assert human.round.deck.take_card.call_count == 1 |
40 |
| - assert human.round.deck.take_discard.call_count == 1 |
41 |
| - |
42 |
| - def test_discard_or_knock(self, mocker): |
43 |
| - # TODO: Rewrite this test for new action separation |
44 |
| - mocker.patch('builtins.print') |
45 |
| - mocker.patch('builtins.input', side_effect=['k', '1', '3', '5', '3', '4']) |
46 |
| - mocker.patch.object(Melds, 'find_discard_scores', side_effect=[[9, 12], [9, 12], [9, 12], [11, 12], [11, 12]]) |
47 |
| - mocker.patch.object(Hand, 'discard_card', return_value=Card("A", "♥")) |
48 |
| - mocker.spy(Hand, 'discard_card') |
49 |
| - human = Human(1) |
50 |
| - human.round = mocker.MagicMock() |
51 |
| - # valid score, not knocked; chooses to knock |
52 |
| - # scores = [9, 12], knocked = False, player_choice = 'k' -> '1' |
53 |
| - human.round.show_knocked = False |
54 |
| - human.discard_or_knock() |
55 |
| - assert human.round.show_knocked |
56 |
| - assert Hand.discard_card.call_count == 1 |
57 |
| - |
58 |
| - # valid score, not knocked |
59 |
| - # scores = [9, 12], knocked = False, player_choice = '3' |
60 |
| - human.round.show_knocked = False |
61 |
| - human.discard_or_knock() |
62 |
| - assert not human.round.show_knocked |
63 |
| - assert Hand.discard_card.call_count == 2 |
64 |
| - |
65 |
| - # valid score, knocked |
66 |
| - # scores = [9, 12], knocked = True, player_choice = '5' |
67 |
| - human.round.show_knocked = True |
68 |
| - human.discard_or_knock() |
69 |
| - assert human.round.show_knocked |
70 |
| - assert Hand.discard_card.call_count == 3 |
71 |
| - |
72 |
| - # invalid score, not knocked |
73 |
| - # scores = [11, 12], knocked = False, player_choice = '3' |
74 |
| - human.round.show_knocked = False |
75 |
| - human.discard_or_knock() |
76 |
| - assert not human.round.show_knocked |
77 |
| - assert Hand.discard_card.call_count == 4 |
78 |
| - |
79 |
| - # invalid score, knocked |
80 |
| - # scores = [11, 12], knocked = True, player_choice = '4' |
81 |
| - human.round.show_knocked = True |
82 |
| - human.discard_or_knock() |
83 |
| - assert human.round.show_knocked |
84 |
| - assert Hand.discard_card.call_count == 5 |
| 5 | + pass |
0 commit comments