Esempio n. 1
0
def test_pgzero_stop_game_no_runner():
    """
    If the game is cancelled before the child process is created ensure
    nothing breaks and the UI is reset.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = None
    pm.stop_game()
    view.remove_python_runner.assert_called_once_with()
Esempio n. 2
0
def test_pgzero_stop_game_no_runner():
    """
    If the game is cancelled before the child process is created ensure
    nothing breaks and the UI is reset.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = None
    pm.stop_game()
    view.remove_python_runner.assert_called_once_with()
Esempio n. 3
0
def test_pgzero_play_toggle_on_cancelled():
    """
    Ensure the button states are correct if playing an unsaved script is
    cancelled before the process is allowed to start.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = None
    pm.run_game = mock.MagicMock()
    pm.play_toggle(None)
    pm.run_game.assert_called_once_with()
    slot = pm.view.button_bar.slots["play"]
    assert slot.setIcon.call_count == 0
Esempio n. 4
0
def test_pgzero_play_toggle_on_cancelled():
    """
    Ensure the button states are correct if playing an unsaved script is
    cancelled before the process is allowed to start.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = None
    pm.run_game = mock.MagicMock()
    pm.play_toggle(None)
    pm.run_game.assert_called_once_with()
    slot = pm.view.button_bar.slots['play']
    assert slot.setIcon.call_count == 0
Esempio n. 5
0
def test_pgzero_stop_game():
    """
    Check that the child process is killed, the runner cleaned up and UI
    is reset.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    mock_runner = mock.MagicMock()
    pm.runner = mock_runner
    pm.stop_game()
    mock_runner.process.kill.assert_called_once_with()
    mock_runner.process.waitForFinished.assert_called_once_with()
    assert pm.runner is None
    view.remove_python_runner.assert_called_once_with()
Esempio n. 6
0
def test_pgzero_stop_game():
    """
    Check that the child process is killed, the runner cleaned up and UI
    is reset.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    mock_runner = mock.MagicMock()
    pm.runner = mock_runner
    pm.stop_game()
    mock_runner.process.kill.assert_called_once_with()
    mock_runner.process.waitForFinished.assert_called_once_with()
    assert pm.runner is None
    view.remove_python_runner.assert_called_once_with()
Esempio n. 7
0
def test_pgzero_play_toggle_off():
    """
    Check the handler for clicking play stops the process and reverts the UI
    state.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = True
    pm.stop_game = mock.MagicMock()
    pm.play_toggle(None)
    pm.stop_game.assert_called_once_with()
    slot = pm.view.button_bar.slots['play']
    assert slot.setIcon.call_count == 1
    slot.setText.assert_called_once_with('Play')
    slot.setToolTip.assert_called_once_with('Play your Pygame Zero game.')
Esempio n. 8
0
def test_pgzero_play_toggle_off():
    """
    Check the handler for clicking play stops the process and reverts the UI
    state.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = True
    pm.stop_game = mock.MagicMock()
    pm.play_toggle(None)
    pm.stop_game.assert_called_once_with()
    slot = pm.view.button_bar.slots['play']
    assert slot.setIcon.call_count == 1
    slot.setText.assert_called_once_with('Play')
    slot.setToolTip.assert_called_once_with('Play your Pygame Zero game.')
Esempio n. 9
0
def test_pgzero_play_toggle_on():
    """
    Check the handler for clicking play starts the new process and updates the
    UI state.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = None

    def runner(pm=pm):
        pm.runner = True

    pm.run_game = mock.MagicMock(side_effect=runner)
    pm.play_toggle(None)
    pm.run_game.assert_called_once_with()
    slot = pm.view.button_bar.slots['play']
    assert slot.setIcon.call_count == 1
    slot.setText.assert_called_once_with('Stop')
    slot.setToolTip.assert_called_once_with('Stop your Pygame Zero game.')
Esempio n. 10
0
def test_pgzero_play_toggle_on():
    """
    Check the handler for clicking play starts the new process and updates the
    UI state.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.runner = None

    def runner(pm=pm):
        pm.runner = True

    pm.run_game = mock.MagicMock(side_effect=runner)
    pm.play_toggle(None)
    pm.run_game.assert_called_once_with()
    slot = pm.view.button_bar.slots['play']
    assert slot.setIcon.call_count == 1
    slot.setText.assert_called_once_with('Stop')
    slot.setToolTip.assert_called_once_with('Stop your Pygame Zero game.')