test_character.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_update_rect_position_with_wrong_type(prepare_videogame):
  23. with pytest.raises(TypeError):
  24. protagonist._update_rect_position(vgscene, 'foo')
  25. def test_move_with_wrong_coordinates(prepare_videogame):
  26. with pytest.raises(TypeError):
  27. protagonist.move('foo', 'bar')
  28. def test_move_with_wrong_key(prepare_videogame):
  29. with pytest.raises(TypeError):
  30. protagonist.move(5, 3, 1)
  31. def test_decrease_with_integer_argument(prepare_videogame):
  32. protagonist.decrease(2)
  33. def test_decrease_with_wrong_type(prepare_videogame):
  34. with pytest.raises(TypeError):
  35. protagonist.decrease('foo')
  36. def test_increase_with_integer_argument(prepare_videogame):
  37. protagonist.increase(2)
  38. def test_increase_with_wrong_type(prepare_videogame):
  39. with pytest.raises(TypeError):
  40. protagonist.increase('foo')
  41. def test_scale_with_wrong_factor_type(prepare_videogame):
  42. with pytest.raises(TypeError):
  43. protagonist.scale_to('foo')
  44. def test_scale_with_a_negative_factor(prepare_videogame):
  45. with pytest.raises(ValueError):
  46. protagonist.scale_to(-1)
  47. def test_set_height_with_wrong_type(prepare_videogame):
  48. with pytest.raises(TypeError):
  49. protagonist.set_height('foo')
  50. def test_set_height_with_a_negative_amount(prepare_videogame):
  51. with pytest.raises(ValueError):
  52. protagonist.set_height(-1)
  53. def test_set_keys_with_wrong_type(prepare_videogame):
  54. with pytest.raises(TypeError):
  55. protagonist.set_keys('foo')
  56. def test_set_position_with_wrong_types(prepare_videogame):
  57. with pytest.raises(TypeError):
  58. protagonist.set_position('foo', 'bar')
  59. def test_set_position_with_wrong_number_of_parameters(prepare_videogame):
  60. with pytest.raises(ValueError):
  61. protagonist.set_position((2, 3, 4))
  62. def test_set_width_with_wrong_type(prepare_videogame):
  63. with pytest.raises(TypeError):
  64. protagonist.set_width('a')
  65. def test_set_width_with_a_negative_amount(prepare_videogame):
  66. with pytest.raises(ValueError):
  67. protagonist.set_width(-1)