示例#1
0
def test_load_time(qtbot):
    # Create Preferences dialog
    main = MainWindowMock(None)
    preferences = main.get_plugin(Plugins.Preferences)

    PLUGIN_REGISTRY.register_plugin(main, MainInterpreter)

    # Create page and measure time to do it
    t0 = time.time()
    preferences.open_dialog(None)
    load_time = time.time() - t0

    container = preferences.get_container()
    dlg = container.dialog
    widget = dlg.get_page()

    # Assert the combobox is populated with the found envs
    assert widget.cus_exec_combo.combobox.count() > 0

    # Assert load time is smaller than the one required to get envs
    # directly. This means we're using the cached envs instead
    assert load_time < GET_ENVS_TIME

    # Load time should be small too because we perform simple validations
    # on the page.
    assert load_time < 0.5
示例#2
0
    def __init__(self, parent):
        super().__init__(parent)
        self.default_style = None
        self.widgetlist = []
        self.thirdparty_plugins = []
        self.shortcut_data = []
        self.prefs_dialog_instance = None
        self._APPLICATION_TOOLBARS = MagicMock()

        self.console = Mock()

        # To provide command line options for plugins that need them
        sys_argv = [sys.argv[0]]  # Avoid options passed to pytest
        self._cli_options = get_options(sys_argv)[0]

        PLUGIN_REGISTRY.reset()
        PLUGIN_REGISTRY.sig_plugin_ready.connect(self.register_plugin)
        PLUGIN_REGISTRY.register_plugin(self, Preferences)

        # Load shortcuts for tests
        for context, name, __ in CONF.iter_shortcuts():
            self.shortcut_data.append((None, context, name, None, None))

        for attr in ['mem_status', 'cpu_status']:
            mock_attr = Mock()
            setattr(mock_attr, 'toolTip', lambda: '')
            setattr(mock_attr, 'setToolTip', lambda x: '')
            setattr(mock_attr, 'prefs_dialog_instance', lambda: '')
            setattr(self, attr, mock_attr)
示例#3
0
    def __init__(self):
        super().__init__(None)
        self.default_style = None
        self.widgetlist = []
        self.thirdparty_plugins = []
        self.shortcut_data = []
        self.prefs_dialog_instance = None
        self._APPLICATION_TOOLBARS = MagicMock()

        self.console = Mock()
        self.sig_main_interpreter_changed = Mock()

        PLUGIN_REGISTRY.reset()
        PLUGIN_REGISTRY.sig_plugin_ready.connect(self.register_plugin)
        PLUGIN_REGISTRY.register_plugin(self, Preferences)

        # Load shortcuts for tests
        for context, name, __ in CONF.iter_shortcuts():
            self.shortcut_data.append((None, context, name, None, None))

        for attr in ['mem_status', 'cpu_status']:
            mock_attr = Mock()
            setattr(mock_attr, 'toolTip', lambda: '')
            setattr(mock_attr, 'setToolTip', lambda x: '')
            setattr(mock_attr, 'prefs_dialog_instance', lambda: '')
            setattr(self, attr, mock_attr)
示例#4
0
文件: conftest.py 项目: andfoy/spyder
    def __init__(self, params):
        main_class, general_config_plugins, plugins = params
        self._main = main_class() if main_class else None
        if self._main is None:
            self._main = MainWindowMock()

        def set_prefs_size(self, size):
            pass

        def reset_spyder(self):
            pass

        def register_plugin(self, plugin_name, external=False):
            plugin = PLUGIN_REGISTRY.get_plugin(plugin_name)
            plugin._register()
            self.add_plugin(plugin, external=external)

        def get_plugin(self, plugin_name, error=False):
            if plugin_name in PLUGIN_REGISTRY:
                return PLUGIN_REGISTRY.get_plugin(plugin_name)
            return None

        def add_plugin(self, plugin, external=False):
            self._PLUGINS[plugin.CONF_SECTION] = plugin
            if external:
                self._EXTERNAL_PLUGINS[plugin.CONF_SECTION] = plugin
            else:
                self._INTERNAL_PLUGINS[plugin.CONF_SECTION] = plugin

        setattr(self._main, '_PLUGINS', OrderedDict())
        setattr(self._main, '_EXTERNAL_PLUGINS', OrderedDict())
        setattr(self._main, '_INTERNAL_PLUGINS', OrderedDict())
        setattr(self._main, 'register_plugin',
                types.MethodType(register_plugin, self._main))
        setattr(self._main, 'get_plugin',
                types.MethodType(get_plugin, self._main))
        setattr(self._main, 'add_plugin',
                types.MethodType(add_plugin, self._main))
        setattr(self._main, 'reset_spyder',
                types.MethodType(reset_spyder, self._main))
        setattr(self._main, 'set_prefs_size',
                types.MethodType(set_prefs_size, self._main))

        PLUGIN_REGISTRY.sig_plugin_ready.connect(self._main.register_plugin)
        PLUGIN_REGISTRY.register_plugin(self._main, Preferences)

        if plugins:
            for Plugin in plugins:
                if hasattr(Plugin, 'CONF_WIDGET_CLASS'):
                    for required in (Plugin.REQUIRES or []):
                        if required not in self._main._PLUGINS:
                            self._main._PLUGINS[required] = MagicMock()
                            self._main._INTERNAL_PLUGINS[
                                required] = MagicMock()

                    PLUGIN_REGISTRY.register_plugin(self._main, Plugin)
                else:
                    plugin = Plugin(self._main)
                    preferences = self._main.get_plugin(Plugins.Preferences)
                    preferences.register_plugin_preferences(plugin)
