示例#1
0
    def setUp(self):
        self._app = wx.PySimpleApp()

        self.cards_image_path = '1'
        self.cards_hidden_image_path = '2'
        self.card_width = 10
        self.card_height = 20
        self.manager = CardImageManager(
            self.cards_image_path,
            self.cards_hidden_image_path,
            self.card_width,
            self.card_height
        )
示例#2
0
class CardImageManagerTest(unittest.TestCase):
    def setUp(self):
        self._app = wx.PySimpleApp()

        self.cards_image_path = '1'
        self.cards_hidden_image_path = '2'
        self.card_width = 10
        self.card_height = 20
        self.manager = CardImageManager(
            self.cards_image_path,
            self.cards_hidden_image_path,
            self.card_width,
            self.card_height
        )

    def test_init(self):
        self.assertEqual(self.manager._image_path, self.cards_image_path)
        self.assertEqual(
            self.manager._hidden_image_path, self.cards_hidden_image_path
        )
        self.assertEqual(self.manager._card_width, self.card_width)
        self.assertEqual(self.manager._card_height, self.card_height)

    def test_prepare_data_prepares_card_images(self):
        all_cards = DurakCard.all()

        with patch('durak.gui.images.wx.Image') as wx_image_mock:
            self.manager._prepare_data()

            wx_image_mock.assert_any_call(
                self.cards_image_path, wx.BITMAP_TYPE_GIF
            )
            wx_image_mock.assert_any_call(
                self.cards_hidden_image_path, wx.BITMAP_TYPE_GIF
            )
            self.assertEqual(
                (wx_image_mock.return_value
                              .ConvertToBitmap
                              .return_value
                              .GetSubBitmap
                              .call_count),
                len(all_cards)
            )
            self.assertItemsEqual(
                self.manager._data.keys(),
                list(all_cards) + [self.manager.HIDDEN]
            )

    def test_get_image(self):
        self.manager._data = {}

        with patch('durak.gui.images.wx.Image') as wx_image_mock:
            result = self.manager.get_image(DurakCard('6H'))
            self.assertTrue(wx_image_mock.called)
            self.assertEqual(result, self.manager._data[DurakCard('6H')])

            wx_image_mock.reset_mock()
            result = self.manager.get_image(DurakCard('6H'))
            self.assertFalse(wx_image_mock.called)
            self.assertEqual(result, self.manager._data[DurakCard('6H')])

    def test_get_hidden_card_image(self):
        self.manager._data = {}

        with patch('durak.gui.images.wx.Image') as wx_image_mock:
            result = self.manager.get_hidden_card_image()
            self.assertTrue(wx_image_mock.called)
            self.assertEqual(result, self.manager._data[self.manager.HIDDEN])

            wx_image_mock.reset_mock()
            result = self.manager.get_hidden_card_image()
            self.assertFalse(wx_image_mock.called)
            self.assertEqual(result, self.manager._data[self.manager.HIDDEN])