def render_column_definition(self, renderer: RenderingEngine, x: int, y: int, board: Board, column: int): column_def = board.get_definition('column', column) for i in column_def: i_str = str(i) renderer.draw_text(i_str, x, y) y += renderer.get_text_height(i_str)
def test_invalid_screen_size(): with pytest.raises(ValueError): RenderingEngine.mock_engine(-1, 240, 14) with pytest.raises(ValueError): RenderingEngine.mock_engine(0, 240, 14) with pytest.raises(ValueError): RenderingEngine.mock_engine(320, -1, 14) with pytest.raises(ValueError): RenderingEngine.mock_engine(320, 0, 14)
def test_drawing_static_image(): test_img = Image('intro_ball.gif', directory='test_assets') r = RenderingEngine.mock_engine(320, 240, 14) r.draw_static_image(test_img, 5, 3) assert r.last_command() == { 'name': 'draw_static_image', 'img': test_img, 'x': 5, 'y': 3 }
def test_drawing_text(): text = 'Test text!' r = RenderingEngine.mock_engine(320, 240, 14) r.draw_text(text, 50, 25, color=[255, 0, 0]) assert r.last_command() == { 'name': 'draw_text', 'text': text, 'x': 50, 'y': 25, 'color': [255, 0, 0], }
def test_row_definition_width(): squares = [ [1, 0, 1], [0, 1, 0], ] test_board = Board(squares) text_renderer = TextBoardRenderer() r = RenderingEngine.pygame_engine(640, 480, DEFAULT_FONT_SIZE) expected_width = r.get_text_width("1 1") assert text_renderer.get_row_definition_width(r, test_board, 0) == expected_width
def initialize(self) -> None: self._renderer = RenderingEngine.pygame_engine(640, 480, 14) self._clock = pygame.time.Clock() self._board_renderer = TextBoardRenderer() squares = [ [1, 0, 0], [0, 1, 0], [1, 0, 1], [1, 0, 0], ] self._board = Board(squares) self._is_running = self.is_ready()
def test_max_row_definition_width(): squares = [ [0, 1, 1], [1, 0, 0], [1, 1, 0], [1, 0, 0], [1, 1, 0], ] test_board = Board(squares) text_renderer = TextBoardRenderer() r = RenderingEngine.pygame_engine(640, 480, DEFAULT_FONT_SIZE) expected_height = r.get_text_height("1 1 1", render_horizontal=False) assert text_renderer.get_max_column_definition_height( r, test_board) == expected_height
def test_get_font_size(): font_size = 26 r = RenderingEngine.mock_engine(320, 240, font_size) assert r.font_size() == font_size
def test_create_renderer(): r = RenderingEngine.mock_engine(320, 240, 14) assert r.width() == 320 assert r.height() == 240
def test_image_not_found(): missing_img = Image('test-image') r = RenderingEngine.mock_engine(320, 240, 14) with pytest.raises(ValueError): r.draw_static_image(missing_img, 5, 3)
def test_end_render(): r = RenderingEngine.mock_engine(320, 240, 14) r.end_render() assert r.last_command() == {'name': 'end_render'}
def test_clear_screen(): r = RenderingEngine.mock_engine(320, 240, 14) r.clear() assert r.last_command() == {'name': 'clear'}
def get_column_definition_height(self, renderer: RenderingEngine, board: Board, column: int) -> int: definition = board.get_definition('column', column) definition_str = self._definition_as_str(definition) return renderer.get_text_height(definition_str, render_horizontal=False)
def get_row_definition_height(self, renderer: RenderingEngine, board: Board, row: int) -> int: definition = board.get_definition('row', row) definition_str = self._definition_as_str(definition) return renderer.get_text_height(definition_str)
def render_row_definition(self, renderer: RenderingEngine, x: int, y: int, board: Board, row: int): row_def = board.get_definition('row', row) row_def_str = self._definition_as_str(row_def) renderer.draw_text(row_def_str, x, y)