Beispiel #1
0
def test_clicked(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(280, 240,
                                       'connect4_clicked') as (actual,
                                                               expected):
        draw_grid(expected)
        expected.setBrush(Connect4Display.player1_colour)
        expected.drawEllipse(5, 205, 30, 30)
        colour = QColor(Connect4Display.player2_colour)
        colour.setAlpha(127)
        expected.setBrush(colour)
        colour.setRgb(0, 0, 0, 127)
        pen = QPen(colour)
        expected.setPen(pen)
        expected.drawEllipse(5, 45, 30, 30)

        display = Connect4Display()
        display.resize(372, 264)
        display.grab()  # Force layout to recalculate.

        space = display.spaces[1][0]
        display.on_click(space)

        render_display(display, actual)
Beispiel #2
0
def test_empty(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240,
                                       'sandbox_empty') as (actual, expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SandboxDisplay.load_pixmap('board-1.png',
                                       QSize(240, 240))).setPos(1, 0)

        expected_scene.render(expected)

        display = SandboxDisplay()

        display.resize(348, 264)

        render_display(display, actual)
    for widget in (display.ui.move_black, display.ui.move_white,
                   display.ui.move_red, display.ui.remove,
                   display.ui.black_count_pixmap,
                   display.ui.white_count_pixmap, display.ui.red_count_pixmap,
                   display.ui.black_count, display.ui.white_count,
                   display.ui.red_count):
        assert widget.isVisibleTo(display)
    assert display.ui.move_black.isChecked()
    assert display.ui.red_count.text() == '0'
Beispiel #3
0
def test_empty(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240, 'spargo_empty') as (
            actual,
            expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SpargoDisplay.load_pixmap('board-1.png',
                                      QSize(240, 240))).setPos(1, 0)

        expected_scene.render(expected)

        display = SpargoDisplay()
        display.resize(348, 264)

        render_display(display, actual)
    assert display.ui.move_text.text() == 'to move'
    assert display.ui.black_count.text() == '0'
    assert display.ui.red_count.text() == ''
    assert display.ui.white_count.text() == '0'
    black_icon = display.black_pixmap.toImage()
    assert display.ui.black_count_pixmap.pixmap().toImage() == black_icon
    assert display.ui.player_pixmap.pixmap().toImage() == black_icon
    white_icon = display.white_pixmap.toImage()
    assert display.ui.white_count_pixmap.pixmap().toImage() == white_icon
def test_pieces(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_pieces') as (actual,
                                                               expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        expected.drawEllipse(90, 90, 60, 60)
        expected.setBrush(TicTacToeDisplay.player2_colour)
        expected.drawEllipse(90, 10, 60, 60)

        display = TicTacToeDisplay()
        board = TicTacToeState('''\
XO.
.X.
...
''')
        display.update_board(board)

        display.resize(324, 264)
        render_display(display, actual)

    player_pixmap = display.ui.player_pixmap.pixmap()
    assert player_pixmap.toImage() == display.player2_icon.toImage()
def test_draw(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_draw') as (actual, expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        expected.drawEllipse(10, 90, 60, 60)
        expected.drawEllipse(90, 170, 60, 60)
        expected.drawEllipse(170, 170, 60, 60)
        expected.drawEllipse(170, 10, 60, 60)
        expected.setBrush(TicTacToeDisplay.player2_colour)
        expected.drawEllipse(90, 10, 60, 60)
        expected.drawEllipse(90, 90, 60, 60)
        expected.drawEllipse(170, 90, 60, 60)
        expected.drawEllipse(10, 170, 60, 60)

        display = TicTacToeDisplay()
        display.resize(324, 264)

        display.update_board(display.start_state)
        board = TicTacToeState('''\
XOX
XOO
OXX
''')
        display.update_board(board)

        render_display(display, actual)
    assert display.ui.player_pixmap.pixmap() is None
    assert display.move_text.text() == 'draw'
def test_winner(pixmap_differ: PixmapDiffer):
    assert 1 == 1
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_winner') as (actual,
                                                               expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        expected.drawEllipse(90, 90, 60, 60)
        expected.drawEllipse(170, 170, 60, 60)
        expected.setBrush(TicTacToeDisplay.player2_colour)
        expected.drawEllipse(90, 10, 60, 60)
        expected.drawEllipse(170, 90, 60, 60)

        display = TicTacToeDisplay()
        display.resize(324, 264)

        board = TicTacToeState('''\
XO.
.XO
..X
''')
        display.update_board(board)

        assert not display.spaces[0][2].isVisible()
        expected_icon = display.player1_icon.toImage()
        assert display.ui.player_pixmap.pixmap().toImage() == expected_icon
        assert display.move_text.text() == 'wins'
        render_display(display, actual)
Beispiel #7
0
def test_update(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240, 'spargo_update') as (
            actual,
            expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SpargoDisplay.load_pixmap('board-1.png',
                                      QSize(240, 240))).setPos(1, 0)
        black_ball = SpargoDisplay.load_pixmap('ball-b-shadow-1.png',
                                               QSize(60, 60))

        expected_scene.addPixmap(black_ball).setPos(63, 166)
        expected_scene.render(expected)

        display = SpargoDisplay()

        display.resize(348, 264)
        display.update_board(SpargoState("""\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . . . 3

1 . B . . 1
  A C E G
>W
"""))

        render_display(display, actual)
    assert display.ui.black_count.text() == '1'
    assert display.ui.white_count.text() == '0'
Beispiel #8
0
def test_coordinates(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 200,
                                       'spline_coordinates') as (actual,
                                                                 expected):
        expected_scene = QGraphicsScene(0, 0, 240, 200)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png',
                                      QSize(160, 160))).setPos(36, 0)

        for i in range(7):
            add_text(expected_scene, str(7 - i), 15 + i % 2 * 10, i * 17 + 27,
                     10)
            add_text(expected_scene, chr(65 + i), i * 17 + 64,
                     178 - i % 2 * 10, 10)

        expected_scene.render(expected)

        display = SplineDisplay()
        display.resize(348, 224)

        display.show_coordinates = True

        render_display(display, actual)
def test_coordinates(pixmap_differ: PixmapDiffer):
    assert 1 == 1
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(200, 200,
                                       'tictactoe_coordinates') as (actual,
                                                                    expected):
        expected.fillRect(0, 0, 250, 200, TicTacToeDisplay.background_colour)
        expected.drawLine(50, 100, 200, 100)
        expected.drawLine(50, 150, 200, 150)
        expected.drawLine(100, 50, 100, 200)
        expected.drawLine(150, 50, 150, 200)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(106, 106, 37, 37)
        set_font_size(expected, 25)
        draw_text(expected, 75, 25, 'A')
        draw_text(expected, 125, 25, 'B')
        draw_text(expected, 175, 25, 'C')
        draw_text(expected, 25, 75, '1')
        draw_text(expected, 25, 125, '2')
        draw_text(expected, 25, 175, '3')

        display = TicTacToeDisplay()
        display.resize(276, 224)

        display.show_coordinates = True
        board = TicTacToeState('''\
  ABC
1 ...
2 .X.
3 ...
''')
        display.update_board(board)

        render_display(display, actual)
Beispiel #10
0
def test_hover_leave(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240,
                                       'spline_hover_leave') as (actual,
                                                                 expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png', QSize(240,
                                                           240))).setPos(1, 0)
        expected_scene.render(expected)

        display = SplineDisplay()
        height = 0
        row = 1
        column = 2
        piece_item = display.item_levels[height][row][column]

        display.resize(348, 264)
        display.grab()  # Force layout to recalculate.

        display.on_hover_enter(piece_item)
        display.on_hover_leave(piece_item)

        render_display(display, actual)
