Use a fake pad to make tests runnable
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
				
			|||||||
import curses
 | 
					import curses
 | 
				
			||||||
from typing import Any
 | 
					from typing import Any, Union
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from dungeonbattle.tests.screen import FakePad
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Display:
 | 
					class Display:
 | 
				
			||||||
@@ -10,3 +12,9 @@ class Display:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def refresh(self) -> None:
 | 
					    def refresh(self) -> None:
 | 
				
			||||||
        raise NotImplementedError
 | 
					        raise NotImplementedError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
 | 
				
			||||||
 | 
					        if self.screen:
 | 
				
			||||||
 | 
					            return curses.newpad(height, width)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return FakePad()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@ class MapDisplay(Display):
 | 
				
			|||||||
        self.pack = pack
 | 
					        self.pack = pack
 | 
				
			||||||
        self.map = m
 | 
					        self.map = m
 | 
				
			||||||
        self.player = player
 | 
					        self.player = player
 | 
				
			||||||
        self.pad = curses.newpad(m.height, m.width + 1)
 | 
					        self.pad = self.newpad(m.height, m.width + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_pad(self) -> None:
 | 
					    def update_pad(self) -> None:
 | 
				
			||||||
        self.pad.addstr(0, 0, self.map.draw_string(self.pack))
 | 
					        self.pad.addstr(0, 0, self.map.draw_string(self.pack))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,12 +18,12 @@ class MenuDisplay(Display):
 | 
				
			|||||||
        self.toplefty = toplefty
 | 
					        self.toplefty = toplefty
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Menu values are printed in pad
 | 
					        # Menu values are printed in pad
 | 
				
			||||||
        self.pad = curses.newpad(self.trueheight, self.truewidth + 1)
 | 
					        self.pad = self.newpad(self.trueheight, self.truewidth + 1)
 | 
				
			||||||
        for i in range(self.trueheight):
 | 
					        for i in range(self.trueheight):
 | 
				
			||||||
            self.pad.addstr(i, 0, " " + self.values[i].value)
 | 
					            self.pad.addstr(i, 0, " " + self.values[i].value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Menu box
 | 
					        # Menu box
 | 
				
			||||||
        self.menubox = curses.newpad(self.height, self.width)
 | 
					        self.menubox = self.newpad(self.height, self.width)
 | 
				
			||||||
        self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓")
 | 
					        self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓")
 | 
				
			||||||
        for i in range(1, self.height - 2):
 | 
					        for i in range(1, self.height - 2):
 | 
				
			||||||
            self.menubox.addstr(i, 0, "┃" + " " * (self.width - 2) + "┃")
 | 
					            self.menubox.addstr(i, 0, "┃" + " " * (self.width - 2) + "┃")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ class StatsDisplay(Display):
 | 
				
			|||||||
        self.topleftx = topleftx
 | 
					        self.topleftx = topleftx
 | 
				
			||||||
        self.toplefty = toplefty
 | 
					        self.toplefty = toplefty
 | 
				
			||||||
        self.player = player
 | 
					        self.player = player
 | 
				
			||||||
        self.pad = curses.newpad(height, width)
 | 
					        self.pad = self.newpad(height, width)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_pad(self) -> None:
 | 
					    def update_pad(self) -> None:
 | 
				
			||||||
        string = ""
 | 
					        string = ""
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								dungeonbattle/tests/screen.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								dungeonbattle/tests/screen.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					class FakePad:
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    In order to run tests, we simulate a fake curses pad that accepts functions
 | 
				
			||||||
 | 
					    but does nothing with them.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    def addstr(self, y: int, x: int, message: str) -> None:
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def refresh(self, pminrow: int, pmincol: int, sminrow: int,
 | 
				
			||||||
 | 
					                smincol: int, smaxrow: int, smaxcol: int) -> None:
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def clear(self):
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
		Reference in New Issue
	
	Block a user