Skip to content

Commit

Permalink
Fix console import menu and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 15, 2016
1 parent df23468 commit 8047a56
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/console/console.py
Expand Up @@ -31,6 +31,7 @@
from .console_settings import optionsDialog
from qgis.core import QgsApplication, QgsContextHelp
from qgis.gui import QgsFilterLineEdit
from functools import partial

import sys

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -409,8 +412,7 @@ def __init__(self, parent=None):
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)
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions 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()

0 comments on commit 8047a56

Please sign in to comment.