def test_config_obj_comma_fix(self): self.assertEquals(fut.config_obj_comma_fix('hello'), 'hello') self.assertEquals(fut.config_obj_comma_fix(['a', 'b', 'c']), 'a, b, c') self.assertEquals( fut.config_obj_comma_fix(['x = a + sum(3', 4, 'f4)']), 'x = a + sum(3, 4, f4)')
def _parse_config(self): """ ROBDOC : CJ added a vague description below, but could be sure... ##Parses the class config attribute?! """ main_section_found = False ftype_in_config = False docstring = [] config_obj = ConfigObj(self.config_only) ##if not config_obj: ##raise dfb.FilterError, 'Missing configuration' ### If input is a file, this will write out to the file, formatted ##lines = config_obj.write() self._filter_dict_dict = {} ##if self.__class__.keys: ##msg = 'Before parse_config, self.__class__.keys = %s' ##raise dfb.FilterAttributeError, msg % self.__class__.keys for section in config_obj.sections: if section == '--main--': main_section_found = True # Default values may be present or not keys_with_vals = [] live_updates = [] for name, value in config_obj[section].iteritems(): ## print '**9810** [%s] %s = %s' % (section, name, value) if name == 'ftype': self.ftype = value ftype_in_config = True elif name.startswith('descr'): # description # Build up multiline docstring # ConfigObj puts strings with commas into a list docstring.append(fut.config_obj_comma_fix(value)) elif name.startswith('key'): # "key = ..." or "keys = ..." key_list = value try: # Note: += doesn't raise the TypeError exception keys_with_vals = keys_with_vals + key_list except TypeError: keys_with_vals = keys_with_vals + [key_list] elif name == 'dynamic': self.dynamic = fut.convert_config_str(value) elif name.startswith('update_live'): # e.g. update_live_27 update_list = value try: # Note: += doesn't raise the TypeError exception live_updates = live_updates + update_list except TypeError: live_updates = live_updates + [update_list] else: msg = 'Unknown [--main--] parameter "%s" in config' raise dfb.PipelineConfigError, msg % name # This is where the class attribute "keys" is defined, just # like the line "keys = [..]" in the filter definitions. ##print '**10025** Setting %s class attr keys from config=%s' % ( ##self.__class__.__name__, keys_with_vals) ##if self.ftype == 'read_and_align': ##pass ## self.__class__.keys = keys_with_vals self._config_keys = keys_with_vals self._live_updates = live_updates ##if self.__class__.keys: ##self._extract_defaults_from_keys() # Into self._keys() ##elif section == '--defaults--': ##print '**10300** Reached section --defaults--' else: if section not in self._ordered_filter_list: self._ordered_filter_list.append(section) self._update_filter_dict(section, config_obj[section]) if not main_section_found: msg = '[--main--] section missing from class %s' raise dfb.PipelineConfigError, msg % self.__class__.__name__ if not ftype_in_config: msg = 'ftype missing from [--main--] section in class %s' raise dfb.PipelineConfigError, msg % self.__class__.__name__ # Append description to any docstring. Must have one or the other. if self.__doc__: docstring = [self.__doc__, '', ''] + docstring self.__doc__ = '\n'.join(docstring) if not self.__doc__: msg = '__doc__/description missing from [--main--] section ' + \ 'in class %s' raise dfb.PipelineConfigError, msg % self.__class__.__name__
def test_config_obj_comma_fix(self): self.assertEquals(fut.config_obj_comma_fix('hello'), 'hello') self.assertEquals(fut.config_obj_comma_fix(['a','b','c']), 'a, b, c') self.assertEquals(fut.config_obj_comma_fix(['x = a + sum(3', 4, 'f4)']), 'x = a + sum(3, 4, f4)')