1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- # -*- coding: utf-8 -*-
- import mock
- import os
- import pygame
- from pie_time import application as app_module
- from pie_time.application import PieTime
- from pie_time.card import AbstractCard
- class Test_AbstractCard(object):
- def _dummy_card(self, **settings):
- app = PieTime(None)
- card = AbstractCard()
- card.set_app(app)
- card.set_settings(settings)
- return card
- def test_init(self):
- card = AbstractCard()
- assert card._app is None
- assert card._settings == {}
- assert card._surface is None
- def test_set_app(self):
- card = AbstractCard()
- app = mock.Mock(spec=PieTime)
- card.set_app(app)
- assert card._app == app
- def test_set_settings(self):
- card = AbstractCard()
- settings = {'spam': 'eggs'}
- card.set_settings(settings)
- assert card._settings == settings
- def test_width(self):
- card = self._dummy_card()
- assert card.width == card._app.screen_size[0]
- def test_height(self):
- card = self._dummy_card()
- assert card.height == card._app.screen_size[1]
- def test_surface(self):
- fake_surface = mock.Mock(spec=pygame.surface.Surface)
- with mock.patch.object(app_module.pygame.surface, 'Surface',
- return_value=fake_surface):
- card = self._dummy_card()
- assert card.surface == fake_surface
- assert card._surface == card.surface
- app_module.pygame.surface.Surface.assert_called_with((
- card.width, card.height
- ))
- def test_background_color(self):
- card = self._dummy_card()
- assert card.background_color == card._app.BACKGROUND_COLOR
- def test_background_color_override(self):
- card = self._dummy_card(background_color=(255, 255, 255))
- assert card.background_color == (255, 255, 255)
- def test_path_for_resource(self):
- card = self._dummy_card()
- spam_path = card.path_for_resource('spam')
- assert os.path.isabs(spam_path)
- assert card.RESOURCE_FOLDER in spam_path
- assert spam_path.endswith('spam')
- spam_eggs_path = card.path_for_resource('spam', folder='eggs')
- assert os.path.isabs(spam_eggs_path)
- assert card.RESOURCE_FOLDER in spam_eggs_path
- assert 'eggs' in spam_eggs_path
- assert spam_eggs_path.endswith('spam')
- def test_tick(self):
- try:
- card = self._dummy_card()
- card.tick()
- except Exception as exc:
- assert isinstance(exc, RuntimeError)
- assert exc.args[0] == 'TODO'
- else:
- assert False, 'Nothing was raised :('
|