def createPDFReport(self, theTitle, theOutputDirectory, theImpactLayer, theCount=0, theIndex=''): """Create PDF report from impact layer. Create map & table report PDF based from theImpactLayer data. :param theTitle: the report title. :param theOutputDirectory: output directory :param theImpactLayer: impact layer instance. :param theCount: the number of as scenario has been run :param theIndex: the index for the beginning of the file name See also: Dock.printMap() """ myMap = Map(self.iface) # FIXME: check if theImpactLayer is the real impact layer... myMap.setImpactLayer(theImpactLayer) LOGGER.debug('Create Report: %s' % theTitle) myMapPath, myTablePath = self.reportPath( theOutputDirectory, theTitle, theCount, theIndex) # create map pdf myMap.printToPdf(myMapPath) # create table report pdf myHtmlRenderer = HtmlRenderer(myMap.pageDpi) myKeywords = myMap.keywordIO.read_keywords(theImpactLayer) myHtmlRenderer.printImpactTable(myKeywords, myTablePath) LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
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
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
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
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
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
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
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
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
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)
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)
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))
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))
def test_windowsDrawingArtifacts(self): """Test that windows rendering does not make artifacts""" # sometimes spurious lines are drawn on the layout LOGGER.info('Testing windowsDrawingArtifacts') myPath = unique_filename( prefix='artifacts', suffix='.pdf', dir=temp_dir('test')) myMap = Map(IFACE) setup_printer(myPath) myMap.setup_composition() myImage = QtGui.QImage(10, 10, QtGui.QImage.Format_RGB32) myImage.setDotsPerMeterX(dpi_to_meters(300)) myImage.setDotsPerMeterY(dpi_to_meters(300)) #myImage.fill(QtGui.QColor(250, 250, 250)) # Look at the output, you will see antialiasing issues around some # of the boxes drawn... # myImage.fill(QtGui.QColor(200, 200, 200)) myImage.fill(200 + 200 * 256 + 200 * 256 * 256) myFilename = os.path.join(temp_dir(), 'greyBox') myImage.save(myFilename, 'PNG') for i in range(10, 190, 10): myPicture = QgsComposerPicture(myMap.composition) myPicture.setPictureFile(myFilename) if qgis_version() >= 10800: # 1.8 or newer myPicture.setFrameEnabled(False) else: myPicture.setFrame(False) myPicture.setItemPosition(i, # x i, # y 10, # width 10) # height myMap.composition.addItem(myPicture) # Same drawing drawn directly as a pixmap # noinspection PyCallByClass,PyTypeChecker,PyArgumentList myPixmapItem = myMap.composition.addPixmap( QtGui.QPixmap.fromImage(myImage)) myPixmapItem.setOffset(i, i + 20) # Same drawing using our drawImage Helper myWidthMM = 1 myMap.draw_image(myImage, myWidthMM, i, i + 40) myImagePath, _, _ = myMap.render() # when this test no longer matches our broken render hash # we know the issue is fixed myTolerance = 0 myFlag, myMessage = check_images( 'windowsArtifacts', myImagePath, myTolerance) myMessage += ('\nWe want these images to match, if they do not ' 'there may be rendering artifacts in windows.\n') assert myFlag, myMessage
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)
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)
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
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)
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)
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)
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))
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))
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)
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)
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
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)
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.setImpactLayer(myLayer) myMap.composeMap() myPath = unique_filename(prefix='mapPdfTest', suffix='.pdf', dir=temp_dir('test')) myMap.printToPdf(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)