diff tests/test.py @ 364:1941f0188e81

FIX: Handle a "default" keyword parameter in ".getvar()" properly. It happened to be a formal parameter but was not used properly within the method body.
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 09 Jul 2021 08:53:30 +0200
parents a5c792074ec9
children 4ff02a4f401a
line wrap: on
line diff
--- a/tests/test.py	Fri Jun 25 00:57:21 2021 +0200
+++ b/tests/test.py	Fri Jul 09 08:53:30 2021 +0200
@@ -440,6 +440,28 @@
         x = cfg.expand_variable("{{intl.cache.items|Empty}}")
         self.assertEqual(10, x)
 
+    def test13_keyerror(self):
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key")
+
+    def test14_getvar_with_default(self):
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertEqual("999", cfg.getvar("non.existing.key", default="999"))
+
+    def test15_getvar_s_with_default(self):
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertEqual("999", cfg.getvar_s("non.existing.key",
+                                             default="999"))
+
+    def test16_getintvar_s_with_default(self):
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertEqual(9999, cfg.getintvar_s("non.existing.key",
+                                               default=9999))
+    def test17_getintvar_s_with_default(self):
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertFalse(cfg.getboolvar_s("non.existing.key",
+                                          default="false"))
+
 
 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase):