コード例 #1
0
ファイル: test_map.py プロジェクト: CharlesRethman/inasafe
    def test_renderComposition(self):
        """Test making an image of the map only."""
        LOGGER.info("Testing renderComposition")
        myLayer, _ = load_layer("test_shakeimpact.shp")
        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])

        myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(myRect)
        CANVAS.refresh()
        myMap = Map(IFACE)
        myMap.set_impact_layer(myLayer)
        myMap.compose_map()
        myImagePath, myControlImage, myTargetArea = myMap.render()
        LOGGER.debug(myImagePath)

        assert myControlImage is not None

        myDimensions = [myTargetArea.left(), myTargetArea.top(), myTargetArea.bottom(), myTargetArea.right()]
        myExpectedDimensions = [0.0, 0.0, 3507.0, 2480.0]
        myMessage = "Expected target area to be %s, got %s" % (str(myExpectedDimensions), str(myDimensions))
        assert myExpectedDimensions == myDimensions, myMessage

        myMessage = "Rendered output does not exist"
        assert os.path.exists(myImagePath), myMessage

        # Beta version and version changes  can introduce a few extra chars
        # into the metadata section so we set a reasonable tolerance to cope
        # with this.
        myTolerance = 8000
        myFlag, myMessage = check_images("renderComposition", myImagePath, myTolerance)
        assert myFlag, myMessage
コード例 #2
0
ファイル: test_map.py プロジェクト: vdeparday/inasafe
    def test_printToPdf(self):
        """Test making a pdf of the map - this is the most typical use of map.
        """
        LOGGER.info('Testing printToPdf')
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])
        myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(myRect)
        CANVAS.refresh()
        myMap = Map(IFACE)
        myMap.set_impact_layer(myLayer)
        myMap.compose_map()
        myPath = unique_filename(prefix='mapPdfTest',
                                 suffix='.pdf',
                                 dir=temp_dir('test'))
        myMap.make_pdf(myPath)
        LOGGER.debug(myPath)
        myMessage = 'Rendered output does not exist: %s' % myPath
        assert os.path.exists(myPath), myMessage
        # pdf rendering is non deterministic so we can't do a hash check
        # test_renderComposition renders just the image instead of pdf
        # so we hash check there and here we just do a basic minimum file
        # size check.
        mySize = os.stat(myPath).st_size

        # Note: You should replace, not append the numbers for a given
        # platform. Also note that this test will break every time the
        # version number of InaSAFE changes so we should ultimately come up
        # with a lower maintenance test strategy.

        myExpectedSizes = [
            441541,  # as rendered on ub 13.04 post 17 May 2013
            441563,  # as rendered on ub 13.04 18 Jul 2013
            447217,  # Nadia Linux Mint 14
            447144,  # as rendered on Jenkins post 29 July 2013
            447172,  # Windows 7 SP1 AMD64
            446839,  # Windows 8 AMD64 post 27 Aug 2013
            234138,  # OSX 10.8
            444421,  # Slackware64 14.0
        ]
        myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            myPath, myExpectedSizes, mySize)
        self.assertIn(mySize, myExpectedSizes, myMessage)
コード例 #3
0
    def test_renderComposition(self):
        """Test making an image of the map only."""
        LOGGER.info('Testing renderComposition')
        myLayer, _ = load_layer('test_shakeimpact.shp')
        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])

        myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(myRect)
        CANVAS.refresh()
        myMap = Map(IFACE)
        myMap.set_impact_layer(myLayer)
        myMap.compose_map()
        myImagePath, myControlImage, myTargetArea = myMap.render()
        LOGGER.debug(myImagePath)

        assert myControlImage is not None

        myDimensions = [
            myTargetArea.left(),
            myTargetArea.top(),
            myTargetArea.bottom(),
            myTargetArea.right()
        ]
        myExpectedDimensions = [0.0, 0.0, 3507.0, 2480.0]
        myMessage = 'Expected target area to be %s, got %s' % (
            str(myExpectedDimensions), str(myDimensions))
        assert myExpectedDimensions == myDimensions, myMessage

        myMessage = 'Rendered output does not exist'
        assert os.path.exists(myImagePath), myMessage

        # Beta version and version changes  can introduce a few extra chars
        # into the metadata section so we set a reasonable tolerance to cope
        # with this.
        myTolerance = 8000
        myFlag, myMessage = check_images('renderComposition', myImagePath,
                                         myTolerance)
        assert myFlag, myMessage
