svir.test package

Submodules

svir.test.qgis_interface module

InaSAFE Disaster risk assessment tool developed by AusAid - QGIS plugin implementation.

Contact : ole.moller.nielsen@gmail.com

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.

Note

This source code was copied from the ‘postgis viewer’ application with original authors: Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org

class svir.test.qgis_interface.QgisInterface(canvas)[source]

Bases: PyQt4.QtCore.QObject

Class to expose qgis objects and functions to plugins.

This class is here for enabling us to run unit tests only, so most methods are simply stubs.

activeLayer()[source]

Get pointer to the active layer (layer selected in the legend).

addDockWidget(area, dock_widget)[source]

Add a dock widget to the main window.

Parameters:
  • area – Where in the ui the dock should be placed.
  • dock_widget (QDockWidget) – A dock widget to add to the UI.
addLayer(layer)[source]

Handle a layer being added to the registry so it shows up in canvas.

Parameters:layer – list<QgsMapLayer> list of map layers that were added
addLayers(layers)[source]

Handle layers being added to the registry so they show up in canvas.

Parameters:layers – list<QgsMapLayer> list of map layers that were added

Note

The QgsInterface api does not include this method, it is added here as a helper to facilitate testing.

addRasterLayer(path, base_name)[source]

Add a raster layer given a raster layer file name

Parameters:
  • path (str) – Path to layer.
  • base_name (str) – Base name for layer.
addToolBar(name)[source]

Add toolbar with specified name.

Parameters:name (str) – Name for the toolbar.
addToolBarIcon(action)[source]

Add an icon to the plugins toolbar.

Parameters:action (QAction) – Action to add to the toolbar.
addVectorLayer(path, base_name, provider_key)[source]

Add a vector layer.

Parameters:
  • path (str) – Path to layer.
  • base_name (str) – Base name for layer.
  • provider_key (str) – Provider key e.g. ‘ogr’
currentLayerChanged
layerSavedAs
layers()[source]
legendInterface()[source]

Get the legend.

See also discussion at:

https://github.com/AIFDR/inasafe/pull/924/

Implementation added for version 3.2.

mainWindow()[source]

Return a pointer to the main window.

In case of QGIS it returns an instance of QgisApp.

mapCanvas()[source]

Return a pointer to the map canvas.

messageBar()[source]

Get the message bar.

New in version 3.2.

Returns:A QGIS message bar instance
Return type:QgsMessageBar
newProject()[source]

Create new project.

next()[source]
removeAllLayers()[source]

Remove layers from the canvas before they get deleted.

Note

This is NOT part of the QGisInterface API but is needed to support QgsMapLayerRegistry.removeAllLayers().

removeToolBarIcon(action)[source]

Remove an action (icon) from the plugin toolbar.

Parameters:action (QAction) – Action to add to the toolbar.
setActiveLayer(layer)[source]

Set the currently active layer in the legend. :param layer: Layer to make active. :type layer: QgsMapLayer, QgsVectorLayer, QgsRasterLayer

zoomFull()[source]

Zoom to the map full extent.

zoomToActiveLayer()[source]

Zoom to extent of active layer.

zoomToNext()[source]

Zoom to next view extent.

zoomToPrevious()[source]

Zoom to previous view extent.

svir.test.qgis_legend_interface module

Mock like implementation for the QgsLegendInterface - used for testing.

class svir.test.qgis_legend_interface.QgisLegend(canvas)[source]

A fake QgsLegendInterface with minimal implementation.

isLayerVisible(layer)[source]

Fake implementation for QgisLegendInterface.isLayerVisible.

Since this is a fake interface pretending to be a real running QGIS app and we do not have a legend, we work on the premise that if a layer is in the canvas, it is also in the (fake) legend.

Parameters:layer (QgsMapLayer) – A QgsMapLayer that we want to determine if it is visible or not.
Returns:Hard coded to always return true if the layer is in the canvas!
Return type:bool
layers()[source]

Fake implementation for QgisLegendInterface.layers().

Returns:A list of QgsMapLayers - one per layer present in the map layer list will be returned.
Return type:list
setLayerVisible(layer, visibility)[source]

Fake implementation for QgisLegendInterface.setLayerVisible.

Since this is a fake interface pretending to be a real running QGIS app and we do not have a legend, we work on the premise that the layer is in the fake legend and we toggle the visibility.

Parameters:
  • layer (QgsMapLayer) – A QgsMapLayer that we want to set visible.
  • visibility (bool) – A boolean to set the layer visible or not.

svir.test.utilities module

Common functionality used by regression tests.

svir.test.utilities.get_qgis_app()[source]

Start one QGIS application to test against.

Returns:Handle to QGIS app, canvas, iface and parent. If there are any errors the tuple members will be returned as None.
Return type:(QgsApplication, CANVAS, IFACE, PARENT)

If QGIS is already running the handle to that app will be returned.

Module contents