def setUpClass(cls):
        """make a Config test object from some inline data

        First this dumps the data into json files, and then points the config object
        to the various paths for loading. The data can then be used to test funct.
        The data contains only values that are usefull for confirming that config
        behaviour is as expected, and is not meant to be useful.

        We also preload some of the config
        """

        logger.debug("Building empty config object")
        config = configerus.new_config()
        make_test_config(config, config_sources)
        cls.config = config
        cls.loaded_config = config.load("config")
        cls.loaded_variables = config.load("variables")
    def test_copy_safety(self):
        """Test that config copy allows overloads and doesn't modify the source"""

        logger.debug("Building empty config object")
        config = configerus.new_config()

        config.add_source(PLUGIN_ID_SOURCE_DICT, "orig", 80).set_data(
            {"copy": {"one": "orig 1"}}
        )

        config_copy_orig = config.load("copy")

        copy1 = config.copy()
        copy1.add_source(PLUGIN_ID_SOURCE_DICT, "copy1", 81).set_data(
            {"copy": {"one": "copy1 1", "two": "copy1 2"}}
        )
        copy2 = config.copy()
        copy2.add_source(PLUGIN_ID_SOURCE_DICT, "copy2", 82).set_data(
            {"copy": {"one": "copy2 1", "two": "copy2 2"}}
        )

        config_copy_late = config.load("copy")
        config1_copy = copy1.load("copy")
        config2_copy = copy2.load("copy")

        logger.debug("LOADED: AFTER: orig: %s", config_copy_orig.data)
        logger.debug("LOADED: AFTER: 1   : %s", config1_copy.data)
        logger.debug("LOADED: AFTER: 2   : %s", config2_copy.data)
        logger.debug("LOADED: AFTER: late: %s", config_copy_late.data)

        # check original values
        self.assertEqual(config_copy_orig.get("one"), "orig 1")
        with self.assertRaises(KeyError):
            config_copy_orig.get("two")
        # check that copied config didn't modify original
        self.assertEqual(
            config_copy_orig.get("one"), config_copy_late.get("one")
        )
        with self.assertRaises(KeyError):
            config_copy_late.get("two")

        self.assertEqual(config1_copy.get("one"), "copy1 1")
        self.assertEqual(config1_copy.get("two"), "copy1 2")
        self.assertEqual(config2_copy.get("one"), "copy2 1")
        self.assertEqual(config2_copy.get("two"), "copy2 2")
Пример #3
0
    def _simple_validate_config(self):
        """use a common config across some tests"""

        logger.debug("Building jsonschema config object")
        config = configerus.new_config()
        config.add_validator(PLUGIN_ID_VALIDATE_JSONSCHEMA)
        config.add_source(PLUGIN_ID_SOURCE_DICT).set_data({
            "valid_load_test":
            self.valid_instance,
            "invalid_load_test":
            self.invalid_instance,
            "get_test": {
                "valid": self.valid_instance,
                "1": {
                    "invalid": self.invalid_instance
                },
            },
            "jsonschema": {
                "instance": self.instance_schema
            },
        })

        return config
Пример #4
0
 def test_construct_3_bad_bootsraps(self):
     """Make sure we can create a Configs object, with default bootstraps"""
     with self.assertRaises(KeyError):
         configerus.new_config(bootstraps=["I do not exist"])
Пример #5
0
 def test_construct_3_default_bootsraps(self):
     """Make sure we can create a Configs object, with default bootstraps"""
     configerus.new_config()
Пример #6
0
 def test_construct_2_single_bootstrap(self):
     """make sure we can create a Configs object, without a single bootstrap"""
     configerus.new_config(bootstraps=["dict"])
Пример #7
0
 def test_construct_1_naked(self):
     """just make sure we can create a Configs object, without any bootstraps"""
     config = configerus.new_config(bootstraps=[])
     self.assertIsInstance(config, Config)