Example #1
0
    def test_defaultTemplate(self):
        """Test that loading default template works"""
        LOGGER.info('Testing defaultTemplate')
        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)
        myPath = unique_filename(prefix='mapDefaultTemplateTest',
                                 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 = [
            400350,  # Slackware64 14.0
        ]
        myMessage = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            myPath, myExpectedSizes, mySize)
        self.assertIn(mySize, myExpectedSizes, myMessage)
Example #2
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
Example #3
0
 def test_getMapTitle(self):
     """Getting the map title from the keywords"""
     myLayer, _ = load_layer('test_floodimpact.tif')
     myMap = Map(IFACE)
     myMap.set_impact_layer(myLayer)
     myTitle = myMap.map_title()
     myExpectedTitle = 'Penduduk yang Mungkin dievakuasi'
     myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
     assert myTitle == myExpectedTitle, myMessage
Example #4
0
 def test_get_map_title(self):
     """Getting the map title from the keywords"""
     layer, _ = load_layer('test_floodimpact.tif')
     report = Map(IFACE)
     report.set_impact_layer(layer)
     title = report.map_title()
     expected_title = 'Penduduk yang Mungkin dievakuasi'
     message = 'Expected: %s\nGot:\n %s' % (expected_title, title)
     assert title == expected_title, message
Example #5
0
 def test_getMapTitle(self):
     """Getting the map title from the keywords"""
     myLayer, _ = load_layer('test_floodimpact.tif')
     myMap = Map(IFACE)
     myMap.set_impact_layer(myLayer)
     myTitle = myMap.map_title()
     myExpectedTitle = 'Penduduk yang Mungkin dievakuasi'
     myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
     assert myTitle == myExpectedTitle, myMessage
Example #6
0
 def test_get_map_title(self):
     """Getting the map title from the keywords"""
     layer, _ = load_layer('test_floodimpact.tif')
     report = Map(IFACE)
     report.set_impact_layer(layer)
     title = report.map_title()
     expected_title = 'Penduduk yang Mungkin dievakuasi'
     message = 'Expected: %s\nGot:\n %s' % (expected_title, title)
     assert title == expected_title, message