コード例 #4
0
 def test_printToPdf(self):
     """Test making a pdf of the map - this is the most typical use of map.
     """
     LOGGER.info('Testing printToPdf')
     myLayer, _ = load_layer('test_shakeimpact.shp')
     myCanvasLayer = QgsMapCanvasLayer(myLayer)
     CANVAS.setLayerSet([myCanvasLayer])
     myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
     CANVAS.setExtent(myRect)
     CANVAS.refresh()
     myMap = Map(IFACE)
     myMap.set_impact_layer(myLayer)
     myMap.compose_map()
     myPath = unique_filename(prefix='mapPdfTest',
                              suffix='.pdf',
                              dir=temp_dir('test'))
     myMap.make_pdf(myPath)
     LOGGER.debug(myPath)
     myMessage = 'Rendered output does not exist: %s' % myPath
     assert os.path.exists(myPath), myMessage
     # pdf rendering is non deterministic so we can't do a hash check
     # test_renderComposition renders just the image instead of pdf
     # so we hash check there and here we just do a basic minimum file
     # size check.
     mySize = os.stat(myPath).st_size
     myExpectedSizes = [
         441541,  # as rendered on ub 13.04 post 17 May 2013
         441428,  # as rendered on ub 13.04 5 Jul 2013
         447217,  # Nadia Linux Mint 14
         447051,  # as rendered on Jenkins post 24 April 2013
         447138,  # Windows 7 SP1 AMD64
         233989,  # OSX 10.8
     ]
     myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
         myPath, myExpectedSizes, mySize)
     self.assertIn(mySize, myExpectedSizes, myMessage)
コード例 #5
0
ファイル: test_map.py プロジェクト: lptorres/inasafe
 def test_printToPdf(self):
     """Test making a pdf of the map - this is the most typical use of map.
     """
     LOGGER.info('Testing printToPdf')
     myLayer, _ = load_layer('test_shakeimpact.shp')
     myCanvasLayer = QgsMapCanvasLayer(myLayer)
     CANVAS.setLayerSet([myCanvasLayer])
     myRect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
     CANVAS.setExtent(myRect)
     CANVAS.refresh()
     myMap = Map(IFACE)
     myMap.set_impact_layer(myLayer)
     myMap.compose_map()
     myPath = unique_filename(prefix='mapPdfTest',
                              suffix='.pdf',
                              dir=temp_dir('test'))
     myMap.make_pdf(myPath)
     LOGGER.debug(myPath)
     myMessage = 'Rendered output does not exist: %s' % myPath
     assert os.path.exists(myPath), myMessage
     # pdf rendering is non deterministic so we can't do a hash check
     # test_renderComposition renders just the image instead of pdf
     # so we hash check there and here we just do a basic minimum file
     # size check.
     mySize = os.stat(myPath).st_size
     myExpectedSizes = [
         441541,  # as rendered on ub 13.04 post 17 May 2013
         441428,  # as rendered on ub 13.04 5 Jul 2013
         447217,  # Nadia Linux Mint 14
         447051,  # as rendered on Jenkins post 24 April 2013
         447138,  # Windows 7 SP1 AMD64
         233989,  # OSX 10.8
     ]
     myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
         myPath, myExpectedSizes, mySize)
     self.assertIn(mySize, myExpectedSizes, myMessage)