test_character.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import pygame
  2. import pytest
  3. from jogai import character, settings
  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_decrease_with_integer_argument(prepare_videogame):
  29. protagonist.decrease(2)
  30. def test_decrease_with_wrong_type(prepare_videogame):
  31. with pytest.raises(TypeError):
  32. protagonist.decrease('foo')
  33. def test_increase_with_integer_argument(prepare_videogame):
  34. protagonist.increase(2)
  35. def test_increase_with_wrong_type(prepare_videogame):
  36. with pytest.raises(TypeError):
  37. protagonist.increase('foo')
  38. def test_scale_with_wrong_factor_type(prepare_videogame):
  39. with pytest.raises(TypeError):
  40. protagonist.scale_to('foo')
  41. def test_scale_with_a_negative_factor(prepare_videogame):
  42. with pytest.raises(ValueError):
  43. protagonist.scale_to(-1)
  44. def test_set_height_with_wrong_type(prepare_videogame):
  45. with pytest.raises(TypeError):
  46. protagonist.set_height('foo')
  47. def test_set_height_with_a_negative_amount(prepare_videogame):
  48. with pytest.raises(ValueError):
  49. protagonist.set_height(-1)
  50. def test_set_keys_with_wrong_type(prepare_videogame):
  51. with pytest.raises(TypeError):
  52. protagonist.set_keys('foo')
  53. def test_set_position_with_wrong_types(prepare_videogame):
  54. with pytest.raises(TypeError):
  55. protagonist.set_position('foo', 'bar')
  56. def test_set_position_with_wrong_number_of_parameters(prepare_videogame):
  57. with pytest.raises(ValueError):
  58. protagonist.set_position((2, 3, 4))
  59. def test_set_width_with_wrong_type(prepare_videogame):
  60. with pytest.raises(TypeError):
  61. protagonist.set_width('a')
  62. def test_set_width_with_a_negative_amount(prepare_videogame):
  63. with pytest.raises(ValueError):
  64. protagonist.set_width(-1)
  65. def test_update_rect_position_with_wrong_type(prepare_videogame):
  66. with pytest.raises(TypeError):
  67. protagonist._update_rect_position(vgscene, 'foo')
  68. def test_jump_counter_when_updating_jump(prepare_videogame):
  69. protagonist.jump()
  70. previous_jump_counter = protagonist._jump_counter
  71. protagonist._update_jump()
  72. assert protagonist._jump_counter == previous_jump_counter - 1
  73. def test_jump_counter_when_jump_finishes():
  74. protagonist.jump()
  75. while protagonist.is_jumping:
  76. protagonist._update_jump()
  77. assert protagonist._jump_counter == settings.DEFAULT_JUMP_FORCE