Ejemplo n.º 1
0
 def test_lowercase(self):
     a = dict(FOO='bar')
     b = dict(BAR='baz')
     util.merge_dicts(a, b, inline=True)
     self.assertIn('FOO', a)
     self.assertIn('BAR', a)
     self.assertNotIn('foo', a)
     self.assertNotIn('bar', a)
Ejemplo n.º 2
0
    def test_replace_primitives(self):
        self.assertEquals(dict(foo='bar'), util.merge_dicts(dict(foo='baz'), dict(foo='bar'), replace_primitives=True))
        self.assertEquals(dict(foo='baz'), util.merge_dicts(dict(foo='bar'), dict(foo='baz'), replace_primitives=True))

        c = dict(bar='baz')
        d = dict(bar='foo')
        a = dict(foo=c)
        b = dict(foo=d)
        self.assertEquals(dict(foo=dict(bar='foo')), util.merge_dicts(a, b, replace_primitives=True))
        self.assertEquals(dict(foo=dict(bar=['baz', 'foo'])), util.merge_dicts(a, b))
        self.assertEquals(dict(foo=dict(bar='foo')), util.merge_dicts(a, b, replace=True))

        e = dict(foo=dict(bar=c, baz=d))
        f = dict(foo=dict(bar=d))

        self.assertEquals(dict(foo=dict(bar=dict(bar='foo'))), util.merge_dicts(e, f, replace=True))
        self.assertEquals(dict(foo=dict(bar=dict(bar='foo'), baz=dict(bar='foo'))), util.merge_dicts(e, f, replace_primitives=True))
Ejemplo n.º 3
0
    def _load_includes(self, current_config, include_paths, visited_files):
        """ Recursively handles includes of other configuration-files. """
        for include_path_or_filepath in include_paths:
            include_path = util.expand_filepath(include_path_or_filepath)

            if include_path in visited_files:
                _warn_because_file_is_loaded_multiple_times(include_path, visited_files)

            visited_files.append(include_path)

            self._fail_if_configuration_file_does_not_exist(include_path)

            try:
                included_config = yaml.load(open(include_path))
                included_config = self._load_config(included_config, visited_files)
                current_config = util.merge_dicts(included_config, current_config, replace_primitives=True)
            except exceptions.ConfigurationError:
                raise
            except Exception, why:
                raise exceptions.ConfigurationError('Error in configuration file %s: %s'%(include_path, why))
Ejemplo n.º 4
0
    def _load_config(self, config, visited_files):
        """ Handles the configuration object, including referenced configurations as
            specified. Also handles replacement of special options like runmodes.
        """
        current_configuration_file = visited_files[-1]

        # if a configuration file does not contain anything, yaml.load returns None,
        # but we consider an empty configuration file to be an empty dict instead
        if config is None:
            config = dict()

        self._fail_if_configuration_is_invalid(config, current_configuration_file)

        includes = config.get('includes', dict())

        config = self._load_includes(config, includes, visited_files)

        # see if we have any special options for this mode
        if 'runmodes' in config:
            # currently we only support "unittest" as the runmode:
            if util.in_unittest():
                config = util.merge_dicts(config, config['runmodes'].get('unittest', dict()), replace_primitives=True)

        return config
Ejemplo n.º 5
0
 def process(self, baton):
     return util.merge_dicts(baton, self.dict, **self.merge_args)
Ejemplo n.º 6
0
 def test_inline(self):
     a = dict(foo='bar')
     b = dict(bar='baz')
     util.merge_dicts(a, b, inline=True)
     self.assertIn('bar', a)
Ejemplo n.º 7
0
 def test_merge_two_primitives(self):
     self.assertEquals(dict(foo=['bar', 'baz']), util.merge_dicts(dict(foo='bar'), dict(foo='baz')))
     self.assertEquals(dict(foo=['baz', 'bar']), util.merge_dicts(dict(foo='baz'), dict(foo='bar')))
     self.assertEquals(dict(foo='bar'), util.merge_dicts(dict(foo='baz'), dict(foo='bar'), replace=True))
Ejemplo n.º 8
0
 def test_simple(self):
     self.assertEquals(dict(foo='bar'), util.merge_dicts(dict(), dict(foo='bar')))
     self.assertEquals(dict(foo='bar'), util.merge_dicts(dict(foo='bar'), dict()))
Ejemplo n.º 9
0
 def test_nesting(self):
     a = dict(foo=['bar', 'baz'])
     b = dict(foo=['baz', 'foo'])
     self.assertEquals(dict(foo=['bar', 'baz', 'baz', 'foo']), util.merge_dicts(a, b))
     self.assertEquals(dict(foo=['baz', 'foo']), util.merge_dicts(a, b, replace=True))