2013-01-11 02:57:43 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
from __future__ import unicode_literals, print_function
|
2012-04-01 13:50:03 +02:00
|
|
|
|
2012-03-11 01:59:58 +01:00
|
|
|
import os
|
2012-05-12 02:03:18 +02:00
|
|
|
from tempfile import mkdtemp
|
|
|
|
|
from shutil import rmtree
|
2012-05-19 23:44:37 +02:00
|
|
|
import locale
|
2012-11-30 15:10:51 +01:00
|
|
|
import logging
|
2013-07-05 01:08:45 +02:00
|
|
|
import subprocess
|
2012-03-11 01:59:58 +01:00
|
|
|
|
|
|
|
|
from pelican import Pelican
|
|
|
|
|
from pelican.settings import read_settings
|
2013-04-19 13:35:20 -04:00
|
|
|
from pelican.tests.support import LoggedTestCase, mute
|
2012-03-11 01:59:58 +01:00
|
|
|
|
2012-03-30 13:44:57 +02:00
|
|
|
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
2013-01-04 14:46:17 -05:00
|
|
|
SAMPLES_PATH = os.path.abspath(os.path.join(
|
2013-03-11 08:25:47 -04:00
|
|
|
CURRENT_DIR, os.pardir, os.pardir, 'samples'))
|
2013-01-04 14:46:17 -05:00
|
|
|
OUTPUT_PATH = os.path.abspath(os.path.join(CURRENT_DIR, 'output'))
|
2012-03-11 01:59:58 +01:00
|
|
|
|
|
|
|
|
INPUT_PATH = os.path.join(SAMPLES_PATH, "content")
|
|
|
|
|
SAMPLE_CONFIG = os.path.join(SAMPLES_PATH, "pelican.conf.py")
|
|
|
|
|
|
|
|
|
|
|
2012-10-09 00:56:15 +02:00
|
|
|
def recursiveDiff(dcmp):
|
|
|
|
|
diff = {
|
2013-01-04 14:46:17 -05:00
|
|
|
'diff_files': [os.path.join(dcmp.right, f)
|
2012-10-09 00:56:15 +02:00
|
|
|
for f in dcmp.diff_files],
|
2013-01-04 14:46:17 -05:00
|
|
|
'left_only': [os.path.join(dcmp.right, f)
|
2012-10-09 00:56:15 +02:00
|
|
|
for f in dcmp.left_only],
|
2013-01-04 14:46:17 -05:00
|
|
|
'right_only': [os.path.join(dcmp.right, f)
|
2012-10-09 00:56:15 +02:00
|
|
|
for f in dcmp.right_only],
|
|
|
|
|
}
|
|
|
|
|
for sub_dcmp in dcmp.subdirs.values():
|
2013-01-11 02:57:43 +01:00
|
|
|
for k, v in recursiveDiff(sub_dcmp).items():
|
2012-10-09 00:56:15 +02:00
|
|
|
diff[k] += v
|
|
|
|
|
return diff
|
|
|
|
|
|
|
|
|
|
|
2013-01-18 07:27:35 -05:00
|
|
|
class TestPelican(LoggedTestCase):
|
2012-03-11 01:59:58 +01:00
|
|
|
# general functional testing for pelican. Basically, this test case tries
|
|
|
|
|
# to run pelican in different situations and see how it behaves
|
|
|
|
|
|
2012-05-12 02:03:18 +02:00
|
|
|
def setUp(self):
|
2013-01-18 07:27:35 -05:00
|
|
|
super(TestPelican, self).setUp()
|
2013-03-26 00:38:07 -05:00
|
|
|
self.temp_path = mkdtemp(prefix='pelicantests.')
|
2014-02-15 21:20:51 +01:00
|
|
|
self.temp_cache = mkdtemp(prefix='pelican_cache.')
|
2012-05-19 23:44:37 +02:00
|
|
|
self.old_locale = locale.setlocale(locale.LC_ALL)
|
2013-03-10 20:11:36 -07:00
|
|
|
self.maxDiff = None
|
2013-01-11 02:57:43 +01:00
|
|
|
locale.setlocale(locale.LC_ALL, str('C'))
|
2012-05-12 02:03:18 +02:00
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
rmtree(self.temp_path)
|
2014-02-15 21:20:51 +01:00
|
|
|
rmtree(self.temp_cache)
|
2012-05-19 23:44:37 +02:00
|
|
|
locale.setlocale(locale.LC_ALL, self.old_locale)
|
2013-01-18 07:27:35 -05:00
|
|
|
super(TestPelican, self).tearDown()
|
2012-05-12 02:03:18 +02:00
|
|
|
|
2012-08-27 18:40:02 +02:00
|
|
|
def assertFilesEqual(self, diff):
|
2013-03-26 00:38:07 -05:00
|
|
|
msg = ("some generated files differ from the expected functional "
|
|
|
|
|
"tests output.\n"
|
|
|
|
|
"This is probably because the HTML generated files "
|
|
|
|
|
"changed. If these changes are normal, please refer "
|
|
|
|
|
"to docs/contribute.rst to update the expected "
|
|
|
|
|
"output of the functional tests.")
|
2012-08-27 18:40:02 +02:00
|
|
|
|
2012-10-09 00:56:15 +02:00
|
|
|
self.assertEqual(diff['left_only'], [], msg=msg)
|
|
|
|
|
self.assertEqual(diff['right_only'], [], msg=msg)
|
|
|
|
|
self.assertEqual(diff['diff_files'], [], msg=msg)
|
2012-08-27 18:40:02 +02:00
|
|
|
|
2013-07-05 01:08:45 +02:00
|
|
|
def assertDirsEqual(self, left_path, right_path):
|
|
|
|
|
out, err = subprocess.Popen(
|
|
|
|
|
['git', 'diff', '--no-ext-diff', '--exit-code', '-w', left_path, right_path], env={'PAGER': ''},
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
|
|
|
|
assert not out, out
|
|
|
|
|
assert not err, err
|
|
|
|
|
|
2012-03-11 01:59:58 +01:00
|
|
|
def test_basic_generation_works(self):
|
|
|
|
|
# when running pelican without settings, it should pick up the default
|
2012-11-24 00:46:03 +01:00
|
|
|
# ones and generate correct output without raising any exception
|
2013-01-04 11:22:49 -05:00
|
|
|
settings = read_settings(path=None, override={
|
2012-11-24 00:46:03 +01:00
|
|
|
'PATH': INPUT_PATH,
|
|
|
|
|
'OUTPUT_PATH': self.temp_path,
|
2014-02-15 21:20:51 +01:00
|
|
|
'CACHE_DIRECTORY': self.temp_cache,
|
2013-01-11 21:24:04 +01:00
|
|
|
'LOCALE': locale.normalize('en_US'),
|
2012-11-24 00:46:03 +01:00
|
|
|
})
|
|
|
|
|
pelican = Pelican(settings=settings)
|
2013-04-19 13:35:20 -04:00
|
|
|
mute(True)(pelican.run)()
|
2013-07-05 01:08:45 +02:00
|
|
|
self.assertDirsEqual(self.temp_path, os.path.join(OUTPUT_PATH, 'basic'))
|
2013-01-18 07:27:35 -05:00
|
|
|
self.assertLogCountEqual(
|
2014-04-01 20:44:09 +02:00
|
|
|
count=3,
|
2012-11-30 15:10:51 +01:00
|
|
|
msg="Unable to find.*skipping url replacement",
|
2013-01-18 07:27:35 -05:00
|
|
|
level=logging.WARNING)
|
2012-05-12 02:03:18 +02:00
|
|
|
|
|
|
|
|
def test_custom_generation_works(self):
|
|
|
|
|
# the same thing with a specified set of settings should work
|
2013-01-04 11:22:49 -05:00
|
|
|
settings = read_settings(path=SAMPLE_CONFIG, override={
|
2012-10-16 01:35:35 +02:00
|
|
|
'PATH': INPUT_PATH,
|
|
|
|
|
'OUTPUT_PATH': self.temp_path,
|
2014-02-15 21:20:51 +01:00
|
|
|
'CACHE_DIRECTORY': self.temp_cache,
|
2013-01-11 21:24:04 +01:00
|
|
|
'LOCALE': locale.normalize('en_US'),
|
2012-10-16 01:35:35 +02:00
|
|
|
})
|
|
|
|
|
pelican = Pelican(settings=settings)
|
2013-04-19 13:35:20 -04:00
|
|
|
mute(True)(pelican.run)()
|
2013-07-05 01:08:45 +02:00
|
|
|
self.assertDirsEqual(self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))
|
2013-08-24 13:42:55 +01:00
|
|
|
|
|
|
|
|
def test_theme_static_paths_copy(self):
|
|
|
|
|
# the same thing with a specified set of settings should work
|
|
|
|
|
settings = read_settings(path=SAMPLE_CONFIG, override={
|
|
|
|
|
'PATH': INPUT_PATH,
|
|
|
|
|
'OUTPUT_PATH': self.temp_path,
|
2014-02-15 21:20:51 +01:00
|
|
|
'CACHE_DIRECTORY': self.temp_cache,
|
2013-08-24 13:42:55 +01:00
|
|
|
'THEME_STATIC_PATHS': [os.path.join(SAMPLES_PATH, 'very'),
|
2013-08-31 22:11:03 +01:00
|
|
|
os.path.join(SAMPLES_PATH, 'kinda'),
|
2013-08-24 13:42:55 +01:00
|
|
|
os.path.join(SAMPLES_PATH, 'theme_standard')]
|
|
|
|
|
})
|
|
|
|
|
pelican = Pelican(settings=settings)
|
|
|
|
|
mute(True)(pelican.run)()
|
|
|
|
|
theme_output = os.path.join(self.temp_path, 'theme')
|
|
|
|
|
extra_path = os.path.join(theme_output, 'exciting', 'new', 'files')
|
|
|
|
|
|
|
|
|
|
for file in ['a_stylesheet', 'a_template']:
|
|
|
|
|
self.assertTrue(os.path.exists(os.path.join(theme_output, file)))
|
|
|
|
|
|
2013-08-31 22:11:03 +01:00
|
|
|
for file in ['wow!', 'boom!', 'bap!', 'zap!']:
|
2013-08-24 13:42:55 +01:00
|
|
|
self.assertTrue(os.path.exists(os.path.join(extra_path, file)))
|
2013-09-14 16:18:53 +01:00
|
|
|
|
|
|
|
|
def test_theme_static_paths_copy_single_file(self):
|
|
|
|
|
# the same thing with a specified set of settings should work
|
|
|
|
|
settings = read_settings(path=SAMPLE_CONFIG, override={
|
|
|
|
|
'PATH': INPUT_PATH,
|
|
|
|
|
'OUTPUT_PATH': self.temp_path,
|
2014-02-15 21:20:51 +01:00
|
|
|
'CACHE_DIRECTORY': self.temp_cache,
|
2013-09-14 16:18:53 +01:00
|
|
|
'THEME_STATIC_PATHS': [os.path.join(SAMPLES_PATH, 'theme_standard')]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
pelican = Pelican(settings=settings)
|
|
|
|
|
mute(True)(pelican.run)()
|
|
|
|
|
theme_output = os.path.join(self.temp_path, 'theme')
|
|
|
|
|
|
|
|
|
|
for file in ['a_stylesheet', 'a_template']:
|
|
|
|
|
self.assertTrue(os.path.exists(os.path.join(theme_output, file)))
|