Skip to content

Commit

Permalink
Improve test coverage - batch of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MyreMylar committed Aug 3, 2022
1 parent ce6f31d commit c98deb1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/test_core/test_layered_gui_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ def update(self, time_delta: float):
pass


class MyDodgySprite1(pygame.sprite.Sprite):
class MyDodgySprite1(GUISprite):
def __init__(self, *groups):
super().__init__(*groups)
self.blendmode = 0

def update(self, time_delta: float):
pass


class MyDodgySprite2(pygame.sprite.Sprite):
class MyDodgySprite2(GUISprite):
def __init__(self, *groups):
super().__init__(*groups)
self.visible = 1
Expand All @@ -42,12 +43,20 @@ class TestUIElement:
def test_remove_sprite_from_group(self, _init_pygame, default_ui_manager):

group = LayeredGUIGroup()
group_2 = LayeredGUIGroup()

proper_sprite = MyProperSprite(group)

proper_sprite_2 = MyProperSprite([group])

proper_sprite_3 = MyProperSprite([[group], [group_2]])

proper_sprite.remove(group)
proper_sprite_2.remove([group])
proper_sprite_3.remove([[group], [group_2]])

assert len(group.sprites()) == 0
assert len(group_2.sprites()) == 0

def test_add_dodgy_sprites(self, _init_pygame, default_ui_manager):
group = LayeredGUIGroup()
Expand Down Expand Up @@ -88,4 +97,4 @@ def test_print_sprite(self, _init_pygame, default_ui_manager):


if __name__ == '__main__':
pytest.console_main()
pytest.console_main()
20 changes: 20 additions & 0 deletions tests/test_elements/test_ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,26 @@ def test_class_theming_id(self, _init_pygame, _display_surface_return_none):
'@test_class',
'button']

def test_change_locale(self, _init_pygame, default_ui_manager, _display_surface_return_none):
button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
text="Test Button",
tool_tip_text="This is a test of the button's tool tip functionality.",
manager=default_ui_manager)

default_ui_manager.set_locale('fr')
default_ui_manager.set_locale('ja')

assert button.text == "Test Button"

dynamic_width_button = UIButton(relative_rect=pygame.Rect(100, 100, -1, 30),
text="Test Button",
tool_tip_text="This is a test of the button's tool tip functionality.",
manager=default_ui_manager)

default_ui_manager.set_locale('fr')
default_ui_manager.set_locale('ja')

assert dynamic_width_button.text == "Test Button"

if __name__ == '__main__':
pytest.console_main()
18 changes: 18 additions & 0 deletions tests/test_elements/test_ui_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,24 @@ def test_set_dimensions(self, _init_pygame, default_ui_manager):
'top': 'top',
'bottom': 'bottom'})

button = UIButton(relative_rect=pygame.Rect(0, 40, 10, 10), text="A",
manager=default_ui_manager,
container=element_5,
anchors={'left': 'left',
'right': 'left',
'top': 'bottom',
'bottom': 'bottom'}
)

button_2 = UIButton(relative_rect=pygame.Rect(40, 0, 10, 10), text="A",
manager=default_ui_manager,
container=element_5,
anchors={'left': 'right',
'right': 'right',
'top': 'top',
'bottom': 'top'}
)

assert element_5.relative_right_margin == 240
assert element_5.relative_bottom_margin == 240

Expand Down
9 changes: 9 additions & 0 deletions tests/test_elements/test_ui_screen_space_health_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ def test_update(self, _init_pygame, default_ui_manager):
health_bar.update(0.01)
assert health_bar.image is not None

def test_health_percentage(self, _init_pygame, default_ui_manager):
healthy_sprite = HealthySprite()
health_bar = UIScreenSpaceHealthBar(relative_rect=pygame.Rect(100, 100, 150, 30),
sprite_to_monitor=healthy_sprite,
manager=default_ui_manager)
healthy_sprite.current_health = 50
health_bar.update(0.01)
assert health_bar.health_percentage == 0.5

def test_rebuild_from_theme_data_non_default(self, _init_pygame):
manager = UIManager((800, 600), os.path.join("tests", "data", "themes",
"ui_screen_health_bar_non_default.json"))
Expand Down

0 comments on commit c98deb1

Please sign in to comment.