test_videogame.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import pygame
  2. import pytest
  3. from pytest import fixture, mark
  4. from jogai import videogame as vg
  5. def test_load_empty_scene():
  6. vg._load_scene({})
  7. @mark.xfail
  8. @mark.parametrize(
  9. ('key, down'),
  10. [('a', False), (-1, True), ('pataca', True), ('', True), (None, True)],
  11. )
  12. def test_simulate_key_press(key, down):
  13. vg.init()
  14. vg.simulate_key_press(key, down)
  15. vg.quit()
  16. def test_add_group_with_wrong_type():
  17. with pytest.raises(TypeError):
  18. vg.add_group('foo')
  19. def test_listen_quit_event():
  20. quit_event = pygame.event.Event(
  21. pygame.QUIT,
  22. mod=pygame.locals.KMOD_NONE,
  23. )
  24. vg.init()
  25. pygame.event.post(quit_event)
  26. vg.listen_events()
  27. def test_get_color_with_wrong_types():
  28. with pytest.raises(TypeError):
  29. vg.get_color('foo', 'bar')
  30. def test_get_color_with_out_of_range_values():
  31. with pytest.raises(ValueError):
  32. vg.get_color(-3, 100000)
  33. @mark.parametrize('wait', [-1, 0, 1, 'foo', None])
  34. def test_wait_and_quit(wait):
  35. vg.quit(wait)
  36. def test_prepare_02_yaml():
  37. vg.init()
  38. vg.prepare('02.yaml')
  39. vg.quit()
  40. def test_load_yaml_with_no_characters():
  41. vg.init()
  42. vg.prepare('no_characters.yaml')
  43. vg.quit()
  44. def test_add_character_with_wrong_type():
  45. with pytest.raises(TypeError):
  46. vg.add_character('foo')
  47. def test_update(prepare_videogame):
  48. vg.update()