test_videogame.py 1.1 KB

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