Пример #1
0
    def test_replicate(self):
        replicate('Name', None)  # does nothing, no exception/error
        source_1 = OrderedDictWithDefaults()
        source_1["name"] = "sea"
        source_1["origin"] = "kitchen"
        source_1.defaults_ = {"brewery": False}
        source_2 = OrderedDictWithDefaults()
        source_2["name"] = ["sea", "legume"]
        source_2["origin"] = "fridge"
        source_3 = OrderedDictWithDefaults()
        source_3["name"] = OrderedDictWithDefaults()
        source_3["name"]["value"] = "oil"
        source_3["name"]["key"] = 1
        source_3["name"].defaults_ = {"value": 1}

        target_1 = OrderedDictWithDefaults()
        target_2 = OrderedDictWithDefaults()
        target_3 = OrderedDictWithDefaults()

        replicate(target_1, source_1)
        replicate(target_2, source_2)
        replicate(target_3, source_3)

        # Note: assertDictEqual not available for Python 2.6
        self.assertEqual(str(source_1), str(target_1))
        self.assertEqual(str(source_2), str(target_2))
        self.assertEqual(str(source_3), str(target_3))
Пример #2
0
    def loadcfg(self, rcfile, title=""):
        """Parse a config file, upgrade or deprecate items if necessary,
        validate it against the spec, and if this is not the first load,
        combine/override with the existing loaded config."""

        sparse = parse(rcfile, self.output_fname, self.tvars)

        if self.upgrader is not None:
            self.upgrader(sparse, title)

        self.validate(sparse)

        if not self.sparse:
            self.sparse = sparse
        else:
            # Already loaded, override with new items.
            replicate(self.sparse, sparse)
Пример #3
0
    def loadcfg(self, rcfile, title=""):
        """Parse a config file, upgrade or deprecate items if necessary,
        validate it against the spec, and if this is not the first load,
        combine/override with the existing loaded config."""

        sparse = parse(rcfile, self.output_fname, self.tvars)

        if self.upgrader is not None:
            self.upgrader(sparse, title)

        self.validate(sparse)

        if not self.sparse:
            self.sparse = sparse
        else:
            # Already loaded, override with new items.
            replicate(self.sparse, sparse)