test_videogame.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # jogai - Python Game Library
  2. #
  3. # This library is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU Library General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2 of the License, or (at your option) any later version.
  7. #
  8. # This library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Library General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU Library General Public
  14. # License along with this library; if not, write to the Free
  15. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. #
  17. # Ramón Palleiro Rodríguez
  18. # Zero! Factorial Studio
  19. # info@zero.gal
  20. import pygame
  21. import pytest
  22. from pytest import fixture, mark
  23. from jogai import videogame as vg
  24. def test_load_empty_scene():
  25. vg._load_scene({})
  26. @mark.xfail
  27. @mark.parametrize(
  28. ('key, down'),
  29. [('a', False), (-1, True), ('pataca', True), ('', True), (None, True)],
  30. )
  31. def test_simulate_key_press(key, down):
  32. vg.init()
  33. vg.simulate_key_press(key, down)
  34. vg.quit()
  35. def test_add_group_with_wrong_type():
  36. with pytest.raises(TypeError):
  37. vg.add_group('foo')
  38. def test_listen_quit_event():
  39. quit_event = pygame.event.Event(
  40. pygame.QUIT,
  41. mod=pygame.locals.KMOD_NONE,
  42. )
  43. vg.init()
  44. pygame.event.post(quit_event)
  45. vg.listen_events()
  46. def test_get_color_with_wrong_types():
  47. with pytest.raises(TypeError):
  48. vg.get_color('foo', 'bar')
  49. def test_get_color_with_out_of_range_values():
  50. with pytest.raises(ValueError):
  51. vg.get_color(-3, 100000)
  52. @mark.parametrize('wait', [-1, 0, 1, 'foo', None])
  53. def test_wait_and_quit(wait):
  54. vg.quit(wait)
  55. def test_prepare_02_yaml():
  56. vg.init()
  57. vg.prepare('02.yaml')
  58. vg.quit()
  59. def test_load_yaml_with_no_characters():
  60. vg.init()
  61. vg.prepare('no_characters.yaml')
  62. vg.quit()
  63. def test_add_character_with_wrong_type():
  64. with pytest.raises(TypeError):
  65. vg.add_character('foo')
  66. def test_update(prepare_videogame):
  67. vg.update()