示例#5
0
def console_plugin(qtbot):
    """Console plugin fixture."""
    class MainWindowMock(QMainWindow):
        def __init__(self):
            super().__init__()
            self._INTERNAL_PLUGINS = {'internal_console': Console}

        def __getattr__(self, attr):
            if attr == '_PLUGINS':
                return {}
            elif attr != '_INTERNAL_PLUGINS':
                return Mock()
            else:
                return self.__dict__[attr]

    window = MainWindowMock()
    console_plugin = PLUGIN_REGISTRY.register_plugin(window,
                                                     Console,
                                                     external=False)
    console_plugin.start_interpreter({})
    window.setCentralWidget(console_plugin.get_widget())

    qtbot.addWidget(window)
    window.resize(640, 480)
    window.show()
    return console_plugin
示例#6
0
 def _hide_options_menus(self):
     """Hide options menu when menubar is pressed in macOS."""
     for plugin_name in PLUGIN_REGISTRY:
         plugin_instance = PLUGIN_REGISTRY.get_plugin(plugin_name)
         if isinstance(plugin_instance, SpyderDockablePlugin):
             if plugin_instance.CONF_SECTION == 'editor':
                 editorstack = self.editor.get_current_editorstack()
                 editorstack.menu.hide()
             else:
                 try:
                     # New API
                     plugin_instance.options_menu.hide()
                 except AttributeError:
                     # Old API
                     plugin_instance._options_menu.hide()
示例#7
0
def console_plugin(qtbot):
    """Console plugin fixture."""

    class MainWindowMock(QMainWindow):
        def __init__(self):
            super().__init__()

    window = MainWindowMock()
    console_plugin = PLUGIN_REGISTRY.register_plugin(
        window, Console, external=False)
    console_plugin.start_interpreter({})
    window.setCentralWidget(console_plugin.get_widget())

    qtbot.addWidget(window)
    window.resize(640, 480)
    window.show()
    return console_plugin
示例#8
0
def console_plugin(qtbot):
    """Console plugin fixture."""
    class MainWindowMock(QMainWindow):
        def __init__(self):
            # This avoids using the cli options passed to pytest
            sys_argv = [sys.argv[0]]
            self._cli_options = get_options(sys_argv)[0]
            super().__init__()

    window = MainWindowMock()
    console_plugin = PLUGIN_REGISTRY.register_plugin(window,
                                                     Console,
                                                     external=False)
    console_plugin.start_interpreter({})
    window.setCentralWidget(console_plugin.get_widget())

    qtbot.addWidget(window)
    window.resize(640, 480)
    window.show()
    return console_plugin
示例#9
0
    def __init__(self, parent, main_class,
                 general_config_plugins, plugins):
        super().__init__(parent)
        self._main = main_class(self) if main_class else None
        if self._main is None:
            self._main = MainWindowMock(self)

        def set_prefs_size(self, size):
            pass

        def reset_spyder(self):
            pass

        def register_plugin(self, plugin_name, external=False):
            plugin = PLUGIN_REGISTRY.get_plugin(plugin_name)
            plugin._register()

        def get_plugin(self, plugin_name, error=False):
            if plugin_name in PLUGIN_REGISTRY:
                return PLUGIN_REGISTRY.get_plugin(plugin_name)
            return None

        setattr(self._main, 'register_plugin',
                types.MethodType(register_plugin, self._main))
        setattr(self._main, 'get_plugin',
                types.MethodType(get_plugin, self._main))
        setattr(self._main, 'reset_spyder',
                types.MethodType(reset_spyder, self._main))
        setattr(self._main, 'set_prefs_size',
                types.MethodType(set_prefs_size, self._main))

        PLUGIN_REGISTRY.reset()
        PLUGIN_REGISTRY.sig_plugin_ready.connect(self._main.register_plugin)
        PLUGIN_REGISTRY.register_plugin(self._main, Preferences)

        if plugins:
            for Plugin in plugins:
                if hasattr(Plugin, 'CONF_WIDGET_CLASS'):
                    for required in (Plugin.REQUIRES or []):
                        if required not in PLUGIN_REGISTRY:
                            PLUGIN_REGISTRY.plugin_registry[required] = MagicMock()

                    PLUGIN_REGISTRY.register_plugin(self._main, Plugin)
                else:
                    plugin = Plugin(self._main)
                    preferences = self._main.get_plugin(Plugins.Preferences)
                    preferences.register_plugin_preferences(plugin)
示例#10
0
 def get_plugin(self, plugin_name):
     if plugin_name in PLUGIN_REGISTRY:
         return PLUGIN_REGISTRY.get_plugin(plugin_name)
示例#11
0
 def register_plugin(self, plugin_name, external=False):
     plugin = PLUGIN_REGISTRY.get_plugin(plugin_name)
     plugin._register()
示例#12
0
 def get_plugin(self, plugin_name, error=False):
     if plugin_name in PLUGIN_REGISTRY:
         return PLUGIN_REGISTRY.get_plugin(plugin_name)
     return None
示例#13
0
文件: conftest.py 项目: andfoy/spyder
 def register_plugin(self, plugin_name, external=False):
     plugin = PLUGIN_REGISTRY.get_plugin(plugin_name)
     plugin._register(omit_conf=True)
     self.add_plugin(plugin, external=external)