test_generation.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. from .notebook import IPYTHON_VERSION
  12. PLUGIN_DIR = os.path.dirname(__file__)
  13. TEST_DATA_DIR = os.path.join(PLUGIN_DIR, 'test_data')
  14. class TestFullRun(unittest.TestCase):
  15. '''Test running Pelican with the Plugin'''
  16. def setUp(self):
  17. '''Create temporary output and cache folders'''
  18. self.temp_path = mkdtemp(prefix='pelicantests.')
  19. self.temp_cache = mkdtemp(prefix='pelican_cache.')
  20. os.chdir(TEST_DATA_DIR)
  21. def tearDown(self):
  22. '''Remove output and cache folders'''
  23. rmtree(self.temp_path)
  24. rmtree(self.temp_cache)
  25. os.chdir(PLUGIN_DIR)
  26. @pytest.mark.skipif(IPYTHON_VERSION >= 3,
  27. reason="output must be created with ipython version 2")
  28. def test_generate_with_ipython3(self):
  29. '''Test generation of site with the plugin.'''
  30. base_path = os.path.dirname(os.path.abspath(__file__))
  31. base_path = os.path.join(base_path, 'test_data')
  32. content_path = os.path.join(base_path, 'content')
  33. output_path = os.path.join(base_path, 'output')
  34. settings_path = os.path.join(base_path, 'pelicanconf.py')
  35. settings = read_settings(path=settings_path,
  36. override={'PATH': content_path,
  37. 'OUTPUT_PATH': self.temp_path,
  38. 'CACHE_PATH': self.temp_cache,
  39. }
  40. )
  41. pelican = Pelican(settings)
  42. pelican.run()
  43. # test existence
  44. assert os.path.exists(os.path.join(self.temp_path,
  45. 'test-ipython-notebook-nb-format-3.html'))
  46. assert os.path.exists(os.path.join(self.temp_path,
  47. 'test-ipython-notebook-nb-format-4.html'))
  48. # test differences
  49. #assert filecmp.cmp(os.path.join(output_path,
  50. # 'test-ipython-notebook-v2.html'),
  51. # os.path.join(self.temp_path,
  52. # 'test-ipython-notebook.html'))
  53. @pytest.mark.skipif(IPYTHON_VERSION < 3,
  54. reason="output must be created with ipython version 3")
  55. def test_generate_with_ipython2(self):
  56. '''Test generation of site with the plugin.'''
  57. base_path = os.path.dirname(os.path.abspath(__file__))
  58. base_path = os.path.join(base_path, 'test_data')
  59. content_path = os.path.join(base_path, 'content')
  60. output_path = os.path.join(base_path, 'output')
  61. settings_path = os.path.join(base_path, 'pelicanconf.py')
  62. settings = read_settings(path=settings_path,
  63. override={'PATH': content_path,
  64. 'OUTPUT_PATH': self.temp_path,
  65. 'CACHE_PATH': self.temp_cache,
  66. }
  67. )
  68. pelican = Pelican(settings)
  69. pelican.run()
  70. # test existence
  71. assert os.path.exists(os.path.join(self.temp_path,
  72. 'test-ipython-notebook-nb-format-3.html'))
  73. assert os.path.exists(os.path.join(self.temp_path,
  74. 'test-ipython-notebook-nb-format-4.html'))
  75. # test differences
  76. #assert filecmp.cmp(os.path.join(output_path,
  77. # 'test-ipython-notebook-v3.html'),
  78. # os.path.join(self.temp_path,
  79. # 'test-ipython-notebook.html'))