Beispiel #11
0
def test_pieces(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(280, 240,
                                       'connect4_pieces') as (actual,
                                                              expected):
        draw_grid(expected)
        expected.setBrush(Connect4Display.player1_colour)
        expected.drawEllipse(125, 205, 30, 30)
        expected.drawEllipse(165, 205, 30, 30)
        expected.setBrush(Connect4Display.player2_colour)
        expected.drawEllipse(125, 165, 30, 30)

        display = Connect4Display()
        board = Connect4State('''\
.......
.......
.......
.......
...O...
...XX..
''')
        display.resize(372, 264)
        display.update_board(board)

        render_display(display, actual)
Beispiel #12
0
def test_hover_enter_red(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(
            240, 240, 'sandbox_hover_enter_red') as (actual, expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SandboxDisplay.load_pixmap('board-1.png',
                                       QSize(240, 240))).setPos(1, 0)
        red_ball = SandboxDisplay.load_pixmap('ball-r-shadow-1.png',
                                              QSize(60, 60))

        new_piece = expected_scene.addPixmap(red_ball)
        new_piece.setPos(115, 114)
        new_piece.setOpacity(0.5)
        expected_scene.render(expected)

        display = SandboxDisplay()
        display.selected_move_type = MoveType.RED
        height = 0
        row = 1
        column = 2
        piece_item = display.item_levels[height][row][column]

        display.resize(348, 264)
        display.grab()  # Force layout to recalculate.

        display.on_hover_enter(piece_item)

        render_display(display, actual)
def test_piece_hover_enter(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size, size, 'tictactoe_piece_hover_enter') as (actual, expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        colour = QColor(TicTacToeDisplay.player2_colour)
        expected.setBrush(colour)
        colour.setAlpha(127)
        expected.setBrush(colour)
        colour.setRgb(0, 0, 0, 127)
        pen = QPen(colour)
        expected.setPen(pen)
        expected.drawEllipse(90, 10, 60, 60)

        display = TicTacToeDisplay()

        board = TicTacToeState('''\
X..
...
...
''')
        display.resize(324, 264)
        display.ui.game_display.grab()
        display.update_board(board)
        display.on_hover_enter(display.spaces[0][1])

        render_display(display, actual)
Beispiel #14
0
def test_text(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(
            300, 240, 'scaled_radio_button_text') as (actual, expected):
        ex_widget = QWidget()
        ex_layout = QVBoxLayout(ex_widget)
        ex_radio1 = QRadioButton('Lorem ipsum')
        ex_radio2 = QRadioButton('Lorem ipsum')
        ex_font = ex_radio1.font()
        if ex_font.family() == 'Sans Serif':
            # Fonts are different on GitHub actions.
            big_font_size = 27
            small_font_size = 27
            ex_radio1.setStyleSheet('QRadioButton::indicator {width: 27} '
                                    'QRadioButton {spacing: 13}')
            ex_radio2.setStyleSheet('QRadioButton::indicator {width: 27} '
                                    'QRadioButton {spacing: 13}')
        else:
            big_font_size = 29
            small_font_size = 28
            ex_radio1.setStyleSheet('QRadioButton::indicator {width: 29} '
                                    'QRadioButton {spacing: 14}')
            ex_radio2.setStyleSheet('QRadioButton::indicator {width: 28} '
                                    'QRadioButton {spacing: 14}')
        ex_font.setPointSize(big_font_size)
        ex_radio1.setFont(ex_font)
        ex_font.setPointSize(small_font_size)
        ex_radio2.setFont(ex_font)
        ex_size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        ex_radio1.setSizePolicy(ex_size_policy)
        ex_radio2.setSizePolicy(ex_size_policy)
        ex_layout.addWidget(ex_radio1)
        ex_layout.addWidget(ex_radio2)
        ex_layout.setStretch(0, 4)
        ex_layout.setStretch(1, 1)

        ex_widget.resize(300, 240)
        expected.drawPixmap(0, 0, ex_widget.grab())

        widget = QWidget()
        layout = QVBoxLayout(widget)
        radio1 = ScaledRadioButton('Lorem ipsum')
        radio2 = ScaledRadioButton('Lorem ipsum')
        size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        radio1.setSizePolicy(size_policy)
        radio2.setSizePolicy(size_policy)
        layout.addWidget(radio1)
        layout.addWidget(radio2)
        layout.setStretch(0, 4)
        layout.setStretch(1, 1)

        widget.resize(300, 240)

        actual.drawPixmap(0, 0, widget.grab())
Beispiel #15
0
def test_text(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(300, 240,
                                       'scaled_label_text') as (actual,
                                                                expected):
        ex_widget = QWidget()
        ex_layout = QVBoxLayout(ex_widget)
        ex_label1 = QLabel('Lorem ipsum')
        ex_label2 = QLabel('Lorem ipsum')
        ex_font = ex_label1.font()
        if ex_font.family() == 'Sans Serif':
            # Fonts are different on GitHub actions.
            big_font_size = 32
            small_font_size = 27
        else:
            big_font_size = 35
            small_font_size = 28
        ex_font.setPointSize(big_font_size)
        ex_label1.setFont(ex_font)
        ex_font.setPointSize(small_font_size)
        ex_label2.setFont(ex_font)
        ex_size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        ex_label1.setSizePolicy(ex_size_policy)
        ex_label1.setAlignment(Qt.AlignBottom)
        ex_label2.setAlignment(Qt.AlignTop)
        ex_label2.setSizePolicy(ex_size_policy)
        ex_layout.addWidget(ex_label1)
        ex_layout.addWidget(ex_label2)
        ex_layout.setStretch(0, 4)
        ex_layout.setStretch(1, 1)

        ex_widget.resize(300, 240)
        expected.drawPixmap(0, 0, ex_widget.grab())

        widget = QWidget()
        layout = QVBoxLayout(widget)
        label1 = ScaledLabel('Lorem ipsum')
        label2 = ScaledLabel('Lorem ipsum')
        size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        label1.setSizePolicy(size_policy)
        label2.setSizePolicy(size_policy)
        label1.setScaledContents(True)
        label2.setScaledContents(True)
        label1.setAlignment(Qt.AlignBottom)
        label2.setAlignment(Qt.AlignTop)
        layout.addWidget(label1)
        layout.addWidget(label2)
        layout.setStretch(0, 4)
        layout.setStretch(1, 1)

        widget.resize(300, 240)

        actual.drawPixmap(0, 0, widget.grab())
def test_piece_hover_leave(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size, size, 'tictactoe_piece_hover_leave') as (actual, expected):
        draw_square_grid(expected)

        display = TicTacToeDisplay()
        display.resize(324, 264)
        display.ui.game_display.grab()
        display.on_hover_enter(display.spaces[0][1])
        display.on_hover_leave(display.spaces[0][1])

        render_display(display, actual)
Beispiel #17
0
def test_pixmap(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(300, 240,
                                       'scaled_label_pixmap') as (actual,
                                                                  expected):
        ex_widget = QWidget()
        ex_widget.resize(300, 240)
        expected.drawPixmap(0, 0, ex_widget.grab())
        icon = GridDisplay.create_icon(GridDisplay.player2_colour)

        expected.drawPixmap(
            0, 0,
            icon.scaled(120, 120, Qt.KeepAspectRatio, Qt.SmoothTransformation))
        expected.drawPixmap(
            110, 120,
            icon.scaled(80, 80, Qt.KeepAspectRatio, Qt.SmoothTransformation))
        expected.drawPixmap(
            260, 200,
            icon.scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation))

        widget = QWidget()
        layout = QVBoxLayout(widget)
        label1 = ScaledLabel()
        label2 = ScaledLabel()
        label3 = ScaledLabel()
        label1.setPixmap(icon)
        label2.setPixmap(icon)
        label3.setPixmap(icon)
        size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        label1.setSizePolicy(size_policy)
        label2.setSizePolicy(size_policy)
        label3.setSizePolicy(size_policy)
        label1.setScaledContents(True)
        label2.setScaledContents(True)
        label3.setScaledContents(True)
        label1.setAlignment(Qt.AlignLeft)
        label2.setAlignment(Qt.AlignCenter)
        label3.setAlignment(Qt.AlignRight)
        layout.addWidget(label1)
        layout.addWidget(label2)
        layout.addWidget(label3)
        layout.setStretch(0, 3)
        layout.setStretch(1, 2)
        layout.setStretch(2, 1)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        widget.resize(300, 240)

        actual.drawPixmap(0, 0, widget.grab())
def test_hover_enter_remove(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(
            240, 240, 'spook_hover_enter_remove') as (actual, expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SpookDisplay.load_pixmap('board-1.png', QSize(240,
                                                          240))).setPos(1, 0)
        white_ball = SpookDisplay.load_pixmap('ball-w-shadow-1.png',
                                              QSize(60, 60))
        red_ball = SpookDisplay.load_pixmap('ball-r-shadow-1.png',
                                            QSize(60, 60))
        black_ball = SpookDisplay.load_pixmap('ball-b-shadow-1.png',
                                              QSize(60, 60))

        black_piece = expected_scene.addPixmap(black_ball)
        black_piece.setPos(115, 114)
        black_piece.setOpacity(0.5)
        red_piece = expected_scene.addPixmap(red_ball)
        red_piece.setPos(63, 62)
        white_piece = expected_scene.addPixmap(white_ball)
        white_piece.setPos(115, 62)
        expected_scene.render(expected)

        display = SpookDisplay()
        display.update_board(
            SpookState('''\
  A C E G
7 . . . . 7

5 . R W . 5

3 . . B . 3

1 . . . . 1
  A C E G
>R(R,B)
'''))
        height = 0
        row = 1
        column = 2
        piece_item = display.item_levels[height][row][column]

        display.resize(348, 264)
        display.grab()  # Force layout to recalculate.

        display.on_hover_enter(piece_item)

        render_display(display, actual)
Beispiel #19
0
def test_double_update(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240,
                                       'spline_double_update') as (actual,
                                                                   expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png', QSize(240,
                                                           240))).setPos(1, 0)
        white_ball = SplineDisplay.load_pixmap('ball-w-shadow-1.png',
                                               QSize(60, 60))
        black_ball = SplineDisplay.load_pixmap('ball-b-shadow-1.png',
                                               QSize(60, 60))

        expected_scene.addPixmap(black_ball).setPos(11, 10)
        expected_scene.addPixmap(white_ball).setPos(63, 10)
        expected_scene.addPixmap(black_ball).setPos(115, 62)
        expected_scene.render(expected)

        display = SplineDisplay()
        trigger_resize(display, 300, 240)
        display.update_board(
            SplineState("""\
  A C E G
7 W B . . 7

5 . . . W 5

3 . . . . 3

1 . . . . 1
  A C E G
"""))
        display.update_board(
            SplineState("""\
  A C E G
7 B W . . 7

5 . . B . 5

3 . . . . 3

1 . . . . 1
  A C E G
"""))

        display.resize(348, 264)

        render_display(display, actual)
def test_invalid_hover_enter(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size,
            size,
            'othello_invalid_hover_enter') as (actual, expected):

        display = OthelloDisplay()
        display.resize(324, 264)
        render_display(display, expected, is_closed=False)

        display.on_hover_enter(display.spaces[0][0])

        render_display(display, actual)
def test_start_tall(pixmap_differ: PixmapDiffer):
    size = 120
    with pixmap_differ.create_painters(size, size * 2,
                                       'tictactoe_start_tall') as (actual,
                                                                   expected):
        expected.fillRect(0, 0, size + 40, size * 2,
                          TicTacToeDisplay.background_colour)
        expected.drawLine(0, 100, 120, 100)
        expected.drawLine(0, 140, 120, 140)
        expected.drawLine(40, 60, 40, 180)
        expected.drawLine(80, 60, 80, 180)

        display = TicTacToeDisplay()
        display.resize(180, 264)
        render_display(display, actual)
def test_piece_click(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_piece_click') as (actual,
                                                                    expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)

        display = TicTacToeDisplay()
        display.resize(324, 264)
        display.ui.game_display.grab()

        display.on_click(display.spaces[0][0])

        render_display(display, actual)
def test_start_wide(pixmap_differ: PixmapDiffer):
    size = 240
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(size * 2, size,
                                       'tictactoe_start_wide') as (actual,
                                                                   expected):
        expected.fillRect(0, 0, size * 2 + 80, size,
                          TicTacToeDisplay.background_colour)
        expected.drawLine(120, 80, 360, 80)
        expected.drawLine(120, 160, 360, 160)
        expected.drawLine(200, 0, 200, 240)
        expected.drawLine(280, 0, 280, 240)

        display = TicTacToeDisplay()
        display.resize(612, 264)
        render_display(display, actual)
Beispiel #24
0
def test_second_level(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240,
                                       'spline_second_level') as (actual,
                                                                  expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png', QSize(240,
                                                           240))).setPos(1, 0)
        white_ball = SplineDisplay.load_pixmap('ball-w-shadow-1.png',
                                               QSize(60, 60))
        black_ball = SplineDisplay.load_pixmap('ball-b-shadow-1.png',
                                               QSize(60, 60))

        expected_scene.addPixmap(black_ball).setPos(11, 62)
        expected_scene.addPixmap(white_ball).setPos(63, 62)
        expected_scene.addPixmap(white_ball).setPos(11, 10)
        expected_scene.addPixmap(black_ball).setPos(63, 10)
        expected_scene.addPixmap(black_ball).setPos(37, 36)
        expected_scene.render(expected)

        display = SplineDisplay()
        display.update_board(
            SplineState("""\
  A C E G
7 W B . . 7

5 B W . . 5

3 . . . . 3

1 . . . . 1
  A C E G
   B D F
 6 B . . 6

 4 . . . 4

 2 . . . 2
   B D F
"""))

        display.resize(348, 264)

        render_display(display, actual)
Beispiel #25
0
def test_resize_narrow(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(120, 240,
                                       'spline_resize_narrow') as (actual,
                                                                   expected):
        expected_scene = QGraphicsScene(0, 0, 120, 240)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png',
                                      QSize(120, 123))).setPos(0, 59)

        expected_scene.render(expected)

        display = SplineDisplay()

        display.resize(204, 264)

        render_display(display, actual)
Beispiel #26
0
def test_hover_enter_leave(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(
            240, 240, 'sandbox_hover_enter_leave') as (actual, expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SandboxDisplay.load_pixmap('board-1.png',
                                       QSize(240, 240))).setPos(1, 0)
        white_ball = SandboxDisplay.load_pixmap('ball-w-shadow-1.png',
                                                QSize(60, 60))

        new_piece = expected_scene.addPixmap(white_ball)
        new_piece.setPos(115, 114)
        expected_scene.render(expected)

        display = SandboxDisplay()
        display.update_board(
            SandboxState('''\
  A C E G
7 . . . . 7

5 . . . . 5

3 . . W . 3

1 . . . . 1
  A C E G
'''))
        display.selected_move_type = MoveType.REMOVE
        height = 0
        row = 1
        column = 2
        piece_item = display.item_levels[height][row][column]

        display.resize(348, 264)
        display.grab()  # Force layout to recalculate.

        display.on_hover_enter(piece_item)
        display.on_hover_leave(piece_item)

        render_display(display, actual)
Beispiel #27
0
def test_empty(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240,
                                       'spline_empty') as (actual, expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png', QSize(240,
                                                           240))).setPos(1, 0)

        expected_scene.render(expected)

        display = SplineDisplay()

        display.resize(348, 264)

        render_display(display, actual)
    black_icon = SplineDisplay.load_pixmap('ball-b-shadow-1.png').toImage()
    assert display.ui.player_pixmap.pixmap().toImage() == black_icon
    assert display.ui.move_text.text() == 'to move'
