From: W. Trevor King Date: Wed, 12 May 2010 15:02:50 +0000 (-0400) Subject: Added hooke.config.TestHookeConfigParser X-Git-Url: http://git.tremily.us/?p=hooke.git;a=commitdiff_plain;h=d68a75a1d4773866c8d726d99783fcb73b504744 Added hooke.config.TestHookeConfigParser Used hooke.hooke.TestHooke to isolate Queue issue to HookeConfigParser: ====================================================================== ERROR: Ensure :class:`HookeConfigParser` is Queue-safe ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/hooke/hooke/config.py", line 270, in test_queue_safe b = q.get(a) File "/usr/lib/python2.6/multiprocessing/queues.py", line 91, in get res = self._recv() File "/tmp/hooke/hooke/compat/odict.py", line 214, in __setitem__ self._keys.append(key) AttributeError: 'odict' object has no attribute '_keys' --- diff --git a/hooke/config.py b/hooke/config.py index 21960de..03da0c9 100644 --- a/hooke/config.py +++ b/hooke/config.py @@ -12,9 +12,11 @@ COPYRIGHT 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', @@ -36,6 +38,14 @@ class Setting (object): 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 @@ -233,7 +243,6 @@ class HookeConfigParser (configparser.SafeConfigParser): 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(): @@ -247,3 +256,22 @@ class HookeConfigParser (configparser.SafeConfigParser): 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))