Exemple #1
0
 def test_getRasterLegend(self):
     """Getting a legend for a raster layer works."""
     myLayer, _ = loadLayer('test_floodimpact.tif')
     myMapLegend = MapLegend(myLayer)
     myImage = myMapLegend.getRasterLegend()
     myPath = unique_filename(prefix='getRasterLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myImage.save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = [
         'getRasterLegend.png',
         'getRasterLegend-variantWindosVistaSP2-32.png',
         'getRasterLegend-variantUB12.04-64.png',
         'getRasterLegend-variantUB11.04-64.png',
         'getRasterLegend-variantJenkins.png'
     ]
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance)
     myMessage += (
         '\nWe want these images to match, if they do already '
         'copy the test image generated to create a new control image.')
     assert myFlag, myMessage
Exemple #2
0
 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(
         myLayer,
         theLegendNotes='Thousand separator represented by \'.\'',
         theLegendUnits='(people per cell)')
     myImage = myMapLegend.getVectorLegend()
     myPath = unique_filename(prefix='getVectorLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myImage.save(myPath, 'PNG')
     print myMapLegend.legendUnits
     print myMapLegend.legendNotes
     print myPath
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = ['getVectorLegend.png',
                        'getVectorLegend-variantWindowsVistaSP2-32.png',
                        'getVectorLegend-variantWindowsXPSP3-32.png',
                        'getVectorLegend-variantOSXml.png',
                        'getVectorLegend-variantUB12.04-64.png',
                        'getVectorLegend-variantUB11.04-64.png',
                        'getVectorLegend-variantLinuxMint-14-x86_64.png',
                        'getVectorLegend-variantWindows7-SP1-AMD64.png',
                        'getVectorLegend-variantJenkins.png']
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
                   'copy the test image generated to create a new control '
                   'image.')
     assert myFlag, myMessage
Exemple #3
0
    def test_getVectorLegend(self):
        """Getting a legend for a vector layer works."""
        myLayer, _ = loadLayer('test_shakeimpact.shp')
        myMapLegend = MapLegend(
            myLayer,
            theLegendNotes='Thousand separator represented by \'.\'',
            theLegendUnits='(people per cell)')
        myImage = myMapLegend.getVectorLegend()
        myPath = unique_filename(prefix='getVectorLegend',
                                 suffix='.png',
                                 dir=temp_dir('test'))
        myImage.save(myPath, 'PNG')
        print myMapLegend.legendUnits
        print myMapLegend.legendNotes
        print myPath
        LOGGER.debug(myPath)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        myTolerance = 0  # to allow for version number changes in disclaimer
        myFlag, myMessage = checkImages(
            'getVectorLegend.png', myPath, myTolerance)
        myMessage += ('\nWe want these images to match, if they do already '
                      'copy the test image generated to create a new control '
                      'image.')
        assert myFlag, myMessage
Exemple #4
0
    def test_getLegend(self):
        """Getting a legend for a generic layer works."""
        LOGGER.debug('test_getLegend called')
        myLayer, _ = loadLayer('test_shakeimpact.shp')
        myMapLegend = MapLegend(myLayer)
        assert myMapLegend.layer is not None
        myLegend = myMapLegend.getLegend()
        myPath = unique_filename(prefix='getLegend',
                                 suffix='.png',
                                 dir=temp_dir('test'))
        myLegend.save(myPath, 'PNG')
        LOGGER.debug(myPath)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        myTolerance = 0  # to allow for version number changes in disclaimer

        myFlag, myMessage = checkImages('getLegend.png',
                                        myPath,
                                        myTolerance)
        myMessage += ('\nWe want these images to match, if they do already '
                      'copy the test image generated to create a new control '
                      'image.')
        assert myFlag, myMessage
        LOGGER.debug('test_getLegend done')
