Mysteriously fix tests

This commit is contained in:
Yohann D'ANELLO 2020-11-10 20:43:30 +01:00
parent f9c3fc1517
commit d50c775e0f
3 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import curses import curses
from typing import Any, Union from typing import Any, Optional, Union
from dungeonbattle.display.texturepack import TexturePack
from dungeonbattle.tests.screen import FakePad from dungeonbattle.tests.screen import FakePad
@ -10,9 +11,9 @@ class Display:
width: int width: int
height: int height: int
def __init__(self, screen: Any, pack: Any): def __init__(self, screen: Any, pack: Optional[TexturePack] = None):
self.screen = screen self.screen = screen
self.pack = pack self.pack = pack or TexturePack.get_pack("ascii")
def newpad(self, height: int, width: int) -> Union[FakePad, Any]: def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
return curses.newpad(height, width) if self.screen else FakePad() return curses.newpad(height, width) if self.screen else FakePad()

View File

@ -6,8 +6,8 @@ from dungeonbattle.entities.player import Player
class StatsDisplay(Display): class StatsDisplay(Display):
player: Player player: Player
def __init__(self, *args): def __init__(self, *args, **kwargs):
super().__init__(*args) super().__init__(*args, **kwargs)
self.pad = self.newpad(self.rows, self.cols) self.pad = self.newpad(self.rows, self.cols)
def update_player(self, p: Player) -> None: def update_player(self, p: Player) -> None:

View File

@ -1,6 +1,7 @@
import unittest import unittest
from dungeonbattle.display.display import Display from dungeonbattle.display.display import Display
from dungeonbattle.display.display_manager import DisplayManager
from dungeonbattle.display.statsdisplay import StatsDisplay from dungeonbattle.display.statsdisplay import StatsDisplay
from dungeonbattle.game import Game, KeyValues, GameMode from dungeonbattle.game import Game, KeyValues, GameMode
from dungeonbattle.menus import MainMenuValues from dungeonbattle.menus import MainMenuValues
@ -12,11 +13,13 @@ class TestGame(unittest.TestCase):
Setup game. Setup game.
""" """
self.game = Game() self.game = Game()
self.game.new_game(None) self.game.new_game()
display = DisplayManager(None, self.game)
self.game.display_refresh = display.refresh
def test_load_game(self) -> None: def test_load_game(self) -> None:
self.assertRaises(NotImplementedError, Game.load_game, "game.save") self.assertRaises(NotImplementedError, Game.load_game, "game.save")
self.assertRaises(NotImplementedError, Display(None).refresh) self.assertRaises(NotImplementedError, Display(None).display)
def test_key_translation(self) -> None: def test_key_translation(self) -> None:
""" """
@ -105,6 +108,7 @@ class TestGame(unittest.TestCase):
self.assertEqual(self.game.state, GameMode.MAINMENU) self.assertEqual(self.game.state, GameMode.MAINMENU)
def test_stats_display(self) -> None: def test_stats_display(self) -> None:
self.game.current_display = StatsDisplay(None, self.game.player, self.game.current_display = StatsDisplay(None)
42, 42) self.game.current_display.update_player(self.game.player)
self.game.current_display.resize(0, 0, 42, 42)
self.game.current_display.refresh() self.game.current_display.refresh()