예제 #1
0
def test_get_border_positions():
    button = TextButton(center_x=50,
                        center_y=20,
                        width=30,
                        height=10,
                        text='Click me')
    assert button.get_top() == 20 + 10 / 2
    assert button.get_bottom() == 20 - 10 / 2
    assert button.get_left() == 50 - 30 / 2
    assert button.get_right() == 50 + 30 / 2
예제 #2
0
def test_draw_color_theme(mocker):
    mocker.patch('arcade.draw_rectangle_filled')
    mocker.patch('arcade.draw_line')

    button = TextButton(center_x=50, center_y=20, width=30, height=10, text='')

    button.pressed = False
    button.draw_color_theme()
    arcade.draw_rectangle_filled.assert_called_once_with(
        50, 20, 30, 10, button.face_color)

    assert arcade.draw_line.call_count == 4
    assert arcade.draw_line.call_args_list == [
        call(button.get_left(), button.get_bottom(), button.get_right(),
             button.get_bottom(), button.shadow_color, button.button_height),
        call(button.get_right(), button.get_bottom(), button.get_right(),
             button.get_top(), button.shadow_color, button.button_height),
        call(button.get_left(), button.get_top(), button.get_right(),
             button.get_top(), button.highlight_color, button.button_height),
        call(button.get_left(), button.get_bottom(), button.get_left(),
             button.get_top(), button.highlight_color, button.button_height)
    ]

    arcade.draw_rectangle_filled.reset_mock()
    arcade.draw_line.reset_mock()
    button.pressed = True
    button.draw_color_theme()
    arcade.draw_rectangle_filled.assert_called_once_with(
        50, 20, 30, 10, button.face_color)

    assert arcade.draw_line.call_count == 4
    assert arcade.draw_line.call_args_list == [
        call(button.get_left(), button.get_bottom(), button.get_right(),
             button.get_bottom(), button.highlight_color,
             button.button_height),
        call(button.get_right(), button.get_bottom(), button.get_right(),
             button.get_top(), button.highlight_color, button.button_height),
        call(button.get_left(), button.get_top(), button.get_right(),
             button.get_top(), button.shadow_color, button.button_height),
        call(button.get_left(), button.get_bottom(), button.get_left(),
             button.get_top(), button.shadow_color, button.button_height)
    ]