Deep copy _DEFAULT_SETTINGS instead of linking.

This caused the defaults to be overwritten and edge case bugs with tests.
The test for empty setting needed to be updated to reflect that the method
for setting up the local settings sets extra settings.
This commit is contained in:
tBunnyMan 2012-08-29 12:17:59 -07:00
commit 644fd4ed5f
4 changed files with 15 additions and 9 deletions

View file

@ -1,3 +1,4 @@
import copy
import os import os
import re import re
import sys import sys
@ -29,7 +30,7 @@ class Pelican(object):
before doing anything else. before doing anything else.
""" """
if settings is None: if settings is None:
settings = _DEFAULT_CONFIG settings = copy.deepcopy(_DEFAULT_CONFIG)
self.path = path or settings['PATH'] self.path = path or settings['PATH']
if not self.path: if not self.path:

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import copy
import locale import locale
import logging import logging
import functools import functools
@ -29,7 +30,7 @@ class Page(object):
if not metadata: if not metadata:
metadata = {} metadata = {}
if not settings: if not settings:
settings = _DEFAULT_CONFIG settings = copy.deepcopy(_DEFAULT_CONFIG)
self.settings = settings self.settings = settings
self._content = content self._content = content

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import copy
import imp import imp
import inspect import inspect
import os import os
@ -81,7 +82,7 @@ def read_settings(filename=None):
if filename: if filename:
local_settings = get_settings_from_file(filename) local_settings = get_settings_from_file(filename)
else: else:
local_settings = _DEFAULT_CONFIG local_settings = copy.deepcopy(_DEFAULT_CONFIG)
configured_settings = configure_settings(local_settings, None, filename) configured_settings = configure_settings(local_settings, None, filename)
return configured_settings return configured_settings
@ -89,10 +90,9 @@ def read_settings(filename=None):
def get_settings_from_module(module=None, default_settings=_DEFAULT_CONFIG): def get_settings_from_module(module=None, default_settings=_DEFAULT_CONFIG):
""" """
Load settings from a module, returning a dict. Load settings from a module, returning a dict.
""" """
context = default_settings.copy() context = copy.deepcopy(default_settings)
if module is not None: if module is not None:
context.update( context.update(
(k, v) for k, v in inspect.getmembers(module) if k.isupper() (k, v) for k, v in inspect.getmembers(module) if k.isupper()
@ -114,7 +114,7 @@ def get_settings_from_file(filename, default_settings=_DEFAULT_CONFIG):
def configure_settings(settings, default_settings=None, filename=None): def configure_settings(settings, default_settings=None, filename=None):
"""Provide optimizations, error checking, and warnings for loaded settings""" """Provide optimizations, error checking, and warnings for loaded settings"""
if default_settings is None: if default_settings is None:
default_settings = _DEFAULT_CONFIG default_settings = copy.deepcopy(_DEFAULT_CONFIG)
# Make the paths relative to the settings file # Make the paths relative to the settings file
if filename: if filename:
@ -138,7 +138,7 @@ def configure_settings(settings, default_settings=None, filename=None):
for locale_ in locales: for locale_ in locales:
try: try:
locale.setlocale(locale.LC_ALL, locale_) locale.setlocale(locale.LC_ALL, locale_)
break # break if it is successfull break # break if it is successful
except locale.Error: except locale.Error:
pass pass
else: else:

View file

@ -1,6 +1,7 @@
import copy
from os.path import dirname, abspath, join from os.path import dirname, abspath, join
from pelican.settings import read_settings, configure_settings, _DEFAULT_CONFIG from pelican.settings import read_settings, configure_settings, _DEFAULT_CONFIG, DEFAULT_THEME
from .support import unittest from .support import unittest
@ -31,7 +32,10 @@ class TestSettingsConfiguration(unittest.TestCase):
def test_read_empty_settings(self): def test_read_empty_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) expected = copy.deepcopy(_DEFAULT_CONFIG)
expected["FEED_DOMAIN"] = '' #This is added by configure settings
self.maxDiff = None
self.assertDictEqual(settings, expected)
def test_configure_settings(self): def test_configure_settings(self):
"""Manipulations to settings should be applied correctly.""" """Manipulations to settings should be applied correctly."""