Example #7
0
 def test_handle_missing_map_title(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
     layer, _ = load_layer('population_padang_1.asc')
     report = Map(IFACE)
     report.set_impact_layer(layer)
     title = report.map_title()
     expected_title = None
     message = 'Expected: %s\nGot:\n %s' % (expected_title, title)
     assert title == expected_title, message
Example #8
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, _ = load_layer('population_padang_1.asc')
     myMap = Map(IFACE)
     myMap.set_impact_layer(myLayer)
     myTitle = myMap.map_title()
     myExpectedTitle = None
     myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
     assert myTitle == myExpectedTitle, myMessage
Example #9
0
 def test_handle_missing_map_title(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
     layer, _ = load_layer('population_padang_1.asc')
     report = Map(IFACE)
     report.set_impact_layer(layer)
     title = report.map_title()
     expected_title = None
     message = 'Expected: %s\nGot:\n %s' % (expected_title, title)
     assert title == expected_title, message
Example #10
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, _ = load_layer('population_padang_1.asc')
     myMap = Map(IFACE)
     myMap.set_impact_layer(myLayer)
     myTitle = myMap.map_title()
     myExpectedTitle = None
     myMessage = 'Expected: %s\nGot:\n %s' % (myExpectedTitle, myTitle)
     assert myTitle == myExpectedTitle, myMessage
Example #11
0
    def test_custom_logo(self):
        """Test that setting user-defined logo works."""
        LOGGER.info('Testing custom_logo')
        layer, _ = load_layer('test_shakeimpact.shp')
        canvas_layer = QgsMapCanvasLayer(layer)
        CANVAS.setLayerSet([canvas_layer])
        rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(rect)
        CANVAS.refresh()
        report = Map(IFACE)
        report.set_impact_layer(layer)
        report.set_organisation_logo(":/plugins/inasafe/logo-flower.png")
        out_path = unique_filename(prefix='mapCustomLogoTest',
                                   suffix='.pdf',
                                   dir=temp_dir('test'))
        report.make_pdf(out_path)
        LOGGER.debug(out_path)
        message = 'Rendered output does not exist: %s' % out_path
        self.assertTrue(os.path.exists(out_path), message)
        # 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.
        out_size = os.stat(out_path).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.

        expected_sizes = [
            402083,  # Ubuntu 13.04_64
            400563,  # Ubuntu 13.10_64
            450385,  # Ubuntu 14.04_64 AG
            413193,  # Ubuntu 14.04_64 TS pycharm
            416313,  # Ubuntu 14.04_64 TS make - TODO why is this?
            419483,  # Ubuntu 14.04_64 MB pycharm
            413193,  # Ubuntu 14.04_64 MB make - TODO why is this?
            418847,  # Ubuntu 14.04_64 IS pycharm
            412764,  # Ubuntu 14.04_64 IS make - TODO why is this?
            367934,  # Slackware64 14.0
            82263,  # Linux Mint 14_64
            85418,  # Windows 7 32bit
            88779,  # Windows 7 64bit
            436118,  # Jenkins ub 12.04
            433856,  # Travis
        ]
        message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            out_path, expected_sizes, out_size)
        self.assertIn(out_size, expected_sizes, message)
Example #12
0
    def test_custom_logo(self):
        """Test that setting user-defined logo works."""
        LOGGER.info('Testing custom_logo')
        layer, _ = load_layer('test_shakeimpact.shp')
        canvas_layer = QgsMapCanvasLayer(layer)
        CANVAS.setLayerSet([canvas_layer])
        rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(rect)
        CANVAS.refresh()
        report = Map(IFACE)
        report.set_impact_layer(layer)
        report.set_organisation_logo(":/plugins/inasafe/logo-flower.png")
        out_path = unique_filename(
            prefix='mapCustomLogoTest', suffix='.pdf', dir=temp_dir('test'))
        report.make_pdf(out_path)
        LOGGER.debug(out_path)
        message = 'Rendered output does not exist: %s' % out_path
        self.assertTrue(os.path.exists(out_path), message)
        # 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.
        out_size = os.stat(out_path).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.

        expected_sizes = [
            402083,  # Ubuntu 13.04_64
            400563,  # Ubuntu 13.10_64
            450385,  # Ubuntu 14.04_64 AG
            413193,  # Ubuntu 14.04_64 TS pycharm
            416313,  # Ubuntu 14.04_64 TS make - TODO why is this?
            419483,  # Ubuntu 14.04_64 MB pycharm
            413193,  # Ubuntu 14.04_64 MB make - TODO why is this?
            419036,  # Ubuntu 14.04_64 IS pycharm
            412764,  # Ubuntu 14.04_64 IS make - TODO why is this?
            367934,  # Slackware64 14.0
            82263,  # Linux Mint 14_64
            85418,  # Windows 7 32bit
            88779,  # Windows 7 64bit
            436118,   # Jenkins ub 12.04
            432703,  # Travis
        ]
        message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            out_path, expected_sizes, out_size)
        self.assertIn(out_size, expected_sizes, message)
Example #13
0
    def test_default_template(self):
        """Test that loading default template works"""
        LOGGER.info('Testing default_template')
        layer, _ = load_layer('test_shakeimpact.shp')
        canvas_layer = QgsMapCanvasLayer(layer)
        CANVAS.setLayerSet([canvas_layer])
        rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(rect)
        CANVAS.refresh()
        report = Map(IFACE)
        report.set_impact_layer(layer)
        out_path = unique_filename(
            prefix='mapDefaultTemplateTest',
            suffix='.pdf',
            dir=temp_dir('test'))
        report.make_pdf(out_path)
        LOGGER.debug(out_path)
        message = 'Rendered output does not exist: %s' % out_path
        self.assertTrue(os.path.exists(out_path), message)
        # 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.
        out_size = os.stat(out_path).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.
        expected_sizes = [
            405359,  # Ubuntu 13.04_64
            427172,  # Ubuntu 13.10_64
            468836,  # Ubuntu 14.04_64 AG
            431844,  # Ubuntu 14.04_64 TS - pycharm
            431873,  # Ubuntu 14.04_64 TS - make - TODO why is this?
            437994,  # Ubuntu 14.04_64 MB - pycharm
            431844,  # Ubuntu 14.04_64 MB - make - TODO why is this?
            434596,  # Ubuntu 14.04_64 MB - pycharm
            428339,  # Ubuntu 14.04_64 MB - make - TODO why is this?
            414589,  # Slackware64 14.0
            144542,  # Linux Mint 14_64
            148267,  # Windows 7 32
            150412,  # Windows 7 64
            448270,  # UB 12.04 Jenkins
            448241,  # Travis
        ]
        message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            out_path, expected_sizes, out_size)
        self.assertIn(out_size, expected_sizes, message)
