def test_set_visual_debug_mode(self, _init_pygame, default_ui_manager: IUIManagerInterface, _display_surface_return_none): default_ui_manager.preload_fonts([{ 'name': 'fira_code', 'point_size': 8, 'style': 'regular' }]) element = UIElement(relative_rect=pygame.Rect(0, 0, 50, 50), manager=default_ui_manager, container=None, starting_height=0, layer_thickness=1) assert element.image is None element.set_visual_debug_mode(True) assert element.image is not None element.set_visual_debug_mode(False) assert element.image is None coloured_surface = pygame.Surface((50, 50)) coloured_surface.fill(pygame.Color(200, 80, 80, 255)) element.set_image(coloured_surface) assert element.pre_debug_image is None element.set_visual_debug_mode(True) assert element.pre_debug_image is not None element.set_visual_debug_mode(False) assert element.pre_debug_image is None
def test_add_font_paths_and_preload_fonts(self, _init_pygame, default_ui_manager, _display_surface_return_none): """ Combined test of setting font paths and pre-loading. We sets the path to a font, preload it then try and use it in a text box and see if any errors or warnings happen. """ default_ui_manager.add_font_paths( font_name='roboto', regular_path='tests/data/Roboto-Regular.ttf') default_ui_manager.preload_fonts([{ 'name': 'roboto', 'point_size': 14, 'style': 'regular' }]) default_ui_manager.preload_fonts([{ 'name': 'fira_code', 'html_size': 3, 'style': 'italic' }]) UITextBox(html_text="<font face=roboto>Test font pre-loading</font>", relative_rect=pygame.Rect(100, 100, 200, 100), manager=default_ui_manager)
def test_creation(self, _init_pygame, default_ui_manager, _display_surface_return_none): default_ui_manager.preload_fonts([{'name': 'fira_code', 'point_size': 14, 'style': 'bold'}]) UIMessageWindow(rect=pygame.Rect(100, 100, 250, 300), window_title="Test Message", html_message="This is a <b>bold</b> test " "of the message box functionality.", manager=default_ui_manager)
def test_creation(self, _init_pygame: None, default_ui_manager: UIManager, _display_surface_return_none): default_ui_manager.preload_fonts([{"name": "fira_code", "size:": 14, "style": "bold"}, {"name": "fira_code", "size:": 14, "style": "italic"}]) text_box = UITextBox(html_text="<font color=#FF0000>Some text</font> in a <b>bold box</b> using colours and " "<i>styles</i>.", relative_rect=pygame.Rect(100, 100, 200, 300), manager=default_ui_manager) assert text_box.image is not None
def test_creation_and_rebuild_with_scrollbar(self, _init_pygame: None, default_ui_manager: UIManager, _display_surface_return_none): default_ui_manager.preload_fonts([{'name': 'fira_code', 'html_size': 4.5, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 4.5, 'style': 'regular'}, {'name': 'fira_code', 'html_size': 2, 'style': 'regular'}, {'name': 'fira_code', 'html_size': 2, 'style': 'italic'}, {'name': 'fira_code', 'html_size': 6, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 6, 'style': 'regular'}, {'name': 'fira_code', 'html_size': 6, 'style': 'bold_italic'}, {'name': 'fira_code', 'html_size': 4, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 4, 'style': 'italic'}, {'name': 'fira_code', 'html_size': 2, 'style': 'bold'}, {'name': 'fira_code', 'html_size': 2, 'style': 'bold_italic'}]) text_box = UITextBox(html_text='' '<font color=regular_text><font color=#E784A2 size=4.5><br><b><u>Lorem</u><br><br><br>' 'ipsum dolor sit amet</b></font>,' ' <b><a href="test">consectetur</a></b> adipiscing elit. in a flibb de dib do ' 'rub a la clob slip the perry tin fo glorp yip dorp' 'skorp si pork flum de dum be dung, slob be robble glurp destination flum kin slum. ' 'Ram slim gordo, fem tulip squirrel slippers save socks certainly.<br>' 'Vestibulum in <i>commodo me</i> tellus in nisi finibus a sodales.<br>Vestibulum' '<font size=2>hendrerit mi <i>sed nulla</i> scelerisque</font>, posuere ullamcorper ' 'sem pulvinar.' 'Nulla at pulvinar a odio, a dictum dolor.<br>Maecenas at <font size=6><b>tellus a' 'tortor. a<br>' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br>' 'In hac a habitasse to platea dictumst.<br>' '<font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec porttitor.<br>Morbi ' 'accumsan, lectus at ' 'tincidunt to dictum, neque <font color=#879AF6>erat tristique erat</font>, ' 'sed a tempus for <b>nunc</b> dolor in nibh.<br>' 'Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet on pharetra a ante ' 'sollicitudin.</font></font>' '<br><br>' '<b>consectetur</b> adipiscing elit. in a<br>' 'Vestibulum in <i>commodo me</i> tellus in nisi finibus a sodales.<br>' 'Vestibulum <font size=2>hendrerit mi <i>sed nulla</i> scelerisque</font>, ' 'posuere ullamcorper sem pulvinar. ' 'Nulla at pulvinar a odio, a dictum dolor.<br>' 'Maecenas at <font size=6><b>tellus a tortor. a<br>' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br>' 'In hac a habitasse to platea dictumst.<br>' '<font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec porttitor.<br>Morbi ' 'accumsan, lectus at' 'tincidunt to dictum, neque <font color=#879AF6>erat tristique erat</font>, ' 'sed a tempus for <b>nunc</b> dolor in nibh.<br>' 'Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet on pharetra a ante ' 'sollicitudin.</font></font>', relative_rect=pygame.Rect(100, 100, 200, 300), manager=default_ui_manager) text_box.rebuild() assert text_box.image is not None
def test_creation_grow_to_fit_width(self, _init_pygame: None, default_ui_manager: UIManager, _display_surface_return_none): default_ui_manager.preload_fonts([{"name": "fira_code", "size:": 14, "style": "bold"}, {"name": "fira_code", "size:": 14, "style": "italic"}]) text_box = UITextBox(html_text="<font color=#FF0000>Some text</font> in a <b>bold box</b> using colours and " "<i>styles</i>. Hey hey hey, what is this? More text padding this out a little." "Well OK.", relative_rect=pygame.Rect(100, 100, -1, 50), manager=default_ui_manager) assert text_box.image is not None and text_box.rect.width == 984
def test_create_too_small(self, _init_pygame, default_ui_manager, _display_surface_return_none): default_ui_manager.preload_fonts([{'name': 'fira_code', 'point_size': 14, 'style': 'bold'}]) with pytest.warns(UserWarning, match="Initial size"): UIMessageWindow(rect=pygame.Rect(100, 100, 50, 50), window_title="Test Message", html_message="This is a <b>bold</b> test of the " "message box functionality.", manager=default_ui_manager)
def test_creation(self, _init_pygame, default_ui_manager, _display_surface_return_none): default_ui_manager.preload_fonts([{ 'name': 'fira_code', 'point_size': 14, 'style': 'bold' }]) UIConfirmationDialog( rect=pygame.Rect(100, 100, 400, 300), manager=default_ui_manager, action_long_desc="Confirm a <b>bold</b> test of the confirmation " "dialog.", window_title="Confirm", action_short_name="Confirm")
def test_create_too_small(self, _init_pygame, default_ui_manager, _display_surface_return_none): default_ui_manager.preload_fonts([{ 'name': 'fira_code', 'point_size': 14, 'style': 'bold' }]) with pytest.warns(UserWarning, match="Initial size"): UIConfirmationDialog( rect=pygame.Rect(100, 100, 50, 50), manager=default_ui_manager, action_long_desc= "Confirm a <b>bold</b> test of the confirmation " "dialog.", window_title="Confirm", action_short_name="Confirm")
def test_print_unused_fonts(self, _init_pygame, default_ui_manager, capsys): """ Test unused font printing, by creating a font we don't use and seeing if the print out reports it. :param _init_pygame: :param default_ui_manager: :param capsys: the captured system output. includes stdout (.out) & stderr (.err) """ default_ui_manager.add_font_paths( font_name='roboto', regular_path='tests/data/Roboto-Regular.ttf') default_ui_manager.preload_fonts([{ 'name': 'roboto', 'point_size': 14, 'style': 'regular' }]) default_ui_manager.print_unused_fonts() captured = capsys.readouterr() assert captured.out == 'Unused font ids:\nroboto_regular_14(HTML size: 4)\n'