コード例 #1
0
def test_card_draw_buttons_custom_size_colours():
    """
    Ensure that customisations to the buttons text size, text colour and
    background colour are set as expected.
    """
    card = Card(
        "title",
        buttons=[
            {
                "label": "Button1",
                "target": "AnotherCard",
                "text_size": 32,
                "text_color": "red",
                "background_color": "blue",
            }
        ],
    )
    card.layout = mock.MagicMock()
    card._button_click = mock.MagicMock()
    card._draw_buttons()
    assert len(card.button_widgets) == 1
    assert card.button_widgets[0].text == "Button1"
    assert card.button_widgets[0].font_size == 32.0
    assert card.button_widgets[0].color == [1.0, 0.0, 0.0, 1.0]
    assert card.button_widgets[0].background_color == [0.0, 0.0, 1.0, 1.0]
    card._button_click.assert_called_once_with("AnotherCard")
    assert card.layout.add_widget.call_count == 1
コード例 #2
0
def test_card_draw_buttons():
    """
    Ensure the expected buttons are created and linked to an event handler.
    """
    card = Card("title",
                buttons=[{
                    "label": "Button1",
                    "target": "AnotherCard"
                }])
    card.layout = mock.MagicMock()
    card._button_click = mock.MagicMock()
    card._draw_buttons()
    assert len(card.button_widgets) == 1
    assert card.button_widgets[0].text == "Button1"
    card._button_click.assert_called_once_with("AnotherCard")
    assert card.layout.add_widget.call_count == 1
コード例 #3
0
def test_card_draw_buttons():
    """
    Ensure the expected buttons are created and linked to an event handler.
    """
    card = Card(
        "title", buttons=[{"label": "Button1", "target": "AnotherCard"}]
    )
    card.layout = mock.MagicMock()
    card._button_click = mock.MagicMock()
    card._draw_buttons()
    assert len(card.button_widgets) == 1
    assert card.button_widgets[0].text == "Button1"
    assert card.button_widgets[0].color == [1.0, 1.0, 1.0, 1.0]  # white.
    assert card.button_widgets[0].background_color == [
        0.7450980392156863,
        0.7450980392156863,
        0.7450980392156863,
        1.0,
    ]  # grey.
    assert card.button_widgets[0].font_size == 24.0
    card._button_click.assert_called_once_with("AnotherCard")
    assert card.layout.add_widget.call_count == 1
コード例 #4
0
def test_card_screen_with_buttons():
    """
    If buttons are configured for the card, ensure the expected _draw_buttons
    method is called to paint the buttons onto the screen for the card.
    """
    mock_screen_manager = mock.MagicMock()
    data_store = {"foo": "bar"}
    card = Card(
        "title", buttons=[{"label": "A Button", "target": "AnotherButton"}]
    )
    card._draw_buttons = mock.MagicMock()
    card.screen(mock_screen_manager, data_store)
    card._draw_buttons.assert_called_once_with()