mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
improved test_setting.py
This commit is contained in:
parent
3958cbcce3
commit
77aac049fd
1 changed files with 22 additions and 22 deletions
|
|
@ -1,33 +1,33 @@
|
||||||
from unittest2 import TestCase
|
import unittest2
|
||||||
import os
|
from os.path import dirname, abspath, join
|
||||||
|
|
||||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||||
|
|
||||||
SETTINGS = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
|
||||||
"default_conf.py"])
|
|
||||||
|
|
||||||
class SettingsTest(TestCase):
|
class TestSettingsFromFile(unittest2.TestCase):
|
||||||
|
"""Providing a file, it should read it, replace the default values and
|
||||||
|
append new values to the settings, if any
|
||||||
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
self.PATH = abspath(dirname(__file__))
|
||||||
|
default_conf = join(self.PATH, 'default_conf.py')
|
||||||
|
self.settings = read_settings(default_conf)
|
||||||
|
|
||||||
def test_read_settings_from_file(self):
|
def test_overwrite_existing_settings(self):
|
||||||
# providing a file, it should read it, replace the default values and append
|
self.assertEqual(self.settings.get('SITENAME'), u"Alexis' log")
|
||||||
# new values to the settings, if any
|
self.assertEqual(self.settings.get('SITEURL'),
|
||||||
settings = read_settings(SETTINGS)
|
'http://blog.notmyidea.org')
|
||||||
|
|
||||||
# overwrite existing settings
|
def test_keep_default_settings(self):
|
||||||
self.assertEqual(settings.get('SITENAME'), u"Alexis' log")
|
"""keep default settings if not defined"""
|
||||||
|
self.assertEqual(self.settings.get('DEFAULT_CATEGORY'),
|
||||||
# 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'])
|
_DEFAULT_CONFIG['DEFAULT_CATEGORY'])
|
||||||
|
|
||||||
# do not copy keys not in caps
|
def test_dont_copy_small_keys(self):
|
||||||
self.assertNotIn('foobar', settings)
|
"""do not copy keys not in caps."""
|
||||||
|
self.assertNotIn('foobar', self.settings)
|
||||||
|
|
||||||
|
def test_read_empty_settings(self):
|
||||||
def test_empty_read_settings(self):
|
"""providing no file should return the default values."""
|
||||||
# providing no file should return the default values
|
|
||||||
settings = read_settings(None)
|
settings = read_settings(None)
|
||||||
self.assertDictEqual(settings, _DEFAULT_CONFIG)
|
self.assertDictEqual(settings, _DEFAULT_CONFIG)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue