Пример #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)
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
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))
Пример #6
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)
Пример #7
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))
Пример #8
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))
Пример #9
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))
Пример #10
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)
Пример #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_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)
Пример #12
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)
Пример #13
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)