test_generic.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function
  3. import filecmp
  4. import os
  5. import unittest
  6. from shutil import rmtree
  7. from tempfile import mkdtemp
  8. import pytest
  9. from pelican import Pelican
  10. from pelican.settings import read_settings
  11. PLUGIN_DIR = os.path.dirname(__file__)
  12. TEST_DATA_DIR = os.path.join(PLUGIN_DIR, 'test_data')
  13. class TestFullRun(unittest.TestCase):
  14. '''Test running Pelican with the Plugin'''
  15. def setUp(self):
  16. '''Create temporary output and cache folders'''
  17. self.temp_path = mkdtemp(prefix='pelicantests.')
  18. self.temp_cache = mkdtemp(prefix='pelican_cache.')
  19. os.chdir(TEST_DATA_DIR)
  20. def tearDown(self):
  21. '''Remove output and cache folders'''
  22. rmtree(self.temp_path)
  23. rmtree(self.temp_cache)
  24. os.chdir(PLUGIN_DIR)
  25. def test_generic_tag_with_config(self):
  26. '''Test generation of site with a generic tag that reads in a config file.'''
  27. base_path = os.path.dirname(os.path.abspath(__file__))
  28. base_path = os.path.join(base_path, 'test_data')
  29. content_path = os.path.join(base_path, 'content')
  30. output_path = os.path.join(base_path, 'output')
  31. settings_path = os.path.join(base_path, 'pelicanconf.py')
  32. settings = read_settings(path=settings_path,
  33. override={'PATH': content_path,
  34. 'OUTPUT_PATH': self.temp_path,
  35. 'CACHE_PATH': self.temp_cache,
  36. }
  37. )
  38. pelican = Pelican(settings)
  39. pelican.run()
  40. assert os.path.exists(os.path.join(self.temp_path,
  41. 'test-generic-config-tag.html'))
  42. assert "Tester" in open(os.path.join(self.temp_path,
  43. 'test-generic-config-tag.html')).read()
  44. # test differences
  45. #assert filecmp.cmp(os.path.join(output_path,
  46. # 'test-ipython-notebook-v3.html'),
  47. # os.path.join(self.temp_path,
  48. # 'test-ipython-notebook.html'))