Exemplo n.º 1
0
 def Xtest_renderTable(self):
     """Test that html renders nicely. Commented out for now until we work
     out how to get webkit to do offscreen rendering nicely."""
     myFilename = 'test_floodimpact.tif'
     myLayer, myType = loadLayer(myFilename)
     CANVAS.refresh()
     del myType
     myMessage = 'Layer is not valid: %s' % myFilename
     assert myLayer.isValid(), myMessage
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myPixmap = myMap.renderImpactTable()
     assert myPixmap is not None
     myExpectedWidth = 500
     myExpectedHeight = 300
     myMessage = 'Invalid width - got %s expected %s' % (
                                 myPixmap.width(),
                                 myExpectedWidth)
     assert myPixmap.width() == myExpectedWidth, myMessage
     myMessage = 'Invalid height - got %s expected %s' % (
                                 myPixmap.height(),
                                 myExpectedHeight)
     assert myPixmap.height() == myExpectedHeight
     myPath = os.path.join(getTempDir(), 'renderImpactTable.png')
     myPixmap.save(myPath, 'PNG')
     myExpectedHash = 'c9164d5c2bb85c6081905456ab827f3e'
     assertHashForFile(myExpectedHash, myPath)
Exemplo n.º 2
0
 def test_getMapTitle(self):
     """Getting the map title from the keywords"""
     myLayer, myType = loadLayer('test_floodimpact.tif')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myTitle = myMap.getMapTitle()
     myExpectedTitle = 'Penduduk yang Mungkin dievakuasi'
     myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
     assert myTitle == myExpectedTitle, myMessage
Exemplo n.º 3
0
    def test_windowsDrawingArtifacts(self):
        """Test that windows rendering does not make artifacts"""
        # sometimes spurious lines are drawn on the layout
        myMap = ISMap(IFACE)
        myMap.setupComposition()
        myPdfPath = os.path.join(getTempDir(), 'outArtifactsTest.pdf')
        myMap.setupPrinter(myPdfPath)

        myPixmap = QtGui.QPixmap(10, 10)
        myPixmap.fill(QtGui.QColor(250, 250, 250))
        myFilename = os.path.join(getTempDir(), 'greyBox')
        myPixmap.save(myFilename, 'PNG')
        for i in range(10, 190, 10):
            myPicture = QgsComposerPicture(myMap.composition)
            myPicture.setPictureFile(myFilename)
            myPicture.setFrame(False)
            myPicture.setItemPosition(i,  # x
                                      i,  # y
                                      10,  # width
                                      10)  # height
            myMap.composition.addItem(myPicture)
            # Same drawing drawn directly as a pixmap
            myPixmapItem = myMap.composition.addPixmap(myPixmap)
            myPixmapItem.setOffset(i, i + 20)
            # Same drawing using our drawPixmap Helper
            myWidthMM = 1
            myMap.drawPixmap(myPixmap, myWidthMM, i, i + 40)

        myMap.renderPrintout()
        myUnwantedHash = 'd05e9223d50baf8bb147475aa96d6ba3'
        myHash = hashForFile(myPdfPath)
        # when this test no longer matches our broken render hash
        # we know the issue is fixed
        myMessage = 'Windows map render still draws with artifacts.'
        assert myHash != myUnwantedHash, myMessage
Exemplo n.º 4
0
 def test_mmPointConversion(self):
     """Test that conversions between pixel and page dimensions work."""
     myMap = ISMap(IFACE)
     myDpi = 300
     myMap.pageDpi = myDpi
     myPixels = 300
     myMM = 25.4  # 1 inch
     myResult = myMap.pointsToMM(myPixels)
     myMessage = "Expected: %s\nGot: %s" % (myMM, myResult)
     assert myResult == myMM, myMessage
     myResult = myMap.mmToPoints(myMM)
     myMessage = "Expected: %s\nGot: %s" % (myPixels, myResult)
     assert myResult == myPixels, myMessage
Exemplo n.º 5
0
 def test_handleMissingMapTitle(self):
     """Missing map title from the keywords fails gracefully"""
     # TODO running OSM Buildngs with Pendudk Jakarta
     # wasthrowing an error when requesting map title
     # that this test wasnt replicating well
     myLayer, myType = loadLayer('population_padang_1.asc')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myTitle = myMap.getMapTitle()
     myExpectedTitle = None
     myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
     assert myTitle == myExpectedTitle, myMessage
