From 7a4936e6a5443d9408e7e62b97f8c3e7cb8b5a37 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 8 Jan 2021 15:58:54 +0100 Subject: [PATCH] Test monocles --- squirrelbattle/game.py | 2 +- squirrelbattle/tests/entities_test.py | 19 +++++++++++++++++-- squirrelbattle/tests/game_test.py | 23 +++++++++++++---------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 5cb3762..837e753 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -345,7 +345,7 @@ class Game: try: self.map_index = d["map_index"] self.maps = [Map().load_state(map_dict) for map_dict in d["maps"]] - except KeyError as e: + except KeyError: self.message = _("Some keys are missing in your save file.\n" "Your save seems to be corrupt. It got deleted.") os.unlink(ResourceManager.get_config_path("save.json")) diff --git a/squirrelbattle/tests/entities_test.py b/squirrelbattle/tests/entities_test.py index af6f7dd..5729032 100644 --- a/squirrelbattle/tests/entities_test.py +++ b/squirrelbattle/tests/entities_test.py @@ -1,11 +1,12 @@ # Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse # SPDX-License-Identifier: GPL-3.0-or-later - +import random import unittest from squirrelbattle.entities.items import BodySnatchPotion, Bomb, Heart, Item, \ Explosion -from squirrelbattle.entities.monsters import Tiger, Hedgehog, Rabbit, TeddyBear +from squirrelbattle.entities.monsters import Tiger, Hedgehog, Rabbit,\ + TeddyBear, GiantSeaEagle from squirrelbattle.entities.friendly import Trumpet from squirrelbattle.entities.player import Player from squirrelbattle.interfaces import Entity, Map @@ -264,3 +265,17 @@ class TestEntities(unittest.TestCase): player_state = player.save_state() self.assertEqual(player_state["current_xp"], 10) + + def test_critical_hit(self) -> None: + """ + Ensure that critical hits are working. + """ + random.seed(2) # Next random.randint(1, 100) will output 8 + self.player.critical = 10 + sea_eagle = GiantSeaEagle() + self.map.add_entity(sea_eagle) + sea_eagle.move(2, 6) + old_health = sea_eagle.health + self.player.hit(sea_eagle) + self.assertEqual(sea_eagle.health, + old_health - self.player.strength * 4) diff --git a/squirrelbattle/tests/game_test.py b/squirrelbattle/tests/game_test.py index 785cd6a..a5cb8ae 100644 --- a/squirrelbattle/tests/game_test.py +++ b/squirrelbattle/tests/game_test.py @@ -1,8 +1,8 @@ # Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse # SPDX-License-Identifier: GPL-3.0-or-later + import curses import os -import random import unittest from ..bootstrap import Bootstrap @@ -10,7 +10,7 @@ from ..display.display import Display from ..display.display_manager import DisplayManager from ..entities.friendly import Merchant, Sunflower from ..entities.items import Bomb, Heart, Sword, Explosion, Shield, Helmet, \ - Chestplate, RingCritical + Chestplate, RingCritical, Monocle from ..entities.monsters import GiantSeaEagle from ..entities.player import Player from ..enums import DisplayActions @@ -584,6 +584,7 @@ class TestGame(unittest.TestCase): # Buy a heart merchant.inventory[1] = Heart() + self.game.display_actions(DisplayActions.REFRESH) item = self.game.store_menu.validate() self.assertIn(item, merchant.inventory) self.assertEqual(item, merchant.inventory[1]) @@ -702,19 +703,21 @@ class TestGame(unittest.TestCase): self.game.save_state() ring.unequip() - def test_critical_hit(self) -> None: + def test_monocle(self) -> None: """ - Ensure that critical hits are working. + The player is wearing a monocle, then the stats are displayed. """ - random.seed(2) # Next random.randint(1, 100) will output 8 - self.game.player.critical = 10 + self.game.state = GameMode.PLAY + + monocle = Monocle() + monocle.hold(self.game.player) + monocle.equip() + sea_eagle = GiantSeaEagle() self.game.map.add_entity(sea_eagle) sea_eagle.move(2, 6) - old_health = sea_eagle.health - self.game.player.hit(sea_eagle) - self.assertEqual(sea_eagle.health, - old_health - self.game.player.strength * 4) + + self.game.display_actions(DisplayActions.REFRESH) def test_ladders(self) -> None: """