def test_convert_dict(self):
     self.assertEquals(fut.convert_config_str('{}'), {})
     self.assertEquals(fut.convert_config_str('{1:1, 2:2, 3:3}'), 
                                               {1:1, 2:2, 3:3})
     self.assertEquals(fut.convert_config_str("{'q':'q', 'w':'w'}"), 
                                               dict(q='q', w='w'))
     self.assertEquals(fut.convert_config_str('{$$//$$}'), '{$$//$$}')
示例#2
0
 def test_convert_dict(self):
     self.assertEquals(fut.convert_config_str('{}'), {})
     self.assertEquals(fut.convert_config_str('{1:1, 2:2, 3:3}'), {
         1: 1,
         2: 2,
         3: 3
     })
     self.assertEquals(fut.convert_config_str("{'q':'q', 'w':'w'}"),
                       dict(q='q', w='w'))
     self.assertEquals(fut.convert_config_str('{$$//$$}'), '{$$//$$}')
示例#3
0
 def _update_filter_dict(self, filt_name, source_dict={}):
     """Update filter dict if it exists, or create a new one, referenced by
     name, which is also one of the dictionary's keys.
     """
     try:
         filt_dict = self._filter_dict_dict[filt_name]
     except KeyError:
         # First reference to filter, so create dictionary
         ##            filt_dict = self._filter_dict_dict[filt_name] = dict(_name=filt_name)
         filt_dict = dict(_name=filt_name)
         self._filter_dict_dict[filt_name] = filt_dict
     for key, value in source_dict.iteritems():
         # Try to convert sensibly, rather than by formal configspec
         new_value = fut.convert_config_str(value)
         # We're building a dictionary, where the key values shouldn't
         # change. If a null value is being passed in where a significant
         # value is already set, we can ignore it, else raise an exception.
         if key in filt_dict and filt_dict[key]:
             if filt_dict[key] == new_value:
                 continue  # Nothing to do
             elif not new_value:
                 continue  # Avoid overwriting current value with [] or None
             else:  # Change value attempt
                 msg = 'Can\'t change %s value (from "%s" to "%s")'
                 raise dfb.FilterAttributeError, msg % (key, filt_dict[key],
                                                        new_value)
         else:
             filt_dict[key] = new_value
示例#4
0
    def _update_filter_dict(self, filt_name, source_dict={}):
        """Update filter dict if it exists, or create a new one, referenced by
        name, which is also one of the dictionary's keys.
        """
        try:
            filt_dict = self._filter_dict_dict[filt_name]
        except KeyError:  
            # First reference to filter, so create dictionary
##            filt_dict = self._filter_dict_dict[filt_name] = dict(_name=filt_name)
            filt_dict = dict(_name=filt_name)
            self._filter_dict_dict[filt_name] = filt_dict
        for key, value in source_dict.iteritems():
            # Try to convert sensibly, rather than by formal configspec
            new_value = fut.convert_config_str(value)
            # We're building a dictionary, where the key values shouldn't
            # change. If a null value is being passed in where a significant
            # value is already set, we can ignore it, else raise an exception.
            if key in filt_dict and filt_dict[key]:
                if filt_dict[key] == new_value:
                    continue  # Nothing to do
                elif not new_value:
                    continue  # Avoid overwriting current value with [] or None
                else:  # Change value attempt
                    msg = 'Can\'t change %s value (from "%s" to "%s")'
                    raise dfb.FilterAttributeError, msg % (key, filt_dict[key],
                                                           new_value)
            else:            
                filt_dict[key] = new_value
示例#5
0
 def t1est_convert_str_returns_on_value_error(self):
     # Does not work yet
     input_string = '{}'
     input_string.startswith = mock.Mock()
     input_string.endswith = input_string.startswith
     input_string.startswith.return_value = True
     self.assertEquals(fut.convert_config_str(input_string), input_string)
     eval = eval_holder
 def t1est_convert_str_returns_on_value_error(self):
     # Does not work yet
     input_string = '{}'
     input_string.startswith = mock.Mock()
     input_string.endswith = input_string.startswith
     input_string.startswith.return_value = True
     self.assertEquals(fut.convert_config_str(input_string), input_string)        
     eval = eval_holder
 def test_convert_config(self):
     self.assertEquals(fut.convert_config_str('1234'), 1234)
     self.assertEquals(fut.convert_config_str(3456), 3456)
     self.assertEquals(fut.convert_config_str('hello'), 'hello')
     self.assertEquals(fut.convert_config_str('0x0'), 0)
     self.assertEquals(fut.convert_config_str('0x20'), 32)
     self.assertEquals(fut.convert_config_str('0xhello'), '0xhello')
示例#8
0
 def test_convert_config(self):
     self.assertEquals(fut.convert_config_str('1234'), 1234)
     self.assertEquals(fut.convert_config_str(3456), 3456)
     self.assertEquals(fut.convert_config_str('hello'), 'hello')
     self.assertEquals(fut.convert_config_str('0x0'), 0)
     self.assertEquals(fut.convert_config_str('0x20'), 32)
     self.assertEquals(fut.convert_config_str('0xhello'), '0xhello')
 def test_convert_list_as_string(self):
     self.assertEquals(fut.convert_config_str('[]'), [])
     self.assertEquals(fut.convert_config_str('[1, 2, 3]'), [1, 2, 3])
     self.assertEquals(fut.convert_config_str("['4', '5', '6']"), [4, 5, 6])
     self.assertEquals(fut.convert_config_str("['q', 'w', 'e']"), 
                                               ['q', 'w', 'e'])
     self.assertEquals(fut.convert_config_str(
         "['hello', '0x20', 'false', '[]']"), ['hello', 32, False, []])
     self.assertEquals(fut.convert_config_str('[$$//$$]'), '[$$//$$]')
