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
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
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
def addSymbolToLegend(self): """Test we can add a symbol to the legend.""" myLayer, myType = loadLayer('test_floodimpact.tif') del myType myMap = ISMap(IFACE) myMap.setImpactLayer(myLayer) myMap.legend = None mySymbol = QgsSymbol() mySymbol.setColor(QtGui.QColor(12, 34, 56)) myMap.addSymbolToLegend(mySymbol, theMin=0, theMax=2, theCategory=None, theLabel='Foo') myPath = os.path.join(getTempDir(), 'addSymbolToLegend.png') myMap.legend.save(myPath, 'PNG') myExpectedHash = '1234' assertHashForFile(myExpectedHash, myPath)
def addSymbolToLegend(self): """Test we can add a symbol to the legend.""" myLayer, myType = loadLayer('test_floodimpact.tif') del myType myMap = Map(IFACE) myMap.setImpactLayer(myLayer) myMap.legend = None mySymbol = QgsSymbol() mySymbol.setColor(QtGui.QColor(12, 34, 56)) myMap.addSymbolToLegend(mySymbol, theMin=0, theMax=2, theCategory=None, theLabel='Foo') myPath = os.path.join(temp_dir(), 'addSymbolToLegend.png') myMap.legend.save(myPath, 'PNG') myExpectedHash = '1234' assertHashForFile(myExpectedHash, myPath)