Exemplo n.º 6
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.legend = None
     myColour = QtGui.QColor(12, 34, 126)
     myMap.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory=None,
                            theLabel='bar')
     myMap.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory=None,
                            theLabel='foo')
     myPath = os.path.join(getTempDir(), 'addClassToLegend.png')
     myMap.legend.save(myPath, 'PNG')
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so hashes are a list
     # of 'known good' renders.
     myExpectedHashes = ['',  # win
                         '67c0f45792318298664dd02cc0ac94c3',  # ub12.04xiner
                         'ea0702782c2ed5d950c427fbe1743858',  # ub11.10-64
                         '53e0ba1144e071ad41756595d29bf444',  # ub12.04
                         '0681c3587305074bc9272f456fb4dd09',  # ub12.04 xvfb
                         # ub11.04-64 laptop
                         '',
                         ]
     assertHashesForFile(myExpectedHashes, myPath)
Exemplo n.º 7
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.legend = None
     myColour = QtGui.QColor(12, 34, 126)
     myMap.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory='foo',
                            theLabel='bar')
     myMap.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory='foo',
                            theLabel='foo')
     myPath = os.path.join(getTempDir(), 'addClassToLegend.png')
     myMap.legend.save(myPath, 'PNG')
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so hashes are a list
     # of 'known good' renders.
     myExpectedHashes = ['658e8dc0bf8b9a09b36994abf9242099',  # win
                         'ea0702782c2ed5d950c427fbe1743858',  # ub11.10
                         '944cee3eb9d916816b60ef41e8069683',  # ub12.04
                         # ub11.04-64 laptop
                         '4f98b1ddef2d72bd38b2f220ec7e01cc',
                         ]
     assertHashesForFile(myExpectedHashes, myPath)
