Ejemplo n.º 1
0
    def test_convert_single(self):
        config1 = {
            'int': '35',
            'str_list': 'abc def ghf',
            'string': 'This is a string',
            'rubbish': 'rubbish stuff',
            'bool1': 'True',
            'int_list': '45 66 55 33',
            'bool2': 'False'
        }

        exp_config1 = {
            'int': 35,
            'str_list': ['abc', 'def', 'ghf'],
            'string': 'This is a string',
            'rubbish': 'rubbish stuff',
            'bool1': True,
            'int_list': [45, 66, 55, 33],
            'bool2': False
        }

        # Apply conversions to the string inputs
        mureilbuilder.apply_conversions(config1, self.config_spec)
        self.assertTrue((config1 == exp_config1))

        # And apply to pre-converted values
        mureilbuilder.apply_conversions(config1, self.config_spec)
        self.assertTrue((config1 == exp_config1))
 def test_convert_single(self):
     config1 = {
         'int': '35',
         'str_list': 'abc def ghf',
         'string': 'This is a string',
         'rubbish': 'rubbish stuff',
         'bool1': 'True',
         'int_list': '45 66 55 33',
         'bool2': 'False'
     }
     
     exp_config1 = {
         'int': 35,
         'str_list': ['abc', 'def', 'ghf'],
         'string': 'This is a string',
         'rubbish': 'rubbish stuff',
         'bool1': True,
         'int_list': [45, 66, 55, 33],
         'bool2': False
     }
     
     # Apply conversions to the string inputs
     mureilbuilder.apply_conversions(config1, self.config_spec)
     self.assertTrue((config1 == exp_config1))
     
     # And apply to pre-converted values
     mureilbuilder.apply_conversions(config1, self.config_spec)
     self.assertTrue((config1 == exp_config1))
 def test_convert_multiple(self):
     config1 = {
         'int': '{2010:35, 2020: 53}',
         'str_list': '{2000:  abc def ghf , 2010: bbg ddf} ',
         'string': '{334: This is a string, 443: and another one } ',
         'rubbish': 'rubbish stuff',
         'bool1': 'True',
         'int_list': '{3040: 45 66 55 33, 4003: 44 33 44 33}  ',
         'bool2': '{300: False, 322: True}'
     }
     
     exp_config1 = {
         'int': {2010: 35, 2020: 53},
         'str_list': {2000: ['abc', 'def', 'ghf'], 2010: ['bbg', 'ddf']},
         'string': {334: 'This is a string', 443: 'and another one'},
         'rubbish': 'rubbish stuff',
         'bool1': True,
         'int_list': {3040: [45, 66, 55, 33], 4003: [44, 33, 44, 33]},
         'bool2': {300: False, 322: True}
     }
     
     # Apply conversions to the string inputs
     mureilbuilder.apply_conversions(config1, self.config_spec)
     self.assertTrue((config1 == exp_config1))
     
     # And apply to pre-converted values
     mureilbuilder.apply_conversions(config1, self.config_spec)
     self.assertTrue((config1 == exp_config1))
    def load_initial_config(self, config, global_config=None):
        config_spec = self.config_spec
        config_copy = copy.deepcopy(config)
        
        # Apply defaults, then globals, then new config values

        # Defaults
        new_config = mureilbuilder.collect_defaults(config_spec)
        
        # Globals
        if global_config:
            mureilbuilder.update_with_globals(new_config, global_config,
                config_spec)

        # New config values
        new_config.update(config_copy)

        # Apply conversions to config
        mureilbuilder.apply_conversions(new_config, config_spec)

        # And check that all of the required parameters are there
        mureilbuilder.check_required_params(new_config, config_spec)

        self.config = new_config
        return
Ejemplo n.º 5
0
    def load_initial_config(self, config, global_config=None):
        config_spec = self.config_spec
        config_copy = copy.deepcopy(config)

        # Apply defaults, then globals, then new config values

        # Defaults
        new_config = mureilbuilder.collect_defaults(config_spec)

        # Globals
        if global_config:
            mureilbuilder.update_with_globals(new_config, global_config,
                                              config_spec)

        # New config values
        new_config.update(config_copy)

        # Apply conversions to config
        mureilbuilder.apply_conversions(new_config, config_spec)

        # And check that all of the required parameters are there
        mureilbuilder.check_required_params(new_config, config_spec)

        self.config = new_config
        return
    def update_from_config_spec(self):
        """Reapply the config_spec, which may have been changed in process_initial_config.
        
        Applies any new defaults and applies conversions.
        """

        # Get defaults
        new_config = mureilbuilder.collect_defaults(self.config_spec)
        
        # Copy defaults to params that are not in self.config already
        for (key, value) in new_config.iteritems():
            if key not in self.config:
                self.config[key] = value
        
        # Apply conversions to config
        mureilbuilder.apply_conversions(self.config, self.config_spec)
Ejemplo n.º 7
0
    def update_from_config_spec(self):
        """Reapply the config_spec, which may have been changed in process_initial_config.
        
        Applies any new defaults and applies conversions.
        """

        # Get defaults
        new_config = mureilbuilder.collect_defaults(self.config_spec)

        # Copy defaults to params that are not in self.config already
        for (key, value) in new_config.iteritems():
            if key not in self.config:
                self.config[key] = value

        # Apply conversions to config
        mureilbuilder.apply_conversions(self.config, self.config_spec)
    def load_initial_config(self, config, global_config=None):
        config_spec = self.config_spec
        config_copy = copy.deepcopy(config)
        
        # Apply defaults, then new config values

        # Defaults
        new_config = mureilbuilder.collect_defaults(config_spec)
        
        # New config values
        new_config.update(config_copy)

        # Apply conversions to config
        mureilbuilder.apply_conversions(new_config, config_spec)

        self.config = new_config
        return
Ejemplo n.º 9
0
    def test_convert_multiple(self):
        config1 = {
            'int': '{2010:35, 2020: 53}',
            'str_list': '{2000:  abc def ghf , 2010: bbg ddf} ',
            'string': '{334: This is a string, 443: and another one } ',
            'rubbish': 'rubbish stuff',
            'bool1': 'True',
            'int_list': '{3040: 45 66 55 33, 4003: 44 33 44 33}  ',
            'bool2': '{300: False, 322: True}'
        }

        exp_config1 = {
            'int': {
                2010: 35,
                2020: 53
            },
            'str_list': {
                2000: ['abc', 'def', 'ghf'],
                2010: ['bbg', 'ddf']
            },
            'string': {
                334: 'This is a string',
                443: 'and another one'
            },
            'rubbish': 'rubbish stuff',
            'bool1': True,
            'int_list': {
                3040: [45, 66, 55, 33],
                4003: [44, 33, 44, 33]
            },
            'bool2': {
                300: False,
                322: True
            }
        }

        # Apply conversions to the string inputs
        mureilbuilder.apply_conversions(config1, self.config_spec)
        self.assertTrue((config1 == exp_config1))

        # And apply to pre-converted values
        mureilbuilder.apply_conversions(config1, self.config_spec)
        self.assertTrue((config1 == exp_config1))