import ConfigParser as configparser
import os.path
import textwrap
+import unittest
from .compat.odict import odict as OrderedDict
+
DEFAULT_PATHS = [
'/usr/share/hooke/hooke.cfg',
'/etc/hooke/hooke.cfg',
self.help = help
self.wrap = wrap
+ def __eq__(self, other):
+ for attr in ['__class__', 'section', 'option', 'value', 'help']:
+ value = getattr(self, attr)
+ o_value = getattr(other, attr)
+ if o_value != value:
+ return False
+ return True
+
def is_section(self):
return self.option == None
if local_fp:
fp = open(os.path.expanduser(self._config_paths[-1]), 'w')
if self._defaults:
- print self._defaults
self._write_setting(fp, configparser.DEFAULTSECT,
help="Miscellaneous options")
for (key, value) in self._defaults.items():
fp.write("\n")
if local_fp:
fp.close()
+
+class TestHookeConfigParser (unittest.TestCase):
+ def test_queue_safe(self):
+ """Ensure :class:`HookeConfigParser` is Queue-safe.
+ """
+ from multiprocessing import Queue
+ q = Queue()
+ a = HookeConfigParser(
+ paths=DEFAULT_PATHS, default_settings=DEFAULT_SETTINGS)
+ q.put(a)
+ b = q.get(a)
+ for attr in ['_dict', '_defaults', '_sections', '_config_paths',
+ '_default_settings']:
+ a_value = getattr(a, attr)
+ b_value = getattr(b, attr)
+ self.failUnless(
+ a_value == b_value,
+ 'HookeConfigParser.%s did not survive Queue: %s != %s'
+ % (attr, a_value, b_value))