Пример #1
0
class DeckPanelTest(unittest.TestCase):
    def setUp(self):
        self._app = wx.PySimpleApp()

        with patch('__builtin__.super'):
            with patch.object(DeckPanel, '_create_widgets'):
                with patch.object(DeckPanel, 'SetSizeHints'):
                    self.panel = DeckPanel(parent=None)

    def test_create_widgets(self):
        with patch('durak.gui.widgets.wx') as wx_patch_mock:
            with patch('durak.gui.widgets.HiddenCard') as HiddenCardMock:
                self.panel._create_widgets()

                wx_patch_mock.StaticBitmap.assert_called_once_with(
                    parent=self.panel, pos=(0, 12)
                )
                HiddenCardMock.assert_called_once_with(
                    parent=self.panel, pos=(50, 0)
                )
                wx_patch_mock.StaticText.assert_called_once_with(
                    parent=self.panel, pos=(70, 100)
                )

                self.assertTrue(self.panel._opened_trump.Hide.called)
                self.assertTrue(self.panel._deck_top.Hide.called)


    def test_set_opened_trump_sets_trump_and_rotates_card(self):
        card = DurakCard('6H')
        self.panel._opened_trump = Mock()

        with patch('durak.gui.widgets.card_image_manager') as img_mng_mock:
            self.panel.set_opened_trump(DurakCard('6H'))
            img_mng_mock.get_image.assert_called_once_with(card)
            img = (
                img_mng_mock.get_image.return_value.ConvertToImage.return_value
            )
            img.Rotate90.assert_called_once_with(clockwise=False)
            self.panel._opened_trump.SetBitmap.assert_called_once_with(
                img.Rotate90.return_value.ConvertToBitmap.return_value
            )

        self.assertEqual(self.panel._trump_card, card)

    def test_set_card_count_sets_count(self):
        self.panel._opened_trump = Mock()
        self.panel._deck_top = Mock()
        self.panel._card_count = Mock()

        self.panel.set_card_count(10)

        self.panel._deck_top.Show.assert_called_once_with(True)
        self.panel._opened_trump.Show.assert_called_once_with(True)
        self.panel._card_count.SetLabel.assert_called_once_with('10')

    def test_set_card_count_hides_deck_if_lt_1(self):
        self.panel._opened_trump = Mock()
        self.panel._deck_top = Mock()
        self.panel._card_count = Mock()

        self.panel.set_card_count(1)

        self.panel._deck_top.Show.assert_called_once_with(False)
        self.panel._opened_trump.Show.assert_called_once_with(True)
        self.panel._card_count.SetLabel.assert_called_once_with('1')

    def test_set_card_count_hides_trump_if_0(self):
        self.panel._opened_trump = Mock()
        self.panel._deck_top = Mock()
        self.panel._card_count = Mock()
        self.panel._trump_card = DurakCard('6H')

        self.panel.set_card_count(0)

        self.panel._deck_top.Show.assert_called_once_with(False)
        self.panel._opened_trump.Show.assert_called_once_with(False)
        self.panel._card_count.SetLabel.assert_called_once_with(u'Козырь - 6H')