| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import pygame
- import pytest
- from jogai import character, settings
- from jogai import videogame as vg
- from jogai.translations import gettext as _
- def test_load_data_with_none_argument(prepare_videogame):
- protagonist._load_data(None)
- def test_load_data_with_wrong_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist._load_data('foo')
- 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):
- protagonist = character.Character('protagonist.png', name=1)
- def test_repr_character(prepare_videogame):
- print(protagonist.__repr__)
- def test_wrong_predefined_keys_type():
- with pytest.raises(TypeError):
- protagonist = 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_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.move(5, 3, key=-1)
- def test_rotate_with_wrong_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.rotate('foo')
- 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_flip_with_wrong_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.flip('foo', 'bar')
- def test_set_angle_with_wrong_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.set_angle('foo')
- 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_touch_with_wrong_characters_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.touch('foo')
- def test_touch_with_list_not_all_characters(prepare_videogame):
- with pytest.raises(ValueError):
- protagonist.touch([secondary, 'foo'])
- def test_touch_with_wrong_key_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.touch(secondary, key=-1)
- def test_touch_without_sprites_colliding(prepare_videogame):
- protagonist.move_to(0, 0)
- secondary.move_to(5000, 500)
- vg.update()
- assert protagonist.touch(secondary) == False
- def test_jump_with_force_as_integer(prepare_videogame):
- protagonist.jump(5)
- def test_jump_with_wrong_force_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.jump('foo')
- def test_jump_with_negative_force(prepare_videogame):
- with pytest.raises(ValueError):
- protagonist.jump(-5)
- def test_jump_with_wrong_key_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist.jump(5, key=-1)
- 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
- def test_update_rect_position_with_wrong_traking_type(prepare_videogame):
- with pytest.raises(TypeError):
- protagonist._update_rect_position(vgscene, tracking='foo')
- def test_update_rect_position_with_no_scene(prepare_videogame):
- protagonist._update_rect_position(None)
- def test_update_rect_position_when_character_moved(prepare_videogame):
- protagonist.move_to(1000, 0)
- protagonist._update_rect_position(vgscene, tracking=True)
- protagonist.move_to(3000, 0)
- protagonist._update_rect_position(vgscene, tracking=True)
|