changeset 625:f167f8db4624

A unittest for the assertion, that a given default must be returned as identical object and not as copy
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 13 Jan 2022 22:14:41 +0100
parents 429a7d5002b8
children b54f2932415f
files tests/test.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test.py	Thu Jan 13 21:43:02 2022 +0100
+++ b/tests/test.py	Thu Jan 13 22:14:41 2022 +0100
@@ -448,11 +448,37 @@
         cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
         self.assertEqual("999", cfg.getvar("non.existing.key", default="999"))
 
+    def test14_getvar_with_original_default(self):
+        # The default must be the original and not a copy
+        dflt = {"foo": "bar"}
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertTrue(cfg.getvar("non.existing.key", default=dflt) is dflt)
+
     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 test15_getvar_s_with_original_default(self):
+        # The default must be the original and not a copy
+        dflt = {"foo2": "bar2"}
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertTrue(cfg.getvar_s("non.existing.key", default=dflt) is dflt)
+
+    def test15b_getvarl_with_original_default(self):
+        # The default must be the original and not a copy
+        dflt = {"foo2": "bar2"}
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertTrue(cfg.getvarl((u"non", u"existing", u"key"),
+                                     default=dflt) is dflt)
+
+    def test15c_getvarl_s_with_original_default(self):
+        # The default must be the original and not a copy
+        dflt = {"foo3": "bar3"}
+        cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
+        self.assertTrue(cfg.getvarl_s((u"non", u"existing", u"key4"),
+                                      default=dflt) is dflt)
+
     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",