Exemple #5
0
    def test_addSymbolToLegend(self):
        """Test we can add a symbol to the legend."""
        myLayer, _ = loadLayer('test_floodimpact.tif')
        myMapLegend = MapLegend(myLayer)
        mySymbol = QgsSymbol()
        mySymbol.setColor(QtGui.QColor(12, 34, 56))
        myMapLegend.addSymbolToLegend(mySymbol,
                                      theMin=0,
                                      # expect 2.0303 in legend
                                      theMax=2.02030,
                                      theCategory=None,
                                      theLabel='Foo')
        myPath = unique_filename(prefix='addSymbolToLegend',
                                 suffix='.png',
                                 dir=temp_dir('test'))
        myMapLegend.getLegend().save(myPath, 'PNG')
        LOGGER.debug(myPath)
        # As we have discovered, different versions of Qt and
        # OS platforms cause different output, so myControlImages is a list
        # of 'known good' renders.

        myTolerance = 0  # to allow for version number changes in disclaimer
        myFlag, myMessage = checkImages('addSymbolToLegend.png',
                                        myPath,
                                        myTolerance)
        myMessage += ('\nWe want these images to match, if they do already '
                      'copy the test image generated to create a new control '
                      'image.')
        assert myFlag, myMessage
Exemple #6
0
 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myImage = myMapLegend.getVectorLegend()
     myPath = unique_filename(prefix='getVectorLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myImage.save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = ['getVectorLegend.png',
                        'getVectorLegend-variantWindosVistaSP2-32.png',
                        'getVectorLegend-variantUB12.04-64.png',
                        'getVectorLegend-variantUB11.04-64.png',
                        'getVectorLegend-variantJenkins.png']
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages,
                                 myPath,
                                 myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
             'copy the test image generated to create a new control image.')
     assert myFlag, myMessage
Exemple #7
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myColour = QtGui.QColor(12, 34, 126)
     myMapLegend.addClassToLegend(myColour,
                                  theMin=None,
                                  theMax=None,
                                  theCategory=None,
                                  theLabel='bar')
     myMapLegend.addClassToLegend(myColour,
                                  theMin=None,
                                  theMax=None,
                                  theCategory=None,
                                  theLabel='foo')
     myPath = unique_filename(prefix='addClassToLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myMapLegend.getLegend().save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so place any other possible
     # variants in the safe_qgis/test_data/test_images/ dir e.g.
     # addClassToLegend-variantUbuntu13.04.png
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages('addClassToLegend.png',
                                     myPath,
                                     myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
                   'copy the test image generated to create a new control '
                   'image.')
     assert myFlag, myMessage
Exemple #8
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, _ = loadLayer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myColour = QtGui.QColor(12, 34, 126)
     myMapLegend.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory=None,
                            theLabel='bar')
     myMapLegend.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory=None,
                            theLabel='foo')
     myPath = unique_filename(prefix='addClassToLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myMapLegend.getLegend().save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = ['getClassToLegend.png',
                        'getClassToLegend-variantWindosVistaSP2-32.png',
                        'getClassToLegend-variantUB12.04-64.png',
                        'getClassToLegend-variantUB11.04-64.png',
                        'getClassToLegend-variantJenkins.png']
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages,
                                     myPath,
                                     myTolerance)
     myMessage += ('\nWe want these images to match, if they do already '
             'copy the test image generated to create a new control image.')
     assert myFlag, myMessage
Exemple #9
0
 def test_addSymbolToLegend(self):
     """Test we can add a symbol to the legend."""
     myLayer, _ = loadLayer('test_floodimpact.tif')
     myMapLegend = MapLegend(myLayer)
     mySymbol = QgsSymbol()
     mySymbol.setColor(QtGui.QColor(12, 34, 56))
     myMapLegend.addSymbolToLegend(mySymbol,
                                   theMin=0,
                                   theMax=2,
                                   theCategory=None,
                                   theLabel='Foo')
     myPath = unique_filename(prefix='addSymblToLegend',
                              suffix='.png',
                              dir=temp_dir('test'))
     myMapLegend.getLegend().save(myPath, 'PNG')
     LOGGER.debug(myPath)
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so myControlImages is a list
     # of 'known good' renders.
     myControlImages = [
         'addSymbolToLegend.png',
         'addSymbolToLegend-variantWindosVistaSP2-32.png',
         'addSymbolToLegend-variantUB12.04-64.png',
         'addSymbolToLegend-variantUB11.04-64.png',
         'addSymbolToLegend-variantJenkins.png'
     ]
     myTolerance = 0  # to allow for version number changes in disclaimer
     myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance)
     myMessage += (
         '\nWe want these images to match, if they do already '
         'copy the test image generated to create a new control image.')
     assert myFlag, myMessage