def test_piece_hover_enter_mcts(pixmap_differ: PixmapDiffer):
    """ Don't display move options while MCTS player is thinking. """
    size = 240
    with pixmap_differ.create_painters(
            size, size,
            'tictactoe_piece_hover_enter_mcts') as (actual, expected):
        draw_square_grid(expected)

        display = TicTacToeDisplay()
        player = MctsPlayer(display.start_state, TicTacToeState.X_PLAYER)
        display.mcts_players = (player, )

        display.resize(324, 264)
        display.ui.game_display.grab()
        display.on_hover_enter(display.spaces[0][1])

        render_display(display, actual)
        display.close()
    assert display.move_text.text() == 'thinking'
    expected_icon = display.player1_icon.toImage()
    assert display.ui.player_pixmap.pixmap().toImage() == expected_icon
Beispiel #29
0
def test_first_level(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(240, 240,
                                       'spline_first_level') as (actual,
                                                                 expected):
        expected_scene = QGraphicsScene(0, 0, 240, 240)
        expected_scene.addPixmap(
            SplineDisplay.load_pixmap('board-1.png', QSize(240,
                                                           240))).setPos(1, 0)
        white_ball = SplineDisplay.load_pixmap('ball-w-shadow-1.png',
                                               QSize(60, 60))
        black_ball = SplineDisplay.load_pixmap('ball-b-shadow-1.png',
                                               QSize(60, 60))

        expected_scene.addPixmap(white_ball).setPos(11, 10)
        expected_scene.addPixmap(black_ball).setPos(63, 10)
        expected_scene.addPixmap(black_ball).setPos(167, 62)
        expected_scene.render(expected)

        display = SplineDisplay()
        display.update_board(
            SplineState("""\
  A C E G
7 W B . . 7

5 . . . B 5

3 . . . . 3

1 . . . . 1
  A C E G
"""))

        display.resize(348, 264)

        render_display(display, actual)
    white_icon = SplineDisplay.load_pixmap('ball-w-shadow-1.png').toImage()
    assert display.ui.player_pixmap.pixmap().toImage() == white_icon
def test_piece_hover_existing(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size, size,
            'tictactoe_piece_hover_existing') as (actual, expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)

        display = TicTacToeDisplay()

        board = TicTacToeState('''\
X..
...
...
''')
        display.update_board(board)
        display.resize(324, 264)
        display.ui.game_display.grab()
        display.on_hover_enter(display.spaces[0][0])

        render_display(display, actual)