コード例 #1
0
ファイル: test_html_renderer.py プロジェクト: essc/inasafe
 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
コード例 #2
0
 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
コード例 #3
0
 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)