def test_printToPdf(self): """Test that we can render some html to a pdf (most common use case). """ LOGGER.debug('InaSAFE HtmlRenderer testing printToPdf') myHtml = self.sampleHtml() myPageDpi = 300 myRenderer = HtmlRenderer(myPageDpi) myPath = unique_filename(prefix='testHtmlTable', suffix='.pdf', dir=temp_dir('test')) LOGGER.debug(myPath) # If it fails myNewPath will come back as None myNewPath = myRenderer.to_pdf(myHtml, myPath) myMessage = 'Rendered output does not exist: %s' % myNewPath assert os.path.exists(myNewPath), myMessage # Also it should use our desired output file name myMessage = 'Incorrect path - got: %s\nExpected: %s\n' % ( myNewPath, myPath) assert myNewPath == 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(myNewPath).st_size myExpectedSize = 18449 # as rendered on linux ub 11.04-64 myMessage = ('Expected rendered map pdf to be at least %s, got %s. ' 'Please update myExpectedSize if the rendered output ' 'is acceptible on your system.' % (myExpectedSize, mySize)) assert mySize >= myExpectedSize, myMessage
def test_printImpactTable(self): """Test that we can render html from impact table keywords.""" LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable') myFilename = 'test_floodimpact.tif' myLayer, _ = load_layer(myFilename) myMessage = 'Layer is not valid: %s' % myFilename assert myLayer.isValid(), myMessage myPageDpi = 300 myHtmlRenderer = HtmlRenderer(myPageDpi) myPath = unique_filename(prefix='impactTable', suffix='.pdf', dir=temp_dir('test')) myKeywordIO = KeywordIO() myKeywords = myKeywordIO.read_keywords(myLayer) myPath = myHtmlRenderer.print_impact_table(myKeywords, filename=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 = [20936, # as rendered on linux ub 12.04 64 21523, # as rendered on linux ub 12.10 64 20605, # as rendered on linux ub 13.04 64 21527, # as rendered on Jenkins post 22 June 2013 377191, # as rendered on OSX 252699L, # as rendered on Windows 7 64 bit 251782L, # as rendered on Windows 8 64 bit amd 21491, # as rendered on Slackware64 14.0 ] print 'Output pdf to %s' % myPath self.assertIn(mySize, myExpectedSizes)
def test_printToPdf(self): """Test that we can render some html to a pdf (most common use case). """ LOGGER.debug('InaSAFE HtmlRenderer testing printToPdf') html = self.sample_html() page_dpi = 300 renderer = HtmlRenderer(page_dpi) path = unique_filename( prefix='testHtmlTable', suffix='.pdf', dir=temp_dir('test')) LOGGER.debug(path) # If it fails new_path will come back as None new_path = renderer.to_pdf(html, path) message = 'Rendered output does not exist: %s' % new_path assert os.path.exists(new_path), message # Also it should use our desired output file name message = 'Incorrect path - got: %s\nExpected: %s\n' % ( new_path, path) assert new_path == 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. size = os.stat(new_path).st_size expected_size = 16600 # as rendered on linux ub 13.04-64 (MB) message = ( 'Expected rendered map pdf to be at least %s, got %s. ' 'Please update expected_size if the rendered output ' 'is acceptible on your system.' % (expected_size, size)) assert size >= expected_size, message
def test_print_to_pdf(self): """Test that we can render some html to a pdf (most common use case). """ LOGGER.debug('InaSAFE HtmlRenderer testing printToPdf') html = self.sample_html() page_dpi = 300 renderer = HtmlRenderer(page_dpi) path = unique_filename(prefix='testHtmlTable', suffix='.pdf', dir=temp_dir('test')) LOGGER.debug(path) # If it fails new_path will come back as None new_path = renderer.to_pdf(html, path) message = 'Rendered output does not exist: %s' % new_path self.assertTrue(os.path.exists(new_path), message) # Also it should use our desired output file name message = 'Incorrect path - got: %s\nExpected: %s\n' % (new_path, path) self.assertEqual(path, new_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. size = os.stat(new_path).st_size expected_size = 16600 # as rendered on linux ub 13.04-64 (MB) message = ('Expected rendered map pdf to be at least %s, got %s. ' 'Please update expected_size if the rendered output ' 'is acceptible on your system.' % (expected_size, size)) self.assertTrue(size >= expected_size, message)
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 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 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_print_impact_table(self): """Test that we can render html from impact table keywords.""" LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable') file_name = 'test_floodimpact.tif' layer, _ = load_layer(file_name) message = 'Layer is not valid: %s' % file_name self.assertTrue(layer.isValid(), message) page_dpi = 300 html_renderer = HtmlRenderer(page_dpi) path = unique_filename( prefix='impact_table', suffix='.pdf', dir=temp_dir('test')) keyword_io = KeywordIO() keywords = keyword_io.read_keywords(layer) path = html_renderer.print_impact_table(keywords, filename=path) message = 'Rendered output does not exist: %s' % path self.assertTrue(os.path.exists(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. size = os.stat(path).st_size expected_sizes = [ 20936, # as rendered on linux ub 12.04 64 21523, # as rendered on linux ub 12.10 64 20605, # as rendered on linux ub 13.04 64 13965, # as rendered on linux ub 13.10 64 14220, # as rendered on linux ub 13.04 64 MB 11085, # as rendered on linux ub 14.04 64 AG 17306, # as rendered on linux ub 14.04_64 TS 17127, # as rendered on linux ub 14.04_64 MB 17295, # as rendered on linux ub 14.04_64 IS 18665, # as rendered on Jenkins per 19 June 2014 377191, # as rendered on OSX 17556, # as rendered on Windows 7_32 16163L, # as rendered on Windows 7 64 bit Ultimate i3 251782L, # as rendered on Windows 8 64 bit amd 21491, # as rendered on Slackware64 14.0 18667, # as rendered on Linux Mint 14_64 ] print 'Output pdf to %s' % path self.assertIn(size, expected_sizes)
def test_print_impact_table(self): """Test that we can render html from impact table keywords.""" LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable') file_name = 'test_floodimpact.tif' layer, _ = load_layer(file_name) message = 'Layer is not valid: %s' % file_name self.assertTrue(layer.isValid(), message) page_dpi = 300 html_renderer = HtmlRenderer(page_dpi) path = unique_filename(prefix='impact_table', suffix='.pdf', dir=temp_dir('test')) keyword_io = KeywordIO() keywords = keyword_io.read_keywords(layer) path = html_renderer.print_impact_table(keywords, filename=path) message = 'Rendered output does not exist: %s' % path self.assertTrue(os.path.exists(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. size = os.stat(path).st_size expected_sizes = [ 20936, # as rendered on linux ub 12.04 64 21523, # as rendered on linux ub 12.10 64 20605, # as rendered on linux ub 13.04 64 13965, # as rendered on linux ub 13.10 64 14220, # as rendered on linux ub 13.04 64 MB 11085, # as rendered on linux ub 14.04 64 AG 17306, # as rendered on linux ub 14.04_64 TS 17127, # as rendered on linux ub 14.04_64 MB 17295, # as rendered on linux ub 14.04_64 IS 18665, # as rendered on Jenkins per 19 June 2014 377191, # as rendered on OSX 17556, # as rendered on Windows 7_32 16163L, # as rendered on Windows 7 64 bit Ultimate i3 251782L, # as rendered on Windows 8 64 bit amd 21491, # as rendered on Slackware64 14.0 18667, # as rendered on Linux Mint 14_64 ] print 'Output pdf to %s' % path self.assertIn(size, expected_sizes)
def test_render_html_to_image(self): """Test that we can render html to a pixmap.""" LOGGER.debug('InaSAFE HtmlRenderer testing renderHtmlToImage') html = self.sample_html(20) LOGGER.debug(html) page_dpi = 100 renderer = HtmlRenderer(page_dpi) path = unique_filename(prefix='testHtmlToImage', suffix='.png', dir=temp_dir('test')) LOGGER.debug(path) width = 150 pixmap = renderer.html_to_image(html, width) self.assertFalse(pixmap.isNull()) LOGGER.debug(pixmap.__class__) pixmap.save(path) message = 'Rendered output does not exist: %s' % path self.assertTrue(os.path.exists(path), message) tolerance = 1000 # to allow for version number changes in disclaimer flag, message = check_images('renderHtmlToImage', path, tolerance) self.assertTrue(flag, message + '\n' + path)
def test_renderHtmlToImage(self): """Test that we can render html to a pixmap.""" LOGGER.debug('InaSAFE HtmlRenderer testing renderHtmlToImage') myHtml = self.sampleHtml(20) LOGGER.debug(myHtml) myPageDpi = 300 myRenderer = HtmlRenderer(myPageDpi) myPath = unique_filename(prefix='testHtmlToImage', suffix='.png', dir=temp_dir('test')) LOGGER.debug(myPath) myWidth = 250 myPixmap = myRenderer.renderHtmlToImage(myHtml, myWidth) assert not myPixmap.isNull() LOGGER.debug(myPixmap.__class__) myPixmap.save(myPath) myMessage = 'Rendered output does not exist: %s' % myPath assert os.path.exists(myPath), myMessage myTolerance = 1000 # to allow for version number changes in disclaimer myFlag, myMessage = check_images('renderHtmlToImage', myPath, myTolerance) assert myFlag, myMessage + '\n' + myPath
def test_renderHtmlToImage(self): """Test that we can render html to a pixmap.""" LOGGER.debug('InaSAFE HtmlRenderer testing renderHtmlToImage') myHtml = self.sampleHtml(20) LOGGER.debug(myHtml) myPageDpi = 300 myRenderer = HtmlRenderer(myPageDpi) myPath = unique_filename( prefix='testHtmlToImage', suffix='.png', dir=temp_dir('test')) LOGGER.debug(myPath) myWidth = 250 myPixmap = myRenderer.html_to_image(myHtml, myWidth) assert not myPixmap.isNull() LOGGER.debug(myPixmap.__class__) myPixmap.save(myPath) myMessage = 'Rendered output does not exist: %s' % myPath assert os.path.exists(myPath), myMessage myTolerance = 1000 # to allow for version number changes in disclaimer myFlag, myMessage = check_images( 'renderHtmlToImage', myPath, myTolerance) assert myFlag, myMessage + '\n' + myPath
def test_render_html_to_image(self): """Test that we can render html to a pixmap.""" LOGGER.debug('InaSAFE HtmlRenderer testing renderHtmlToImage') html = self.sample_html(20) LOGGER.debug(html) page_dpu = 300 renderer = HtmlRenderer(page_dpu) path = unique_filename( prefix='testHtmlToImage', suffix='.png', dir=temp_dir('test')) LOGGER.debug(path) width = 250 pixmap = renderer.html_to_image(html, width) self.assertFalse(pixmap.isNull()) LOGGER.debug(pixmap.__class__) pixmap.save(path) message = 'Rendered output does not exist: %s' % path self.assertTrue(os.path.exists(path), message) tolerance = 1000 # to allow for version number changes in disclaimer flag, message = check_images( 'renderHtmlToImage', path, tolerance) self.assertTrue(flag, message + '\n' + path)