Example #1
0
def test_pgzero_run_game():
    """
    Ensure that running the game launches the process as expected.
    """
    editor = mock.MagicMock()
    editor.envars = [
        ['name', 'value'],
    ]
    view = mock.MagicMock()
    view.current_tab.path = '/foo'
    view.current_tab.isModified.return_value = True
    mock_runner = mock.MagicMock()
    view.add_python3_runner.return_value = mock_runner
    pm = PyGameZeroMode(editor, view)
    pm.workspace_dir = mock.MagicMock(return_value='/bar')
    with mock.patch('builtins.open') as oa, \
            mock.patch('mu.modes.pygamezero.write_and_flush'):
        pm.run_game()
        oa.assert_called_once_with('/foo', 'w', newline='')
    py_args = ['-m', 'pgzero']
    view.add_python3_runner.assert_called_once_with('/foo',
                                                    '/bar',
                                                    interactive=False,
                                                    envars=editor.envars,
                                                    python_args=py_args)
    mock_runner.process.waitForStarted.assert_called_once_with()
Example #2
0
def test_pgzero_show_sounds():
    """
    The view is called to run the OS's file explorer for the given sounds path.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.show_sounds(None)
    sounds_dir = os.path.join(pm.workspace_dir(), 'sounds')
    view.open_directory_from_os.assert_called_once_with(sounds_dir)
Example #3
0
def test_pgzero_show_sounds():
    """
    The view is called to run the OS's file explorer for the given sounds path.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PyGameZeroMode(editor, view)
    pm.show_sounds(None)
    sounds_dir = os.path.join(pm.workspace_dir(), 'sounds')
    view.open_directory_from_os.assert_called_once_with(sounds_dir)
Example #4
0
def test_pgzero_show_music_no_file():
    """
    Run the OS file explorer for the workspace if no file is current.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.current_tab = None
    pm = PyGameZeroMode(editor, view)
    pm.show_music(None)
    music_dir = os.path.join(pm.workspace_dir(), "music")
    view.open_directory_from_os.assert_called_once_with(music_dir)
Example #5
0
def test_pgzero_run_game():
    """
    Ensure that running the game launches the process as expected.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.current_tab.path = '/foo'
    view.current_tab.isModified.return_value = True
    mock_runner = mock.MagicMock()
    view.add_python3_runner.return_value = mock_runner
    pm = PyGameZeroMode(editor, view)
    pm.workspace_dir = mock.MagicMock(return_value='/bar')
    with mock.patch('builtins.open') as oa, \
            mock.patch('mu.modes.pygamezero.write_and_flush'):
        pm.run_game()
        oa.assert_called_once_with('/foo', 'w', newline='')
    view.add_python3_runner.assert_called_once_with('/foo', '/bar',
                                                    interactive=False,
                                                    runner='pgzrun')
    mock_runner.process.waitForStarted.assert_called_once_with()
Example #6
0
def test_pgzero_run_game():
    """
    Ensure that running the game launches the process as expected.
    """
    editor = mock.MagicMock()
    editor.envars = [
        ['name', 'value'],
    ]
    view = mock.MagicMock()
    view.current_tab.path = '/foo'
    view.current_tab.isModified.return_value = True
    mock_runner = mock.MagicMock()
    view.add_python3_runner.return_value = mock_runner
    pm = PyGameZeroMode(editor, view)
    pm.workspace_dir = mock.MagicMock(return_value='/bar')
    pm.run_game()
    editor.save_tab_to_file.called_once_with(view.current_tab)
    py_args = ['-m', 'pgzero']
    view.add_python3_runner.assert_called_once_with('/foo',
                                                    '/bar',
                                                    interactive=False,
                                                    envars=editor.envars,
                                                    python_args=py_args)
    mock_runner.process.waitForStarted.assert_called_once_with()