Exemple #1
0
def projects(qtbot, mocker):
    """Projects plugin fixture."""
    class MainWindowMock(object):
        def __getattr__(self, attr):
            if attr == 'ipyconsole' or attr == 'editor':
                return None
            else:
                return Mock()

    # Create plugin
    projects = Projects(parent=None)

    # Patching necessary to test visible_if_project_open
    projects.shortcut = None
    mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                        'install_tab_event_filter')
    mocker.patch.object(projects, 'toggle_view_action')
    projects.create_dockwidget()

    # This can only be done at this point
    projects.main = MainWindowMock()

    qtbot.addWidget(projects)
    projects.show()
    return projects
Exemple #2
0
def projects(qtbot, mocker):
    """Projects plugin fixture."""

    class MainWindowMock(object):
        def __getattr__(self, attr):
            if attr == 'ipyconsole' or attr == 'editor':
                return None
            else:
                return Mock()

    # Create plugin
    projects = Projects(parent=None)

    # Patching necessary to test visible_if_project_open
    projects.shortcut = None
    mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                        'install_tab_event_filter')
    mocker.patch.object(projects, 'toggle_view_action')
    projects.create_dockwidget()

    # This can only be done at this point
    projects.main = MainWindowMock()

    qtbot.addWidget(projects)
    projects.show()
    return projects
Exemple #3
0
def projects(qtbot, mocker):
    """Projects plugin fixture."""

    class EditorMock(object):
        def get_open_filenames(self):
            # Patch this with mocker to return a different value.
            # See test_set_project_filenames_in_close_project.
            return []

        def __getattr__(self, attr):
            return Mock()

    class MainWindowMock(object):
        editor = EditorMock()

        def __getattr__(self, attr):
            if attr == 'ipyconsole':
                return None
            else:
                return Mock()

    # Create plugin
    projects = Projects(parent=None)
    projects._setup()

    # Patching necessary to test visible_if_project_open
    projects.shortcut = None
    mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                        'install_tab_event_filter')
    mocker.patch.object(projects, '_toggle_view_action')
    projects._create_dockwidget()

    # This can only be done at this point
    projects.main = MainWindowMock()

    qtbot.addWidget(projects)
    projects.show()
    return projects
Exemple #4
0
def projects(qtbot, mocker):
    """Projects plugin fixture."""
    class EditorMock(MagicMock):
        def get_open_filenames(self):
            # Patch this with mocker to return a different value.
            # See test_set_project_filenames_in_close_project.
            return []

    class MainWindowProjectsMock(MainWindowMock):
        def __getattr__(self, attr):
            if attr == 'ipyconsole':
                return None
            try:
                super().__getattr__(attr)
            except AttributeError:
                return MagicMock()

    # Main window mock
    main_window = MainWindowProjectsMock()

    # Create plugin
    projects = Projects(configuration=CONF)
    projects.initialize()

    projects.editor = EditorMock()

    projects.sig_switch_to_plugin_requested.connect(
        lambda x, y: projects.change_visibility(True))

    # This can only be done at this point
    projects._main = main_window

    # Patching necessary to test visible_if_project_open
    projects.shortcut = None
    mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                        'install_tab_event_filter')
    qtbot.addWidget(projects.get_widget())
    return projects
Exemple #5
0
def projects(qtbot, mocker):
    """Projects plugin fixture."""

    class EditorMock(object):
        def get_open_filenames(self):
            # Patch this with mocker to return a different value.
            # See test_set_project_filenames_in_close_project.
            return []

        def __getattr__(self, attr):
            return Mock()

    class MainWindowMock(object):
        editor = EditorMock()

        def __getattr__(self, attr):
            if attr == 'ipyconsole':
                return None
            else:
                return Mock()

    # Create plugin
    projects = Projects(parent=None)

    # Patching necessary to test visible_if_project_open
    projects.shortcut = None
    mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                        'install_tab_event_filter')
    mocker.patch.object(projects, 'toggle_view_action')
    projects.create_dockwidget()

    # This can only be done at this point
    projects.main = MainWindowMock()

    qtbot.addWidget(projects)
    projects.show()
    return projects
Exemple #6
0
def projects(qtbot, mocker, request, tmpdir):
    """Projects plugin fixture."""
    use_cli_project = request.node.get_closest_marker('use_cli_project')

    class EditorMock(MagicMock):
        def get_open_filenames(self):
            # Patch this with mocker to return a different value.
            # See test_set_project_filenames_in_close_project.
            return []

    class MainWindowProjectsMock(MainWindowMock):
        def __init__(self, parent):
            # This avoids using the cli options passed to pytest
            sys_argv = [sys.argv[0]]
            self._cli_options = get_options(sys_argv)[0]
            super().__init__(parent)

        def __getattr__(self, attr):
            if attr == 'ipyconsole':
                return None
            try:
                super().__getattr__(attr)
            except AttributeError:
                return MagicMock()

        def get_initial_working_directory(self):
            return str(tmpdir)

    # Main window mock
    main_window = MainWindowProjectsMock(None)
    if use_cli_project:
        tmpdir.mkdir('cli_project_dir')

        # This allows us to test relative paths passed on the command line
        main_window._cli_options.project = 'cli_project_dir'

    # Create plugin
    projects = Projects(configuration=CONF)
    projects.initialize()

    projects.editor = EditorMock()

    projects.sig_switch_to_plugin_requested.connect(
        lambda x, y: projects.change_visibility(True))

    # This can only be done at this point
    projects._main = main_window

    # Patching necessary to test visible_if_project_open
    projects.shortcut = None
    mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                        'install_tab_event_filter')
    yield projects
    projects.get_container().close()
    projects.on_close()
Exemple #7
0
def projects(qtbot):
    """Projects plugin fixture"""
    projects = Projects(parent=None, testing=True)
    qtbot.addWidget(projects)
    return projects