mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Tests for settings.
This commit is contained in:
parent
c13c707a62
commit
8454b0d1b8
5 changed files with 67 additions and 45 deletions
|
|
@ -1,35 +1,35 @@
|
|||
import os
|
||||
|
||||
_DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
||||
DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
||||
"themes/notmyidea"])
|
||||
_DEFAULT_CONFIG = {'PATH': None,
|
||||
'THEME': _DEFAULT_THEME,
|
||||
'OUTPUT_PATH': 'output/',
|
||||
'MARKUP': ('rst', 'md'),
|
||||
'STATIC_PATHS': ['images',],
|
||||
'THEME_STATIC_PATHS': ['static',],
|
||||
'FEED': 'feeds/all.atom.xml',
|
||||
'CATEGORY_FEED': 'feeds/%s.atom.xml',
|
||||
'TRANSLATION_FEED': 'feeds/all-%s.atom.xml',
|
||||
'SITENAME': 'A Pelican Blog',
|
||||
'DISPLAY_PAGES_ON_MENU': True,
|
||||
'PDF_GENERATOR': False,
|
||||
'DEFAULT_CATEGORY': 'misc',
|
||||
'FALLBACK_ON_FS_DATE': True,
|
||||
'CSS_FILE': 'main.css',
|
||||
'REVERSE_ARCHIVE_ORDER': False,
|
||||
'KEEP_OUTPUT_DIRECTORY': False,
|
||||
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
|
||||
'RELATIVE_URLS': True,
|
||||
'DEFAULT_LANG': 'en',
|
||||
'PELICAN_CLASS': 'pelican.Pelican',
|
||||
'JINJA_EXTENSIONS': [],
|
||||
DEFAULT_CONFIG = {'PATH': None,
|
||||
'THEME': DEFAULT_THEME,
|
||||
'OUTPUT_PATH': 'output/',
|
||||
'MARKUP': ('rst', 'md'),
|
||||
'STATIC_PATHS': ['images',],
|
||||
'THEME_STATIC_PATHS': ['static',],
|
||||
'FEED': 'feeds/all.atom.xml',
|
||||
'CATEGORY_FEED': 'feeds/%s.atom.xml',
|
||||
'TRANSLATION_FEED': 'feeds/all-%s.atom.xml',
|
||||
'SITENAME': 'A Pelican Blog',
|
||||
'DISPLAY_PAGES_ON_MENU': True,
|
||||
'PDF_GENERATOR': False,
|
||||
'DEFAULT_CATEGORY': 'misc',
|
||||
'FALLBACK_ON_FS_DATE': True,
|
||||
'CSS_FILE': 'main.css',
|
||||
'REVERSE_ARCHIVE_ORDER': False,
|
||||
'KEEP_OUTPUT_DIRECTORY': False,
|
||||
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
|
||||
'RELATIVE_URLS': True,
|
||||
'DEFAULT_LANG': 'en',
|
||||
'PELICAN_CLASS': 'pelican.Pelican',
|
||||
'JINJA_EXTENSIONS': [],
|
||||
}
|
||||
|
||||
def read_settings(filename):
|
||||
"""Load a Python file into a dictionary.
|
||||
"""
|
||||
context = _DEFAULT_CONFIG.copy()
|
||||
context = DEFAULT_CONFIG.copy()
|
||||
if filename:
|
||||
tempdict = {}
|
||||
execfile(filename, tempdict)
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
from unittest2 import TestCase
|
||||
|
||||
from pelican.settings import read_settings, DEFAULT_CONFIG
|
||||
|
||||
class SettingsTest(TestCase):
|
||||
|
||||
def test_read_settings(self):
|
||||
# providing no file should return the default values
|
||||
settings = read_settings(None)
|
||||
self.assertDictEqual(settings, DEFAULT_CONFIG)
|
||||
|
||||
# providing a file should read it, replace the default values and append
|
||||
# new values to the settings, if any
|
||||
settings = read_settings(mock)
|
||||
self.assertIn('key', settings)
|
||||
self.assertEqual(settings['KEY'
|
||||
|
|
@ -8,14 +8,18 @@ DISQUS_SITENAME = "blog-notmyidea"
|
|||
PDF_GENERATOR = False
|
||||
|
||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||
('Filyb', "http://filyb.info/"),
|
||||
('Libert-fr', "http://www.libert-fr.com"),
|
||||
('N1k0', "http://prendreuncafe.com/blog/"),
|
||||
(u'Tarek Ziadé', "http://ziade.org/blog"),
|
||||
('Zubin Mithra', "http://zubin71.wordpress.com/"),)
|
||||
('Filyb', "http://filyb.info/"),
|
||||
('Libert-fr', "http://www.libert-fr.com"),
|
||||
('N1k0', "http://prendreuncafe.com/blog/"),
|
||||
(u'Tarek Ziadé', "http://ziade.org/blog"),
|
||||
('Zubin Mithra', "http://zubin71.wordpress.com/"),)
|
||||
|
||||
SOCIAL = (('twitter', 'http://twitter.com/ametaireau'),
|
||||
('lastfm', 'http://lastfm.com/user/akounet'),
|
||||
('github', 'http://github.com/ametaireau'),)
|
||||
|
||||
STATIC_PATHS = ["pictures",]
|
||||
|
||||
# foobar will not be used, because it's not in caps. All configuration keys
|
||||
# have to be in caps
|
||||
foobar = "barbaz"
|
||||
|
|
|
|||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
34
tests/test_settings.py
Normal file
34
tests/test_settings.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from unittest2 import TestCase
|
||||
import os
|
||||
|
||||
from pelican.settings import read_settings, DEFAULT_CONFIG
|
||||
|
||||
SETTINGS = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
||||
"../samples/pelican.conf.py"])
|
||||
|
||||
class SettingsTest(TestCase):
|
||||
|
||||
|
||||
def test_read_settings(self):
|
||||
# providing a file, it should read it, replace the default values and append
|
||||
# new values to the settings, if any
|
||||
settings = read_settings(SETTINGS)
|
||||
|
||||
# overwrite existing settings
|
||||
self.assertEqual(settings.get('SITENAME'), u"Alexis' log")
|
||||
|
||||
# add new settings
|
||||
self.assertEqual(settings.get('SITEURL'), 'http://blog.notmyidea.org')
|
||||
|
||||
# keep default settings if not defined
|
||||
self.assertEqual(settings.get('DEFAULT_CATEGORY'),
|
||||
DEFAULT_CONFIG['DEFAULT_CATEGORY'])
|
||||
|
||||
# do not copy keys not in caps
|
||||
self.assertNotIn('foobar', settings)
|
||||
|
||||
|
||||
def test_empty_read_settings(self):
|
||||
# providing no file should return the default values
|
||||
settings = read_settings(None)
|
||||
self.assertDictEqual(settings, DEFAULT_CONFIG)
|
||||
Loading…
Add table
Add a link
Reference in a new issue