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,9 +1,9 @@
|
||||||
import os
|
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"])
|
"themes/notmyidea"])
|
||||||
_DEFAULT_CONFIG = {'PATH': None,
|
DEFAULT_CONFIG = {'PATH': None,
|
||||||
'THEME': _DEFAULT_THEME,
|
'THEME': DEFAULT_THEME,
|
||||||
'OUTPUT_PATH': 'output/',
|
'OUTPUT_PATH': 'output/',
|
||||||
'MARKUP': ('rst', 'md'),
|
'MARKUP': ('rst', 'md'),
|
||||||
'STATIC_PATHS': ['images',],
|
'STATIC_PATHS': ['images',],
|
||||||
|
|
@ -29,7 +29,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
||||||
def read_settings(filename):
|
def read_settings(filename):
|
||||||
"""Load a Python file into a dictionary.
|
"""Load a Python file into a dictionary.
|
||||||
"""
|
"""
|
||||||
context = _DEFAULT_CONFIG.copy()
|
context = DEFAULT_CONFIG.copy()
|
||||||
if filename:
|
if filename:
|
||||||
tempdict = {}
|
tempdict = {}
|
||||||
execfile(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'
|
|
||||||
|
|
@ -19,3 +19,7 @@ SOCIAL = (('twitter', 'http://twitter.com/ametaireau'),
|
||||||
('github', 'http://github.com/ametaireau'),)
|
('github', 'http://github.com/ametaireau'),)
|
||||||
|
|
||||||
STATIC_PATHS = ["pictures",]
|
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