Example #14
0
    def Xtest_renderTemplate(self):
        """Test that load template works"""
        # Use the template from our resources bundle
        myInPath = ":/plugins/inasafe/basic.qpt"
        myLayer, _ = load_layer("test_shakeimpact.shp")

        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])
        myMap = Map(IFACE)
        set_jakarta_extent()
        myMap.set_impact_layer(myLayer)
        myPath = unique_filename(prefix="outTemplate", suffix=".pdf", dir=temp_dir("test"))
        LOGGER.debug(myPath)
        myMap.render_template(myInPath, myPath)
        assert os.path.exists(myPath)
Example #15
0
    def create_pdf(
            self,
            title,
            output_directory,
            impact_layer,
            count=0,
            index=None):
        """Create PDF report from impact layer.

        Create map & table report PDF based from impact_layer data.

        :param title: Report title.
        :type title: str

        :param output_directory: Output directory.
        :type output_directory: str

        :param impact_layer: Impact layer instance.
        :type impact_layer: QgsMapLayer

        :param count: The number of scenarios that were run.
        :type count: int

        :param index: A sequential number to place at the beginning of the
            file name.
        :type index: int, None

        See also:
            Dock.printMap()
        """

        inasafe_map = Map(self.iface)

        # FIXME: check if impact_layer is the real impact layer...
        inasafe_map.set_impact_layer(impact_layer)

        LOGGER.debug('Create Report: %s' % title)
        map_path, table_path = self.report_path(
            output_directory, title, count, index)

        # create map pdf
        inasafe_map.make_pdf(map_path)

        # create table report pdf
        html_renderer = HtmlRenderer(inasafe_map.page_dpi)
        keywords = inasafe_map.keyword_io.read_keywords(impact_layer)
        html_renderer.print_impact_table(keywords, table_path)
        LOGGER.debug("Report done %s %s" % (map_path, table_path))
Example #16
0
    def test_default_template(self):
        """Test that loading default template works"""
        LOGGER.info('Testing default_template')
        layer, _ = load_layer('test_shakeimpact.shp')
        canvas_layer = QgsMapCanvasLayer(layer)
        CANVAS.setLayerSet([canvas_layer])
        rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(rect)
        CANVAS.refresh()
        report = Map(IFACE)
        report.set_impact_layer(layer)
        out_path = unique_filename(prefix='mapDefaultTemplateTest',
                                   suffix='.pdf',
                                   dir=temp_dir('test'))
        report.make_pdf(out_path)
        LOGGER.debug(out_path)
        message = 'Rendered output does not exist: %s' % out_path
        self.assertTrue(os.path.exists(out_path), message)
        # 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.
        out_size = os.stat(out_path).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.
        expected_sizes = [
            405359,  # Ubuntu 13.04_64
            427172,  # Ubuntu 13.10_64
            468836,  # Ubuntu 14.04_64 AG
            431844,  # Ubuntu 14.04_64 TS - pycharm
            431873,  # Ubuntu 14.04_64 TS - make - TODO why is this?
            437994,  # Ubuntu 14.04_64 MB - pycharm
            431844,  # Ubuntu 14.04_64 MB - make - TODO why is this?
            434420,  # Ubuntu 14.04_64 IS - pycharm
            428339,  # Ubuntu 14.04_64 IS - make - TODO why is this?
            414589,  # Slackware64 14.0
            144542,  # Linux Mint 14_64
            148267,  # Windows 7 32
            150412,  # Windows 7 64
            448270,  # UB 12.04 Jenkins
            449448,  # Travis
        ]
        message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            out_path, expected_sizes, out_size)
        self.assertIn(out_size, expected_sizes, message)
Example #17
0
    def create_pdf(self,
                   title,
                   output_directory,
                   impact_layer,
                   count=0,
                   index=''):
        """Create PDF report from impact layer.

        Create map & table report PDF based from impact_layer data.

        :param title: Report title.
        :type title: str

        :param output_directory: Output directory.
        :type output_directory: str

        :param impact_layer: Impact layer instance.
        :type impact_layer: QgsMapLayer

        :param count: The number of scenarios that were run.
        :type count: int

        :param index: The prefix for the beginning of the file name. Note we
            need a better explanation of this param.
        :type index: str

        See also:
            Dock.printMap()
        """

        myMap = Map(self.iface)

        # FIXME: check if impact_layer is the real impact layer...
        myMap.set_impact_layer(impact_layer)

        LOGGER.debug('Create Report: %s' % title)
        myMapPath, myTablePath = self.report_path(
            output_directory, title, count, index)

        # create map pdf
        myMap.make_pdf(myMapPath)

        # create table report pdf
        myHtmlRenderer = HtmlRenderer(myMap.pageDpi)
        myKeywords = myMap.keywordIO.read_keywords(impact_layer)
        myHtmlRenderer.printImpactTable(myKeywords, myTablePath)
        LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
