test_abstract_card.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- coding: utf-8 -*-
  2. import mock
  3. import os
  4. import pygame
  5. from pie_time import application as app_module
  6. from pie_time.application import PieTime
  7. from pie_time.card import AbstractCard
  8. class Test_AbstractCard(object):
  9. def _dummy_card(self, **settings):
  10. app = PieTime(None)
  11. card = AbstractCard()
  12. card.set_app(app)
  13. card.set_settings(settings)
  14. return card
  15. def test_init(self):
  16. card = AbstractCard()
  17. assert card._app is None
  18. assert card._settings == {}
  19. assert card._surface is None
  20. def test_set_app(self):
  21. card = AbstractCard()
  22. app = mock.Mock(spec=PieTime)
  23. card.set_app(app)
  24. assert card._app == app
  25. def test_set_settings(self):
  26. card = AbstractCard()
  27. settings = {'spam': 'eggs'}
  28. card.set_settings(settings)
  29. assert card._settings == settings
  30. def test_width(self):
  31. card = self._dummy_card()
  32. assert card.width == card._app.screen_size[0]
  33. def test_height(self):
  34. card = self._dummy_card()
  35. assert card.height == card._app.screen_size[1]
  36. def test_surface(self):
  37. fake_surface = mock.Mock(spec=pygame.surface.Surface)
  38. with mock.patch.object(app_module.pygame.surface, 'Surface',
  39. return_value=fake_surface):
  40. card = self._dummy_card()
  41. assert card.surface == fake_surface
  42. assert card._surface == card.surface
  43. app_module.pygame.surface.Surface.assert_called_with((
  44. card.width, card.height
  45. ))
  46. def test_background_color(self):
  47. card = self._dummy_card()
  48. assert card.background_color == card._app.BACKGROUND_COLOR
  49. def test_background_color_override(self):
  50. card = self._dummy_card(background_color=(255, 255, 255))
  51. assert card.background_color == (255, 255, 255)
  52. def test_path_for_resource(self):
  53. card = self._dummy_card()
  54. spam_path = card.path_for_resource('spam')
  55. assert os.path.isabs(spam_path)
  56. assert card.RESOURCE_FOLDER in spam_path
  57. assert spam_path.endswith('spam')
  58. spam_eggs_path = card.path_for_resource('spam', folder='eggs')
  59. assert os.path.isabs(spam_eggs_path)
  60. assert card.RESOURCE_FOLDER in spam_eggs_path
  61. assert 'eggs' in spam_eggs_path
  62. assert spam_eggs_path.endswith('spam')
  63. def test_tick(self):
  64. try:
  65. card = self._dummy_card()
  66. card.tick()
  67. except Exception as exc:
  68. assert isinstance(exc, RuntimeError)
  69. assert exc.args[0] == 'TODO'
  70. else:
  71. assert False, 'Nothing was raised :('