Exemplo n.º 1
0
    def test_getVectorLegend(self):
        """Getting a legend for a vector layer works.
        @note This test is not related do thousand separator since we insert
        our own legend notes and our own layer.
        """
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myMapLegend = MapLegend(
            myLayer,
            legend_notes='Thousand separator represented by \',\'',
            legend_units='(people per cell)')
        myImage = myMapLegend.vector_legend()
        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.

        myTolerance = 0  # to allow for version number changes in disclaimer
        myFlag, myMessage = check_images(
            'getVectorLegend', 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
Exemplo n.º 2
0
    def test_addSymbolToLegend(self):
        """Test we can add a symbol to the legend."""
        myLayer, _ = load_layer('test_floodimpact.tif')
        myMapLegend = MapLegend(myLayer)
        mySymbol = QgsFillSymbolV2()
        mySymbol.setColor(QtGui.QColor(12, 34, 56))
        myMapLegend.add_symbol(
            mySymbol,
            minimum=0,
            # expect 2.0303 in legend
            maximum=2.02030,
            label='Foo')
        myPath = unique_filename(
            prefix='addSymbolToLegend',
            suffix='.png',
            dir=temp_dir('test'))
        myMapLegend.get_legend().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 = check_images(
            'addSymbolToLegend', 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
Exemplo n.º 3
0
    def test_getLegend(self):
        """Getting a legend for a generic layer works."""
        LOGGER.debug('test_getLegend called')
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myMapLegend = MapLegend(myLayer)
        assert myMapLegend.layer is not None
        myLegend = myMapLegend.get_legend()
        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 = check_images('getLegend', 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')
Exemplo n.º 4
0
    def test_getVectorLegend(self):
        """Getting a legend for a vector layer works.
        @note This test is not related do thousand separator since we insert
        our own legend notes and our own layer.
        """
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myMapLegend = MapLegend(
            myLayer,
            legend_notes='Thousand separator represented by \',\'',
            legend_units='(people per cell)')
        myImage = myMapLegend.vector_legend()
        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.

        myTolerance = 0  # to allow for version number changes in disclaimer
        myFlag, myMessage = check_images('getVectorLegend', 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
Exemplo n.º 5
0
    def test_getLegend(self):
        """Getting a legend for a generic layer works."""
        LOGGER.debug('test_getLegend called')
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myMapLegend = MapLegend(myLayer)
        assert myMapLegend.layer is not None
        myLegend = myMapLegend.get_legend()
        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 = check_images('getLegend', 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')
Exemplo n.º 6
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, _ = load_layer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myColour = QtGui.QColor(12, 34, 126)
     myMapLegend.add_class(
         myColour,
         label='bar')
     myMapLegend.add_class(
         myColour,
         label='foo')
     myPath = unique_filename(
         prefix='addClassToLegend',
         suffix='.png',
         dir=temp_dir('test'))
     myMapLegend.get_legend().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 = check_images(
         'addClassToLegend', 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
Exemplo n.º 7
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, _ = load_layer('test_shakeimpact.shp')
     myMapLegend = MapLegend(myLayer)
     myColour = QtGui.QColor(12, 34, 126)
     myMapLegend.add_class(
         myColour,
         label='bar')
     myMapLegend.add_class(
         myColour,
         label='foo')
     myPath = unique_filename(
         prefix='addClassToLegend',
         suffix='.png',
         dir=temp_dir('test'))
     myMapLegend.get_legend().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 = check_images(
         'addClassToLegend', 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
Exemplo n.º 8
0
    def test_addSymbolToLegend(self):
        """Test we can add a symbol to the legend."""
        myLayer, _ = load_layer('test_floodimpact.tif')
        myMapLegend = MapLegend(myLayer)
        mySymbol = QgsSymbol()
        mySymbol.setColor(QtGui.QColor(12, 34, 56))
        myMapLegend.add_symbol(
            mySymbol,
            minimum=0,
            # expect 2.0303 in legend
            maximum=2.02030,
            label='Foo')
        myPath = unique_filename(prefix='addSymbolToLegend',
                                 suffix='.png',
                                 dir=temp_dir('test'))
        myMapLegend.get_legend().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 = check_images('addSymbolToLegend', 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