diff tests/test.py @ 227:f5011eec3b6e

Added a loader with key "ignore" that ignores the given configuration file
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 12 May 2019 18:06:37 +0200
parents 0b855758ba08
children b2c75efad9e4
line wrap: on
line diff
--- a/tests/test.py	Sun May 12 17:27:12 2019 +0200
+++ b/tests/test.py	Sun May 12 18:06:37 2019 +0200
@@ -79,7 +79,7 @@
     def test01_toml_types(self):
         cfg = configmix.toml.load(os.path.join(TESTDATADIR, "conf1.toml"))
         self.__check_types(cfg)
-        self.__check_comment(cfg)        
+        self.__check_comment(cfg)
 
     def test02_py_types(self):
         cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py"))
@@ -253,7 +253,7 @@
         url = cfg.getvar_s("db.engines.ro.url")
         self.assertEqual(
             u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
-            url)        
+            url)
 
     def test03_namespace(self):
         cfg = self._load(
@@ -372,6 +372,27 @@
 
         self.assertRaises(ValueError, _ld)
 
+    def test02_ignore_one_style(self):
+        configmix.clear_assoc()
+        configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
+        configmix.set_assoc("*", "ignore", append=True)
+
+        cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"),
+                             os.path.join(TESTDATADIR, "conf30.conf"))
+        self.assertEqual(u("new value"), cfg.getvar_s("key-new"))
+        self.assertRaises(KeyError, cfg.getvar_s, "key1")
+
+    def test02_ignore_all(self):
+        configmix.clear_assoc()
+        configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
+        # This inserts at index 0 effectively ignoring all configuration files!
+        configmix.set_assoc("*", "ignore")
+
+        cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"),
+                             os.path.join(TESTDATADIR, "conf30.conf"))
+        self.assertRaises(KeyError, cfg.getvar_s, "key-new")
+        self.assertRaises(KeyError, cfg.getvar_s, "key1")        
+
     def test03_only_style_corrrect_style(self):
         configmix.clear_assoc()
         configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))