diff --git a/python/console/console.py b/python/console/console.py index 25376325534..3233273bca0 100644 --- a/python/console/console.py +++ b/python/console/console.py @@ -31,6 +31,7 @@ from .console_editor import EditorTabWidget from .console_settings import optionsDialog from qgis.core import QgsApplication, QgsContextHelp from qgis.gui import QgsFilterLineEdit +from functools import partial import sys @@ -58,6 +59,8 @@ def show_console(): QgsContextHelp.run("PythonConsole") settings.setValue('pythonConsole/contextHelpOnFirstLaunch', False) + return _console + _console_output = None # hook for python console so all output will be redirected @@ -409,8 +412,7 @@ class PythonConsoleWidget(QWidget): self.classMenu = QMenu() for (title, icon), commands in default_command.items(): action = self.classMenu.addAction(icon, title) - action.triggered.connect( - lambda commands=commands: self.shell.commandConsole(commands)) + action.triggered.connect(partial(self.shell.commandConsole, commands)) cM = self.toolBar.widgetForAction(self.actionClass) cM.setMenu(self.classMenu) diff --git a/tests/src/python/CMakeLists.txt b/tests/src/python/CMakeLists.txt index 8190aff3cf1..b1623e0f035 100644 --- a/tests/src/python/CMakeLists.txt +++ b/tests/src/python/CMakeLists.txt @@ -75,6 +75,7 @@ ADD_PYTHON_TEST(PyQgsVirtualLayerProvider test_provider_virtual.py) ADD_PYTHON_TEST(PyQgsVirtualLayerDefinition test_qgsvirtuallayerdefinition.py) ADD_PYTHON_TEST(PyQgsLayerDefinition test_qgslayerdefinition.py) ADD_PYTHON_TEST(PyQgsWFSProvider test_provider_wfs.py) +ADD_PYTHON_TEST(PyQgsConsole test_console.py) IF (NOT WIN32) ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py) diff --git a/tests/src/python/test_console.py b/tests/src/python/test_console.py new file mode 100644 index 00000000000..decaf120882 --- /dev/null +++ b/tests/src/python/test_console.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +"""QGIS Unit tests for the console + +.. note:: This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +""" +__author__ = 'Matthias Kuhn' +__date__ = '15.4.2016' +__copyright__ = 'Copyright 2015, The QGIS Project' +# This will get replaced with a git SHA1 when you do a git archive +__revision__ = '$Format:%H$' + +import qgis # NOQA + +from qgis.testing import unittest, start_app +from console import console + +start_app() + + +class TestConsole(unittest.TestCase): + + def test_show_console(self): + my_console = console.show_console() + my_console_widget = my_console.console + + for action in my_console_widget.classMenu.actions(): + action.trigger() + + +if __name__ == "__main__": + unittest.main()