示例#1
0
def test_draw_texture_theme(mocker):
    mocker.patch('arcade.draw_texture_rectangle')

    theme = arcade.gui.Theme()
    normal_texture = arcade.Texture('normal')
    clicked_texture = arcade.Texture('clicked')
    theme.button_textures['normal'] = normal_texture
    theme.button_textures['clicked'] = clicked_texture
    button = TextButton(center_x=50,
                        center_y=20,
                        width=30,
                        height=10,
                        text='',
                        theme=theme)

    button.pressed = False
    button.draw_texture_theme()
    arcade.draw_texture_rectangle.assert_called_once_with(
        50, 20, 30, 10, normal_texture)

    arcade.draw_texture_rectangle.reset_mock()
    button.pressed = True
    button.draw_texture_theme()
    arcade.draw_texture_rectangle.assert_called_once_with(
        50, 20, 30, 10, clicked_texture)
示例#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)
    ]
示例#3
0
def test_check_mouse_release_when_pressed_is_true_and_check_mouse_collision_true(
        mocker):
    mocker.patch.object(TextButton, 'check_mouse_collision', return_value=True)
    mocker.patch.object(TextButton, 'on_release')
    mocker.patch.object(TextButton, 'on_click')
    button = TextButton(center_x=50,
                        center_y=20,
                        width=30,
                        height=10,
                        text='Click me')
    button.pressed = True
    button.check_mouse_release(50, 20)

    assert button.pressed is False
    button.check_mouse_collision.assert_called_once_with(50, 20)
    button.on_release.assert_called_once()
    button.on_click.assert_called_once()