Exemplo n.º 8
0
 def test_addClassToLegend(self):
     """Test we can add a class to the map legend."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.legend = None
     myColour = QtGui.QColor(12, 34, 126)
     myMap.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory='foo',
                            theLabel='bar')
     myMap.addClassToLegend(myColour,
                            theMin=None,
                            theMax=None,
                            theCategory='foo',
                            theLabel='foo')
     myPath = os.path.join(getTempDir(), 'addClassToLegend.png')
     myMap.legend.save(myPath, 'PNG')
     myExpectedHash = None
     if  os.name is'nt':
         # windows renders fonts slightly differently
         myExpectedHash = '658e8dc0bf8b9a09b36994abf9242099'
     else:
         myExpectedHash = 'ea0702782c2ed5d950c427fbe1743858'
     assertHashForFile(myExpectedHash, myPath)
Exemplo n.º 9
0
 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.getVectorLegend()
     myPath = os.path.join(getTempDir(), 'getVectorLegend.png')
     myMap.legend.save(myPath, 'PNG')
     myExpectedHash = None
     if  os.name is'nt':
         # windows renders fonts slightly differently
         myExpectedHash = '658e8dc0bf8b9a09b36994abf9242099'
     else:
         myExpectedHash = 'f2169dd3146aca6b30a10cddfb5ebf68'
     assertHashForFile(myExpectedHash, myPath)
Exemplo n.º 10
0
 def test_getRasterLegend(self):
     """Getting a legend for a raster layer works."""
     myLayer, myType = loadLayer('test_floodimpact.tif')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.getRasterLegend()
     myPath = os.path.join(getTempDir(), 'getRasterLegend.png')
     myMap.legend.save(myPath, 'PNG')
     myExpectedHash = None
     if  os.name is'nt':
         # windows renders fonts slightly differently
         myExpectedHash = '658e8dc0bf8b9a09b36994abf9242099'
     else:
         myExpectedHash = '1fc706f7c08e7d3057a685f9e6c4df3f'
     assertHashForFile(myExpectedHash, myPath)
Exemplo n.º 11
0
    def test_renderTemplate(self):
        """Test that load template works"""
        #Use the template from our resources bundle
        myInPath = ':/plugins/inasafe/basic.qpt'
        myLayer, myType = loadLayer('test_shakeimpact.shp')
        del myType

        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])
        myMap = ISMap(IFACE)
        setJakartaGeoExtent()
        myMap.setImpactLayer(myLayer)
        myOutPath = os.path.join(getTempDir(), 'outTemplate.pdf')
        if os.path.exists(myOutPath):
            os.remove(myOutPath)
        myMap.renderTemplate(myInPath, myOutPath)
        assert os.path.exists(myOutPath)
Exemplo n.º 12
0
 def test_getRasterLegend(self):
     """Getting a legend for a raster layer works."""
     myLayer, myType = loadLayer('test_floodimpact.tif')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.getRasterLegend()
     myPath = os.path.join(getTempDir(), 'getRasterLegend.png')
     myMap.legend.save(myPath, 'PNG')
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so hashes are a list
     # of 'known good' renders.
     myExpectedHashes = ['658e8dc0bf8b9a09b36994abf9242099',  # win
                         '1fc706f7c08e7d3057a685f9e6c4df3f',  # ub11.10
                         '2845879db127ce81d85baaac0b2c11b7',  # ub12.04
                         # ub11.04-64 laptop
                         '6ab9f8cc2445d1e672fd5013ac76cce7',
                         ]
     assertHashesForFile(myExpectedHashes, myPath)
Exemplo n.º 13
0
 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.getVectorLegend()
     myPath = os.path.join(getTempDir(), 'getVectorLegend.png')
     myMap.legend.save(myPath, 'PNG')
     myExpectedHash = None
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so hashes are a list
     # of 'known good' renders.
     myExpectedHashes = ['658e8dc0bf8b9a09b36994abf9242099',  # win
                         'f2169dd3146aca6b30a10cddfb5ebf68',  # ub11.10
                         'de6cbd59899d0077b11dd09c00a343e8',  # ub12.04
                         # ub11.04-64 laptop
                         '6f9a68611cad040d0a524f929361bb64',
                         ]
     assertHashesForFile(myExpectedHashes, myPath)
Exemplo n.º 14
0
 def test_getRasterLegend(self):
     """Getting a legend for a raster layer works."""
     myLayer, myType = loadLayer('test_floodimpact.tif')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.getRasterLegend()
     myPath = os.path.join(getTempDir(), 'getRasterLegend.png')
     myMap.legend.save(myPath, 'PNG')
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so hashes are a list
     # of 'known good' renders.
     myExpectedHashes = ['',  # win
                         '9ead6ce0ac789adc65a6f00bd2d1f709',  # ub12.04xiner
                         '84bc3d518e3a0504f8dc36dfd620394e',  # ub11.10-64
                         'b68ccc328de852f0c66b8abe43eab3da',  # ub12.04
                         'cd5fb96f6c5926085d251400dd3b4928',  # ub12.04 xvfb
                         # ub11.04-64 laptop
                         '',
                         ]
     assertHashesForFile(myExpectedHashes, myPath)
Exemplo n.º 15
0
 def test_getVectorLegend(self):
     """Getting a legend for a vector layer works."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myMap = ISMap(IFACE)
     myMap.setImpactLayer(myLayer)
     myMap.getVectorLegend()
     myPath = os.path.join(getTempDir(), 'getVectorLegend.png')
     myMap.legend.save(myPath, 'PNG')
     # As we have discovered, different versions of Qt and
     # OS platforms cause different output, so hashes are a list
     # of 'known good' renders.
     myExpectedHashes = ['',  # win
                         'd0c3071c4babe7db4f9762b311d61184',  # ub12.04 xinr
                         'b94cfd8a10d709ff28466ada425f24c8',  # ub11.10-64
                         '00dc58aa50867de9b617ccfab0d13f21',  # ub12.04
                         'e65853e217a4c9b0c2f303dd2aadb373',  # ub12.04 xvfb
                         # ub11.04-64 laptop
                         '',
                         ]
     assertHashesForFile(myExpectedHashes, myPath)
Exemplo n.º 16
0
 def test_inasafeMap(self):
     """Test making a pdf using the ISMap class."""
     myLayer, myType = loadLayer('test_shakeimpact.shp')
     del myType
     myCanvasLayer = QgsMapCanvasLayer(myLayer)
     CANVAS.setLayerSet([myCanvasLayer])
     myMap = ISMap(IFACE)
     myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
     CANVAS.setExtent(myRect)
     CANVAS.refresh()
     myMap.setImpactLayer(myLayer)
     myPath = os.path.join(getTempDir(), 'outCustom.pdf')
     if os.path.exists(myPath):
         os.remove(myPath)
     myMap.makePdf(myPath)
     assert os.path.exists(myPath)
     # ,, note:: Template writing is experimental
     myMap.writeTemplate(os.path.join(getTempDir(), 'template.qpt'))
Exemplo n.º 17
0
 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)