import pygame import pytest from jogai import character, settings from jogai import videogame as vg from jogai.translations import gettext as _ def test_height_is_a_non_negative_integer(prepare_videogame): assert protagonist.height > -1 def test_width_is_a_non_negative_integer(prepare_videogame): assert protagonist.width > -1 def test_x_coordinate_is_an_integer(prepare_videogame): assert isinstance(protagonist.x, int) def test_y_coordinate_is_an_integer(prepare_videogame): assert isinstance(protagonist.y, int) def test_wrong_character_name(): with pytest.raises(TypeError): ch = character.Character('protagonist.png', 1) def test_repr_character(prepare_videogame): print(protagonist.__repr__) def test_wrong_predefined_keys_type(): with pytest.raises(TypeError): ch = character.Character('protagonist.png', predefined_keys=[]) def test_move_with_wrong_coordinates(prepare_videogame): with pytest.raises(TypeError): protagonist.move('foo', 'bar') def test_move_with_wrong_key(prepare_videogame): with pytest.raises(TypeError): protagonist.move(5, 3, 1) def test_decrease_with_integer_argument(prepare_videogame): protagonist.decrease(2) def test_decrease_with_wrong_type(prepare_videogame): with pytest.raises(TypeError): protagonist.decrease('foo') def test_increase_with_integer_argument(prepare_videogame): protagonist.increase(2) def test_increase_with_wrong_type(prepare_videogame): with pytest.raises(TypeError): protagonist.increase('foo') def test_scale_with_wrong_factor_type(prepare_videogame): with pytest.raises(TypeError): protagonist.scale_to('foo') def test_scale_with_a_negative_factor(prepare_videogame): with pytest.raises(ValueError): protagonist.scale_to(-1) def test_set_height_with_wrong_type(prepare_videogame): with pytest.raises(TypeError): protagonist.set_height('foo') def test_set_height_with_a_negative_amount(prepare_videogame): with pytest.raises(ValueError): protagonist.set_height(-1) def test_set_keys_with_wrong_type(prepare_videogame): with pytest.raises(TypeError): protagonist.set_keys('foo') def test_set_position_with_wrong_types(prepare_videogame): with pytest.raises(TypeError): protagonist.set_position('foo', 'bar') def test_set_position_with_wrong_number_of_parameters(prepare_videogame): with pytest.raises(ValueError): protagonist.set_position((2, 3, 4)) def test_set_width_with_wrong_type(prepare_videogame): with pytest.raises(TypeError): protagonist.set_width('a') def test_set_width_with_a_negative_amount(prepare_videogame): with pytest.raises(ValueError): protagonist.set_width(-1) def test_update_rect_position_with_wrong_type(prepare_videogame): with pytest.raises(TypeError): protagonist._update_rect_position(vgscene, 'foo') def test_jump_counter_when_updating_jump(prepare_videogame): protagonist.jump() previous_jump_counter = protagonist._jump_counter protagonist._update_jump() assert protagonist._jump_counter == previous_jump_counter - 1 def test_jump_counter_when_jump_finishes(): protagonist.jump() while protagonist.is_jumping: protagonist._update_jump() assert protagonist._jump_counter == settings.DEFAULT_JUMP_FORCE