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 myControlImages = ['renderHtmlToImage.png', 'renderHtmlToImage-variantOSX10.8.png', 'renderHtmlToImage-variantWindosVistaSP2-32.png', 'renderHtmlToImage-variantWindowsXPSP3-32.png', 'renderHtmlToImage-variantUB11.04-64.png', 'renderHtmlToImage-variantLinuxMint-14-x86_64.png', 'renderHtmlToImage-variantWindows7-SP1-AMD64.png', 'renderHtmlToImage-variantUB11.10-64.png'] myTolerance = 1000 # to allow for version number changes in disclaimer myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance) assert myFlag, myMessage
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.printToPdf(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, _ = loadLayer(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.readKeywords(myLayer) myPath = myHtmlRenderer.printImpactTable(myKeywords, theFilename=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 myExpectedSize = 20936 # as rendered on linux ub 12.04 64 myMessage = ('Expected rendered table pdf to be at least %s, got %s' % (myExpectedSize, mySize)) assert mySize >= myExpectedSize, myMessage
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.printToPdf(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, _ = loadLayer(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.readKeywords(myLayer) myPath = myHtmlRenderer.printImpactTable(myKeywords, theFilename=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 myExpectedSize = 20936 # as rendered on linux ub 12.04 64 myMessage = ('Expected rendered table pdf to be at least %s, got %s' % (myExpectedSize, mySize)) assert mySize >= myExpectedSize, myMessage
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 myControlImages = [ 'renderHtmlToImage.png', 'renderHtmlToImage-variantWindosVistaSP2-32.png', 'renderHtmlToImage-variantUB11.04-64.png', 'renderHtmlToImage-variantUB11.10-64.png' ] myTolerance = 1000 # to allow for version number changes in disclaimer myFlag, myMessage = checkImages(myControlImages, myPath, myTolerance) assert myFlag, myMessage
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 = checkImages( 'renderHtmlToImage', myPath, myTolerance) assert myFlag, myMessage