Exemple #1
0
    def test_existing_string(self):
        """Test if string variable given in config file is correctly returned"""
        config = RawConfigParser()

        configtext = """
        [test]
        var1 = test
        """
        config.read_string(configtext)

        var1 = config.get("test", "var1")
        print(f"From RawConfigParser -> var1: {var1}")
        self.assertEqual(var1, "test")

        wrap = ConfigWrapper(
            config, {
                "var1": {
                    "default": "<undefined>",
                    "description": "this is just a test for string var1"
                }
            })

        var1 = wrap.get("test", "var1")
        print(f"From ConfigWrapper -> var1: {var1}")
        self.assertEqual(var1, "test")
        self.assertIsInstance(var1, str)
Exemple #2
0
    def test_nodefault_exception_string(self):
        """Test if undefined or value without default raises exception"""
        config = RawConfigParser()

        configtext = """
        [test]
        """
        config.read_string(configtext)

        with self.assertRaises(NoOptionError):
            _ = config.get("test", "var1")
        with self.assertRaises(NoOptionError):
            _ = config.get("test", "var2")

        wrap = ConfigWrapper(
            config,
            {"var1": {
                "description": "this is just a test for string var1"
            }})

        with self.assertRaises(NoOptionError):
            _ = wrap.get("test", "var2")
        with self.assertRaises(NoOptionError):
            _ = wrap.get("test", "var1")
Exemple #3
0
    def test_manual_fallback_string(self):
        """Test if explicit fallback string has precedence"""
        config = RawConfigParser()

        configtext = """
        [test]
        """
        config.read_string(configtext)

        with self.assertRaises(NoOptionError):
            _ = config.get("test", "var1")

        wrap = ConfigWrapper(
            config, {
                "var1": {
                    "default": "<undefined>",
                    "description": "this is just a test for string var1"
                }
            })

        var1 = wrap.get("test", "var1", fallback="{{manual}}")
        print(f"From ConfigWrapper -> var1: {var1}")
        self.assertEqual(var1, "{{manual}}")
        self.assertIsInstance(var1, str)
Exemple #4
0
    def test_default_string(self):
        """Test if default string variable is returned if variable not defined"""
        config = RawConfigParser()

        configtext = """
        [test]
        """
        config.read_string(configtext)

        with self.assertRaises(NoOptionError):
            _ = config.get("test", "var1")

        wrap = ConfigWrapper(
            config, {
                "var1": {
                    "default": "<undefined>",
                    "description": "this is just a test for string var1"
                }
            })

        var1 = wrap.get("test", "var1")
        print(f"From ConfigWrapper -> var1: {var1}")
        self.assertEqual(var1, "<undefined>")
        self.assertIsInstance(var1, str)