Module: safe_qgis.utilities_test

Helper module for gui test suite

class safe_qgis.utilities_test.RedirectStdStreams(stdout=None, stderr=None)[source]

Context manager for redirection of stdout and stderr

This is from http://stackoverflow.com/questions/6796492/ python-temporarily-redirect-stdout-stderr

In this context, the class is used to get rid of QGIS output in the test suite - BUT IT DOESN’T WORK (Maybe because QGIS starts its providers in a different process?)

Usage:

devnull = open(os.devnull, ‘w’) print(‘Fubar’)

with RedirectStdStreams(stdout=devnull, stderr=devnull):
print(“You’ll never see me”)

print(“I’m back!”)

safe_qgis.utilities_test.assertHashForFile(theHash, theFilename)[source]

Assert that a files has matches its expected hash

safe_qgis.utilities_test.assertHashesForFile(theHashes, theFilename)[source]

Assert that a files has matches one of a list of expected hashes

safe_qgis.utilities_test.checkImage(theControlImagePath, theTestImagePath, theTolerance=1000)[source]

Compare a test image against a known good image.

Args:
  • theControlImagePath: The image representing expected output

  • theTestImagePath: The Image being checked (must have same dimensions

    as the control image).

  • theTolerance: How many pixels may be different between the

    two images.

Returns:
(bool, str, str) where: * bool is success or failure indicator * str is a message providing analysis comparison notes
Raises:
None
safe_qgis.utilities_test.checkImages(theControlImages, theTestImagePath, theTolerance=1000)[source]

Compare a test image against a collection of known good images.

Args:
  • theControlImagePath: list of file names. Give only the basename +ext

    as the test image path (CONTROL_IMAGE_DIR) will be prepended.

  • theTestImagePath: The Image being checked (must have same dimensions

    as the control image). Must be full path to image.

  • theTolerance: How many pixels may be different between the

    two images.

Returns:
(bool, str, str) where: * bool is success or failure indicator * str is the file path of the resulting difference image * str is a message providing analysis comparison notes
Raises:
None
safe_qgis.utilities_test.getQgisTestApp()[source]

Start one QGis application to test agaist

Input
NIL
Output
handle to qgis app

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

safe_qgis.utilities_test.hashForFile(theFilename)[source]

Return an md5 checksum for a file

safe_qgis.utilities_test.loadLayer(theLayerFile, theDirectory='/home/timlinux/dev/python/inasafe_data/test')[source]

Helper to load and return a single QGIS layer

Args:

theLayerFile: Pathname to raster or vector file DIR: Optional parameter stating the parent dir. If None,

pathname is assumed to be absolute

Returns: QgsMapLayer, str (for layer type)

safe_qgis.utilities_test.setBatemansBayGeoExtent()[source]

Zoom to an area occupied by both Batemans Bay layers in geo crs

safe_qgis.utilities_test.setCanvasCrs(theEpsgId, theOtfpFlag=False)[source]

Helper to set the crs for the CANVAS before a test is run.

Args:

  • theEpsgId - Valid EPSG identifier (int)

  • theOtfpFlag - whether on the fly projections should be enabled

    on the CANVAS. Default to False.

safe_qgis.utilities_test.setGeoExtent(theBoundingBox)[source]

Zoom to an area specified given bounding box (list)

safe_qgis.utilities_test.setJakartaGeoExtent()[source]

Zoom to an area occupied by both Jakarta layers in Geo

safe_qgis.utilities_test.setJakartaGoogleExtent()[source]

Zoom to an area occupied by both Jakarta layers in 900913 crs

safe_qgis.utilities_test.setPadangGeoExtent()[source]

Zoom to an area occupied by both both Padang layers

safe_qgis.utilities_test.setYogyaGeoExtent()[source]

Zoom to an area occupied by both Jakarta layers in Geo

safe_qgis.utilities_test.unitTestDataPath(theSubdir=None)[source]

Return the absolute path to the InaSAFE unit test data dir.

Note

This is not the same thing as the SVN inasafe_data dir. Rather this is a new dataset where the test datasets are all tiny for fast testing and the datasets live in the same repo as the code.

Args:
  • theSubdir: (Optional) Additional subdir to add to the path - typically ‘hazard’ or ‘exposure’.

This module forms part of the InaSAFE tool.

Previous topic

Module: safe_qgis.impact_functions_doc

Next topic

Module: safe_qgis.safe_interface

This Page