Example #18
0
    def create_pdf(self,
                   title,
                   output_directory,
                   impact_layer,
                   count=0,
                   index=None):
        """Create PDF report from impact layer.

        Create map & table report PDF based from impact_layer data.

        :param title: Report title.
        :type title: str

        :param output_directory: Output directory.
        :type output_directory: str

        :param impact_layer: Impact layer instance.
        :type impact_layer: QgsMapLayer

        :param count: The number of scenarios that were run.
        :type count: int

        :param index: A sequential number to place at the beginning of the
            file name.
        :type index: int, None

        See also:
            Dock.printMap()
        """

        inasafe_map = Map(self.iface)

        # FIXME: check if impact_layer is the real impact layer...
        inasafe_map.set_impact_layer(impact_layer)

        LOGGER.debug('Create Report: %s' % title)
        map_path, table_path = self.report_path(output_directory, title, count,
                                                index)

        # create map pdf
        inasafe_map.make_pdf(map_path)

        # create table report pdf
        html_renderer = HtmlRenderer(inasafe_map.page_dpi)
        keywords = inasafe_map.keyword_io.read_keywords(impact_layer)
        html_renderer.print_impact_table(keywords, table_path)
        LOGGER.debug("Report done %s %s" % (map_path, table_path))
Example #19
0
    def create_pdf(self,
                   title,
                   output_directory,
                   impact_layer,
                   count=0,
                   index=''):
        """Create PDF report from impact layer.

        Create map & table report PDF based from impact_layer data.

        :param title: Report title.
        :type title: str

        :param output_directory: Output directory.
        :type output_directory: str

        :param impact_layer: Impact layer instance.
        :type impact_layer: QgsMapLayer

        :param count: The number of scenarios that were run.
        :type count: int

        :param index: The prefix for the beginning of the file name. Note we
            need a better explanation of this param.
        :type index: str

        See also:
            Dock.printMap()
        """

        myMap = Map(self.iface)

        # FIXME: check if impact_layer is the real impact layer...
        myMap.set_impact_layer(impact_layer)

        LOGGER.debug('Create Report: %s' % title)
        myMapPath, myTablePath = self.report_path(output_directory, title,
                                                  count, index)

        # create map pdf
        myMap.make_pdf(myMapPath)

        # create table report pdf
        myHtmlRenderer = HtmlRenderer(myMap.pageDpi)
        myKeywords = myMap.keywordIO.read_keywords(impact_layer)
        myHtmlRenderer.printImpactTable(myKeywords, myTablePath)
        LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
Example #20
0
    def Xtest_renderTemplate(self):
        """Test that load template works"""
        #Use the template from our resources bundle
        myInPath = ':/plugins/inasafe/basic.qpt'
        myLayer, _ = load_layer('test_shakeimpact.shp')

        myCanvasLayer = QgsMapCanvasLayer(myLayer)
        CANVAS.setLayerSet([myCanvasLayer])
        myMap = Map(IFACE)
        set_jakarta_extent()
        myMap.set_impact_layer(myLayer)
        myPath = unique_filename(prefix='outTemplate',
                                 suffix='.pdf',
                                 dir=temp_dir('test'))
        LOGGER.debug(myPath)
        myMap.render_template(myInPath, myPath)
        assert os.path.exists(myPath)
Example #21
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

        # 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)
Example #22
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
Example #23
0
    def test_custom_logo(self):
        """Test that setting user-defined logo works"""
        LOGGER.info('Testing custom_logo')
        layer, _ = load_layer('test_shakeimpact.shp')
        canvas_layer = QgsMapCanvasLayer(layer)
        CANVAS.setLayerSet([canvas_layer])
        rect = QgsRectangle(106.7894, -6.2308, 106.8004, -6.2264)
        CANVAS.setExtent(rect)
        CANVAS.refresh()
        report = Map(IFACE)
        report.set_impact_layer(layer)
        report.set_logo(":/plugins/inasafe/logo-flower.png")
        out_path = unique_filename(prefix='mapCustomLogoTest',
                                   suffix='.pdf',
                                   dir=temp_dir('test'))
        report.make_pdf(out_path)
        LOGGER.debug(out_path)
        message = 'Rendered output does not exist: %s' % out_path
        assert os.path.exists(out_path), message
        # 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.
        out_size = os.stat(out_path).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.

        expected_sizes = [
            402083,  # Ubuntu 13.04_64
            388095,  # Slackware64 14.0
        ]
        message = '%s\nExpected rendered map pdf to be in %s, got %s' % (
            out_path, expected_sizes, out_size)
        self.assertIn(out_size, expected_sizes, message)
Example #24
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)
Example #25
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)