test_pdf.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import unittest
  2. import os
  3. import locale
  4. import logging
  5. import pdf
  6. from tempfile import mkdtemp
  7. from pelican import Pelican
  8. from pelican.readers import MarkdownReader
  9. from pelican.settings import read_settings
  10. from shutil import rmtree
  11. CUR_DIR = os.path.dirname(__file__)
  12. class TestPdfGeneration(unittest.TestCase):
  13. def setUp(self, override=None):
  14. self.temp_path = mkdtemp(prefix='pelicantests.')
  15. settings = {
  16. 'PATH': os.path.join(os.path.dirname(CUR_DIR), '..', 'test_data',
  17. 'content'),
  18. 'OUTPUT_PATH': self.temp_path,
  19. 'PLUGINS': [pdf],
  20. 'LOCALE': locale.normalize('en_US'),
  21. }
  22. if override:
  23. settings.update(override)
  24. self.settings = read_settings(override=settings)
  25. pelican = Pelican(settings=self.settings)
  26. try:
  27. pelican.run()
  28. except ValueError:
  29. logging.warn('Relative links in the form of ' +
  30. '|filename|images/test.png are not yet handled by ' +
  31. ' the pdf generator')
  32. pass
  33. def tearDown(self):
  34. rmtree(self.temp_path)
  35. def test_existence(self):
  36. assert os.path.exists(os.path.join(self.temp_path, 'pdf',
  37. 'this-is-a-super-article.pdf'))
  38. if MarkdownReader.enabled:
  39. assert os.path.exists(os.path.join(self.temp_path, 'pdf',
  40. 'a-markdown-powered-article.pdf'))