Skip to content

Commit

Permalink
Merge pull request #16 from Pilifer/test4
Browse files Browse the repository at this point in the history
test more draws (issue#8) and another type hint. (issue #1)
  • Loading branch information
pvcraven authored Mar 3, 2020
2 parents ed033cd + ea351c4 commit e882d47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 1 addition & 2 deletions source/game_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, width: int, height: int, title: str):
# Where is the mouse?
self.mouse_position: Optional[Tuple[float, float]] = None

self.mouse_over_text = None
self.mouse_over_text: Optional[str] = None

# These are sprites that appear as buttons on the character sheet.
self.character_sheet_buttons = arcade.SpriteList()
Expand Down Expand Up @@ -181,7 +181,6 @@ def draw_character_screen(self):
if self.game_engine.player.fighter.ability_points > 0:
self.character_sheet_buttons.draw()


def handle_and_draw_messages(self):
# Check message queue. Limit to 2 lines
while len(self.game_engine.messages) > 2:
Expand Down
37 changes: 36 additions & 1 deletion tests/test_game_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,32 @@ def test_draw_inventory_with_selected_item(
call.draw_text("2: ", 480.0, 40, (0, 0, 0, 255)),
]

def test_draw_mouse_over_text_when_it_is_there(
self, mock_arcade, mock_draw_text, mock_engine, window,
):
window.mouse_over_text = "foo"
mock_mouse_position = (Mock(), Mock())
window.mouse_position = mock_mouse_position

window.draw_mouse_over_text()

mock_arcade.draw_xywh_rectangle_filled.assert_called_once_with(
*mock_mouse_position, 100, 16, mock_arcade.color.BLACK
)
mock_draw_text.assert_called_once_with(
"foo", *mock_mouse_position, mock_arcade.csscolor.WHITE
)

def test_draw_mouse_over_text_when_it_is_not_there(
self, mock_arcade, mock_draw_text, mock_engine, window,
):
window.mouse_over_text = None

window.draw_mouse_over_text()

mock_arcade.draw_xywh_rectangle_filled.assert_not_called()
mock_draw_text.assert_not_called()

def test_draw_in_normal_state(self, mocker, mock_arcade, mock_engine, window):
mock_draw_hp = mocker.patch("game_window.MyGame.draw_hp_and_status_bar")
mock_draw_inventory = mocker.patch("game_window.MyGame.draw_inventory")
Expand All @@ -280,7 +306,7 @@ def test_draw_in_normal_state(self, mocker, mock_arcade, mock_engine, window):
mock_handle_and_draw_messages.assert_called_once()
mock_draw_mouse_over_text.assert_called_once()

def test_draw_in_select_location_state(
def test_draw_in_select_location_state_with_mouse_position(
self, mocker, mock_arcade, mock_pixel_to_char, window
):
mock_grid_coordinates = Mock(), Mock()
Expand All @@ -303,3 +329,12 @@ def test_draw_in_select_location_state(
mock_arcade.color.LIGHT_BLUE,
2,
)

def test_draw_in_select_location_state_without_mouse_position(
self, mock_arcade, mock_pixel_to_char, window
):
window.mouse_position = None

window.draw_in_select_location_state()

mock_pixel_to_char.assert_not_called()

0 comments on commit e882d47

Please sign in to comment.