示例#10
0
 def test_convert_list_as_string(self):
     self.assertEquals(fut.convert_config_str('[]'), [])
     self.assertEquals(fut.convert_config_str('[1, 2, 3]'), [1, 2, 3])
     self.assertEquals(fut.convert_config_str("['4', '5', '6']"), [4, 5, 6])
     self.assertEquals(fut.convert_config_str("['q', 'w', 'e']"),
                       ['q', 'w', 'e'])
     self.assertEquals(
         fut.convert_config_str("['hello', '0x20', 'false', '[]']"),
         ['hello', 32, False, []])
     self.assertEquals(fut.convert_config_str('[$$//$$]'), '[$$//$$]')
 def test_convert_space(self):
     # Actual spaces are stripped out
     self.assertEquals(fut.convert_config_str(' '), '')
     self.assertEquals(fut.convert_config_str('space'), ' ')
     self.assertEquals(fut.convert_config_str('Space'), ' ')
示例#12
0
 def test_convert_none(self):
     self.assertEquals(fut.convert_config_str(None), None)
     self.assertEquals(fut.convert_config_str('None'), None)
     self.assertEquals(fut.convert_config_str('none'), None)
     self.assertEquals(fut.convert_config_str('non'), 'non')
示例#13
0
 def test_convert_list_as_list(self):
     self.assertEquals(fut.convert_config_str([]), [])
     self.assertEquals(fut.convert_config_str([1, 2, 3]), [1, 2, 3])
     self.assertEquals(fut.convert_config_str(['4', '5', '6']), [4, 5, 6])
     self.assertEquals(fut.convert_config_str(['q', 'w', 'e']),
                       ['q', 'w', 'e'])
示例#14
0
 def test_convert_empty(self):
     self.assertEquals(fut.convert_config_str('empty'), '')
     self.assertEquals(fut.convert_config_str('Empty'), '')
     self.assertEquals(fut.convert_config_str(''), '')
示例#15
0
 def test_convert_iterables(self):
     self.assertEquals(fut.convert_config_str('[]'), [])
     self.assertEquals(fut.convert_config_str('{}'), {})
 def test_convert_boolean(self):
     self.assertEquals(fut.convert_config_str('True'), True)
     self.assertEquals(fut.convert_config_str('false'), False)
     self.assertEquals(fut.convert_config_str('T'), True)
     self.assertEquals(fut.convert_config_str(True), True)
示例#17
0
    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__
示例#18
0
 def test_convert_boolean(self):
     self.assertEquals(fut.convert_config_str('True'), True)
     self.assertEquals(fut.convert_config_str('false'), False)
     self.assertEquals(fut.convert_config_str('T'), True)
     self.assertEquals(fut.convert_config_str(True), True)
 def test_convert_empty(self):
     self.assertEquals(fut.convert_config_str('empty'), '')
     self.assertEquals(fut.convert_config_str('Empty'), '')
     self.assertEquals(fut.convert_config_str(''), '')
 def test_convert_hex_to_int(self):
     self.assertEquals(fut.convert_config_str('0x2000'), 8192)
     self.assertEquals(fut.convert_config_str(0x2000), 8192)
     self.assertEquals(fut.convert_config_str('A'), 'A')
     self.assertEquals(fut.convert_config_str('0xA'), 10)
     self.assertEquals(fut.convert_config_str('0xabc'), 0xABC)
 def test_convert_iterables(self):
     self.assertEquals(fut.convert_config_str('[]'), [])
     self.assertEquals(fut.convert_config_str('{}'), {})
示例#22
0
 def test_convert_space(self):
     # Actual spaces are stripped out
     self.assertEquals(fut.convert_config_str(' '), '')
     self.assertEquals(fut.convert_config_str('space'), ' ')
     self.assertEquals(fut.convert_config_str('Space'), ' ')
 def test_convert_list_as_list(self):
     self.assertEquals(fut.convert_config_str([]), [])
     self.assertEquals(fut.convert_config_str([1, 2, 3]), [1, 2, 3])
     self.assertEquals(fut.convert_config_str(['4', '5', '6']), [4, 5, 6])
     self.assertEquals(fut.convert_config_str(
         ['q', 'w', 'e']), ['q', 'w', 'e'])
 def test_convert_none(self):
     self.assertEquals(fut.convert_config_str(None), None)
     self.assertEquals(fut.convert_config_str('None'), None)
     self.assertEquals(fut.convert_config_str('none'), None)
     self.assertEquals(fut.convert_config_str('non'), 'non')
示例#25
0
 def test_convert_hex_to_int(self):
     self.assertEquals(fut.convert_config_str('0x2000'), 8192)
     self.assertEquals(fut.convert_config_str(0x2000), 8192)
     self.assertEquals(fut.convert_config_str('A'), 'A')
     self.assertEquals(fut.convert_config_str('0xA'), 10)
     self.assertEquals(fut.convert_config_str('0xabc'), 0xABC)
示例#26
0
    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__