test_character.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import pygame
  2. import pytest
  3. from jogai import character
  4. from jogai import videogame as vg
  5. from jogai.translations import gettext as _
  6. def test_height_is_a_non_negative_integer(prepare_videogame):
  7. assert protagonist.height > -1
  8. def test_width_is_a_non_negative_integer(prepare_videogame):
  9. assert protagonist.width > -1
  10. def test_x_coordinate_is_an_integer(prepare_videogame):
  11. assert isinstance(protagonist.x, int)
  12. def test_y_coordinate_is_an_integer(prepare_videogame):
  13. assert isinstance(protagonist.y, int)
  14. def test_wrong_character_name():
  15. with pytest.raises(TypeError):
  16. ch = character.Character('protagonist.png', 1)
  17. def test_repr_character(prepare_videogame):
  18. print(protagonist.__repr__)
  19. def test_wrong_predefined_keys_type():
  20. with pytest.raises(TypeError):
  21. ch = character.Character('protagonist.png', predefined_keys=[])
  22. def test_move_with_wrong_coordinates(prepare_videogame):
  23. with pytest.raises(TypeError):
  24. protagonist.move('foo', 'bar')
  25. def test_move_with_wrong_key(prepare_videogame):
  26. with pytest.raises(TypeError):
  27. protagonist.move(5, 3, 1)
  28. def test_scale_with_wrong_factor_type(prepare_videogame):
  29. with pytest.raises(TypeError):
  30. protagonist.scale_to('foo')
  31. def test_scale_with_a_negative_factor(prepare_videogame):
  32. with pytest.raises(ValueError):
  33. protagonist.scale_to(-1)
  34. def test_set_height_with_wrong_type(prepare_videogame):
  35. with pytest.raises(TypeError):
  36. protagonist.set_height('foo')
  37. def test_set_height_with_a_negative_amount(prepare_videogame):
  38. with pytest.raises(ValueError):
  39. protagonist.set_height(-1)
  40. def test_set_position_with_wrong_types(prepare_videogame):
  41. with pytest.raises(TypeError):
  42. protagonist.set_position('foo', 'bar')
  43. def test_set_width_with_wrong_type(prepare_videogame):
  44. with pytest.raises(TypeError):
  45. protagonist.set_width('a')
  46. def test_set_width_with_a_negative_amount(prepare_videogame):
  47. with pytest.raises(ValueError):
  48. protagonist.set_width(-1)